Automatic decoding of supported literals in REPL
Automatic decoding & display of string, number, and list types in REPL. General updates to README, style, and comments.
This commit is contained in:
16
src/REPL.hs
16
src/REPL.hs
@ -11,19 +11,29 @@ import System.IO (hFlush, stdout)
|
||||
|
||||
repl :: Map.Map String T -> IO ()
|
||||
repl env = do
|
||||
putStr "sapling > "
|
||||
putStr "sapling < "
|
||||
hFlush stdout
|
||||
input <- getLine
|
||||
if input == "_:exit"
|
||||
then putStrLn "Goodbye!"
|
||||
else if input == ""
|
||||
then do
|
||||
then do
|
||||
putStrLn ""
|
||||
repl env
|
||||
else do
|
||||
let clearEnv = Map.delete "__result" env
|
||||
let newEnv = evalSingle clearEnv (parseSingle input)
|
||||
case Map.lookup "__result" newEnv of
|
||||
Just r -> putStrLn $ "sapling < " ++ show r
|
||||
Just r -> do
|
||||
putStrLn $ "sapling > " ++ show r
|
||||
putStrLn $ "DECODE -: " ++ (decodeResult r)
|
||||
Nothing -> pure ()
|
||||
repl newEnv
|
||||
|
||||
decodeResult :: T -> String
|
||||
decodeResult tc =
|
||||
case ofString tc of
|
||||
Right str -> "\"" ++ str ++ "\""
|
||||
Left _ -> case ofNumber tc of
|
||||
Right num -> "Number: " ++ show num
|
||||
Left _ -> "Failed to decode number from Tree"
|
||||
|
Reference in New Issue
Block a user