Skip to content

Commit

Permalink
Merge pull request #20 from AxelHumeau/feature/error-handling
Browse files Browse the repository at this point in the history
feature(error-handling): exit when error
  • Loading branch information
AxelHumeau authored Dec 19, 2023
2 parents f615b78 + fb4edee commit 906b7bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions LobsterLang/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions foo.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(define foo 21)
(define x 5)
(define value (* x foo))
p
(* value 4)
(define value (* 4 (+ 1 2)))
value

0 comments on commit 906b7bb

Please sign in to comment.