tidy up
This commit is contained in:
parent
6f4a835e54
commit
ef7dc3603d
5 changed files with 50 additions and 2 deletions
14
app/Main.hs
14
app/Main.hs
|
|
@ -15,8 +15,20 @@ run source = do
|
|||
Left (SyntaxError s) -> putStrLn s
|
||||
Right statements -> runStatements statements
|
||||
|
||||
runEval :: String -> IO ()
|
||||
runEval source = do
|
||||
let tokensMaybe = scanTokensFromSource source
|
||||
object <- case tokensMaybe of
|
||||
Left UnexpectedCharacterError -> putStrLn "Unexpected character" >> return NullObject
|
||||
Right tokens -> do
|
||||
let exprMaybe = parseExpression tokens
|
||||
case exprMaybe of
|
||||
Left (SyntaxError s) -> putStrLn s >> return NullObject
|
||||
Right statements -> eval statements
|
||||
print object
|
||||
|
||||
repl :: IO ()
|
||||
repl = putStr ">> " >> hFlush stdout >> getLine >>= run
|
||||
repl = putStr ">> " >> hFlush stdout >> getLine >>= runEval
|
||||
|
||||
main :: IO ()
|
||||
main = getArgs >>= fs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue