From fb4edeee714715ca49d78391699193654098b1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9?= Date: Tue, 19 Dec 2023 10:01:24 +0100 Subject: [PATCH] feature(error-handling): exit when error --- LobsterLang/app/Main.hs | 6 ++++-- foo.scm | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/LobsterLang/app/Main.hs b/LobsterLang/app/Main.hs index 3f01971..89f6fe6 100644 --- a/LobsterLang/app/Main.hs +++ b/LobsterLang/app/Main.hs @@ -10,11 +10,13 @@ module Main (main) where import Parse import Scope import System.IO (isEOF) +import System.Exit (exitWith, ExitCode (ExitFailure)) -- | Infinite loop until EOF from the user inputLoop :: [Scope.ScopeMb] -> IO () -inputLoop stack = isEOF >>= \end -> if end then print "End of Interpretation GLaDOS" else - getLine >>= \line -> case parseLisp line stack of +inputLoop new = isEOF >>= \end -> if end then print "End of Interpretation GLaDOS" else + getLine >>= \line -> case parseLisp line new of + (Nothing, stack) -> (if stack == new then print "***ERROR" >> exitWith (ExitFailure 84) else inputLoop stack) (res, stack') -> print res >> inputLoop stack' -- | Main diff --git a/foo.scm b/foo.scm index d5ac46b..62a7db8 100644 --- a/foo.scm +++ b/foo.scm @@ -1,4 +1,7 @@ (define foo 21) (define x 5) (define value (* x foo)) +p +(* value 4) +(define value (* 4 (+ 1 2))) value