Tests and better default REPL behavior
This commit is contained in:
13
src/Main.hs
13
src/Main.hs
@ -10,7 +10,18 @@ import qualified Data.Map as Map
|
||||
import Text.Megaparsec (runParser)
|
||||
|
||||
main :: IO ()
|
||||
main = repl Map.empty --(Map.fromList [("__result", Leaf)])
|
||||
main = repl library
|
||||
|
||||
runSapling :: String -> String
|
||||
runSapling s = show $ result (evalSapling Map.empty $ parseSapling s)
|
||||
|
||||
library = evalSapling Map.empty $ parseSapling
|
||||
"false = t\n \
|
||||
\ true = t t\n \
|
||||
\ id = (\\a : a)\n \
|
||||
\ triage = (\\a b c : t (t a b) c)\n \
|
||||
\ match_bool = (\\ot of : triage of (\\z : ot) t)\n \
|
||||
\ and = match_bool id (\\z : false)\n \
|
||||
\ if = (\\cond then else : t (t else (t t then)) t cond)"
|
||||
|
||||
runSaplingEnv env s = show $ result (evalSapling env $ parseSapling s)
|
||||
|
@ -32,7 +32,6 @@ parseSapling input =
|
||||
in map parseSingle nonEmptyLines
|
||||
|
||||
parseSingle :: String -> SaplingAST
|
||||
parseSingle "" = error "Empty input provided to parseSingle"
|
||||
parseSingle input = case runParser parseExpression "" (lexSapling input) of
|
||||
Left err -> error $ handleParseError err
|
||||
Right ast -> ast
|
||||
|
@ -16,6 +16,10 @@ repl env = do
|
||||
input <- getLine
|
||||
if input == "_:exit"
|
||||
then putStrLn "Goodbye!"
|
||||
else if input == ""
|
||||
then do
|
||||
putStrLn ""
|
||||
repl env
|
||||
else do
|
||||
let clearEnv = Map.delete "__result" env
|
||||
let newEnv = evalSingle clearEnv (parseSingle input)
|
||||
|
Reference in New Issue
Block a user