Allow multiline expressions

This commit is contained in:
2025-01-20 19:20:29 -06:00
committed by James Eversole
parent eeaf9e0289
commit ec0a6b7b16
7 changed files with 336 additions and 262 deletions

View File

@ -13,22 +13,23 @@ evalSingle env term
| SFunc name [] body <- term =
let res = evalAST env body
in Map.insert "__result" res (Map.insert name res env)
| SApp func arg <- term = Map.insert "__result"
(apply (evalAST env func) (evalAST env arg)) env
| SVar name <- term = case Map.lookup name env of
Just v -> Map.insert "__result" v env
Nothing -> errorWithoutStackTrace $ "Variable " ++ name ++ " not defined"
| otherwise = Map.insert "__result" (evalAST env term) env
| SApp func arg <- term =
let res = apply (evalAST env func) (evalAST env arg)
in Map.insert "__result" res env
| SVar name <- term =
case Map.lookup name env of
Just v -> Map.insert "__result" v env
Nothing -> errorWithoutStackTrace $ "Variable " ++ name ++ " not defined"
| otherwise =
Map.insert "__result" (evalAST env term) env
evalTricu :: Env -> [TricuAST] -> Env
evalTricu env list = evalTricu' env (filter (/= SEmpty) list)
where
evalTricu' :: Env -> [TricuAST] -> Env
evalTricu' env [] = env
evalTricu' env [s] =
let updatedEnv = evalSingle env s
in Map.insert "__result" (result updatedEnv) updatedEnv
evalTricu' env (x:xs) = evalTricu (evalSingle env x) xs
evalTricu env [] = env
evalTricu env [x] =
let updatedEnv = evalSingle env x
in Map.insert "__result" (result updatedEnv) updatedEnv
evalTricu env (x:xs) =
evalTricu (evalSingle env x) xs
evalAST :: Env -> TricuAST -> T
evalAST env term