awful lot of error handling
This commit is contained in:
parent
061303ccc0
commit
75a33c2d94
4 changed files with 103 additions and 67 deletions
16
app/Main.hs
16
app/Main.hs
|
|
@ -4,10 +4,18 @@ import Lox.Interpreter
|
|||
import System.IO
|
||||
|
||||
run :: String -> IO ()
|
||||
run source = print result
|
||||
where result = eval expr
|
||||
expr = parse tokens
|
||||
tokens = scanTokensFromSource source
|
||||
run source = do
|
||||
let tokensMaybe = scanTokensFromSource source
|
||||
case tokensMaybe of
|
||||
Left UnexpectedCharacterError -> putStrLn "Unexpected character"
|
||||
Right tokens -> do
|
||||
let exprMaybe = parse tokens
|
||||
case exprMaybe of
|
||||
Left ExpectedExpressionError -> putStrLn "Expected expression"
|
||||
Left MismatchedParenthesesError -> putStrLn "Mismatched parentheses"
|
||||
Right expr -> do
|
||||
result <- eval expr
|
||||
print result
|
||||
|
||||
main :: IO ()
|
||||
main = putStr ">> " >> hFlush stdout >> getLine >>= run
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue