2024-12-20 11:38:09 -06:00
|
|
|
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!"
|
2024-12-27 14:10:13 -06:00
|
|
|
else if input == ""
|
|
|
|
then do
|
|
|
|
putStrLn ""
|
|
|
|
repl env
|
2024-12-20 11:38:09 -06:00
|
|
|
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
|