module REPL where -- import Calc import System.Console.Readline import System -- import Useful {- untag ('<':xs) = intag xs untag (x:xs) = x : untag xs untag [] = [] intag ('>':xs) = untag xs intag (x:xs) = intag xs intag [] = [] -} main = do path <- checkPath "units.txt" cnts <- readFile path hs <- newHashes errors <- mapM (\s -> run hs s) (lines cnts) mapM_ myPutStrLn errors putStrLn startMessage loop (myF hs) -- (untag . calc) prompt = ">>> " isQuit (':':'q':_) = True isQuit _ = False -- isHelp (':':'h':_) = True -- isHelp _ = False version = "0.2.1" startMessage = "calc "++version++"\n"++ ":q or ^D to quit" leavingMessage = "Leaving calc" loop f = do s <- readline prompt case s of Nothing -> putStrLn $ "\n" ++ leavingMessage Just str -> do if isQuit str then putStrLn leavingMessage else do addHistory str result <- f str putStrLn result -- $ f str loop f myF hs x = do c <- calc hs x return $ untag c myPutStrLn x = if x == "" then return () else putStrLn $ untag x