Update lambda handling; better default decode out

This commit is contained in:
James Eversole
2024-12-27 20:46:30 -06:00
parent 44e2169cdb
commit d804a114bb
5 changed files with 72 additions and 66 deletions

View File

@ -5,35 +5,38 @@ import Lexer
import Parser
import Research
import Control.Monad (void)
import Control.Monad (void)
import qualified Data.Map as Map
import System.IO (hFlush, stdout)
import System.Console.Haskeline
import System.IO (hFlush, stdout)
repl :: Map.Map String T -> IO ()
repl env = do
putStr "sapling < "
hFlush stdout
input <- getLine
case input of
":_exit" ->
putStrLn "Goodbye!"
"" -> do
putStrLn ""
repl env
_ -> do
let clearEnv = Map.delete "__result" env
newEnv = evalSingle clearEnv (parseSingle input)
case Map.lookup "__result" newEnv of
Just r -> do
putStrLn $ "sapling > " ++ show r
putStrLn $ "DECODE -: " ++ (decodeResult r)
Nothing -> pure ()
repl newEnv
repl env = runInputT defaultSettings (loop env)
where
loop :: Map.Map String T -> InputT IO ()
loop env = do
minput <- getInputLine "sapling < "
case minput of
Nothing -> outputStrLn "Goodbye!"
Just ":_exit" -> outputStrLn "Goodbye!"
Just "" -> do
outputStrLn ""
loop env
Just input -> do
let clearEnv = Map.delete "__result" env
newEnv = evalSingle clearEnv (parseSingle input)
case Map.lookup "__result" newEnv of
Just r -> do
outputStrLn $ "sapling > " ++ show r
outputStrLn $ "DECODE -: " ++ decodeResult r
Nothing -> return ()
loop newEnv
decodeResult :: T -> String
decodeResult tc =
case ofString tc of
decodeResult tc = case ofNumber tc of
Right num -> show num
Left _ -> case ofString tc of
Right str -> "\"" ++ str ++ "\""
Left _ -> case ofNumber tc of
Right num -> "# " ++ show num
Left _ -> case ofList tc of
Right list -> "[" ++ unlines (map decodeResult list) ++ "]"
Left _ -> ""