Includes better error handling, additional tests, parsing and lexing fixes to match the desired behavior defined by the new tests, and a very basic REPL implementation.
26 lines
608 B
Haskell
26 lines
608 B
Haskell
module REPL where
|
|
|
|
import Eval
|
|
import Lexer
|
|
import Parser
|
|
import Research
|
|
|
|
import Control.Monad (void)
|
|
import qualified Data.Map as Map
|
|
import System.IO (hFlush, stdout)
|
|
|
|
repl :: Map.Map String T -> IO ()
|
|
repl env = do
|
|
putStr "sapling > "
|
|
hFlush stdout
|
|
input <- getLine
|
|
if input == "_:exit"
|
|
then putStrLn "Goodbye!"
|
|
else do
|
|
let clearEnv = Map.delete "__result" env
|
|
let newEnv = evalSingle clearEnv (parseSingle input)
|
|
case Map.lookup "__result" newEnv of
|
|
Just r -> putStrLn $ "sapling < " ++ show r
|
|
Nothing -> pure ()
|
|
repl newEnv
|