Created
September 19, 2021 00:18
-
-
Save gdevanla/5e4a6869ff2d2a79b445ebf3b809e6de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Notes on how to wrap InputT over StateT to maintain the environment around a language repl. | |
type HaskellLineT = InputT (StateT Env IO) () | |
runScriptInteractive = runStateT (runInputT defaultSettings loop) (initEnv Nothing) | |
where | |
loop :: HaskellLineT | |
loop = do | |
minput <- getInputLine "%" | |
when (isNothing minput) loop | |
env <- lift get | |
let lex_result = scanner (fromJust minput) | |
case lex_result of | |
Right lex -> do | |
let ast = P.parse loxProgram "" lex | |
case ast of | |
Right ast' -> do | |
(env', msg) <- liftIO $ interpretProgram ast' env | |
when (isJust msg) $ liftIO $ print msg | |
lift $ put env' | |
loop | |
Left e -> do | |
liftIO $ print $ "Scanner error" <> show e | |
loop | |
Left e -> do | |
liftIO $ print $ "Lexer error" <> show e | |
loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment