Update lambda handling; better default decode out
This commit is contained in:
53
src/REPL.hs
53
src/REPL.hs
@ -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 _ -> ""
|
||||
|
Reference in New Issue
Block a user