diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-10-05 14:28:00 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 78fac664f39dc52818fb99264c258b822df7d5b9 (patch) | |
| tree | 9b7187e15c4b2690df89e7558c610f20c99e9efd /app | |
| parent | 77968899b90cd9afe2ed2668b290b66cb553ced2 (diff) | |
Refactor Env into LContext
Diffstat (limited to 'app')
| -rw-r--r-- | app/Main.hs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/app/Main.hs b/app/Main.hs index 45540aa..0aa66d7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -23,21 +23,21 @@ parseArgs config args = config { configUseREPL = True } rest _ -> config -repl :: Config -> Env -> InputT IO () -repl config env = do +repl :: LState -> InputT IO () +repl ls = do minput <- getInputLine "> " case minput of Nothing -> return () Just input -> do - result <- lift $ runL config (runInlineScript "<repl>" env input) + result <- lift $ runL ls (runInlineScript "<repl>" input) case result of Left (LException mp ex) -> do outputStrLn $ case mp of Just p -> p ++ " error: " ++ ex Nothing -> "error: " ++ ex - repl config env - Right (newEnv, _) -> do - repl config newEnv + repl ls + Right (_, LState { stateEnv = newEnv }) -> do + repl ls { stateEnv = newEnv } main :: IO () main = do @@ -54,6 +54,7 @@ main = do } let config = parseArgs initialConfig args + ls = LState { stateConfig = config, stateEnv = builtinEnv } if (configShowHelp config) then do putStrLn $ "Usage: " ++ progName ++ " # to open REPL" @@ -73,15 +74,15 @@ main = do case (configScriptFileName config) of Just scriptFileName -> do - result <- runL config (runScriptFile builtinEnv scriptFileName) + result <- runL ls (runScriptFile scriptFileName) case result of Left (LException mp ex) -> case mp of Just p -> putStrLn $ p ++ " error: " ++ ex Nothing -> putStrLn $ "error: " ++ ex - Right (evaledEnv, _) -> do + Right (_, LState { stateEnv = evaledEnv }) -> do when (configUseREPL config) $ - runInputT defaultSettings (repl config evaledEnv) + runInputT defaultSettings (repl ls { stateEnv = evaledEnv }) Nothing -> do putStrLn $ "Lang REPL" putStrLn $ "Use CTRL+D to exit" - runInputT defaultSettings (repl config builtinEnv) + runInputT defaultSettings (repl ls) |
