Tests and better default REPL behavior

This commit is contained in:
2024-12-27 14:10:13 -06:00
committed by James Eversole
parent c3c6646cb2
commit 9c1c916fc9
5 changed files with 106 additions and 92 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)