Compare commits
1 Commits
24ed67ae71
...
a615c2110c
Author | SHA1 | Date |
---|---|---|
Suguivy | a615c2110c |
|
@ -28,5 +28,4 @@ executable cherry
|
||||||
|
|
||||||
build-depends: base >= 4.7 && < 5,
|
build-depends: base >= 4.7 && < 5,
|
||||||
containers,
|
containers,
|
||||||
parsec,
|
parsec
|
||||||
haskeline
|
|
||||||
|
|
35
src/Main.hs
35
src/Main.hs
|
@ -3,22 +3,24 @@ module Main where
|
||||||
import Evaluator
|
import Evaluator
|
||||||
import ExprParser
|
import ExprParser
|
||||||
import Text.Parsec.Error
|
import Text.Parsec.Error
|
||||||
import Control.Monad
|
import Data.Either
|
||||||
import Data.Maybe
|
import System.IO
|
||||||
import System.Console.Haskeline
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
putStrLn logo
|
putStrLn ""
|
||||||
runInputT defaultSettings loop
|
putLogo
|
||||||
where loop = do
|
putStrLn ""
|
||||||
line <- getInputLine "cherry> "
|
cycle
|
||||||
unless (isNothing line) $ do
|
where cycle = do
|
||||||
let r = readEval $ fromJust line
|
putPrompt
|
||||||
outputStrLn $ case r of
|
hFlush stdout
|
||||||
Right res -> res
|
s <- getLine
|
||||||
Left err -> show err
|
let r = readEval s
|
||||||
loop
|
putStrLn $ case r of
|
||||||
|
(Right res) -> res
|
||||||
|
(Left err) -> show err
|
||||||
|
cycle
|
||||||
|
|
||||||
readEval :: String -> Either ParseError String
|
readEval :: String -> Either ParseError String
|
||||||
readEval s = do
|
readEval s = do
|
||||||
|
@ -26,5 +28,8 @@ readEval s = do
|
||||||
let result = eval expr
|
let result = eval expr
|
||||||
return $ show result
|
return $ show result
|
||||||
|
|
||||||
logo :: String
|
putLogo :: IO ()
|
||||||
logo = unlines [""," /\\", " | \\", " @ @",""]
|
putLogo = putStr . concat $ map (++"\n") [" /\\", " | \\", " @ @"]
|
||||||
|
|
||||||
|
putPrompt :: IO ()
|
||||||
|
putPrompt = putStr "chery> "
|
||||||
|
|
|
@ -34,8 +34,7 @@ packages:
|
||||||
# These entries can reference officially published versions as well as
|
# These entries can reference officially published versions as well as
|
||||||
# forks / in-progress versions pinned to a git hash. For example:
|
# forks / in-progress versions pinned to a git hash. For example:
|
||||||
#
|
#
|
||||||
extra-deps:
|
# extra-deps:
|
||||||
#- readline-1.0.3.0
|
|
||||||
# - acme-missiles-0.3
|
# - acme-missiles-0.3
|
||||||
# - git: https://github.com/commercialhaskell/stack.git
|
# - git: https://github.com/commercialhaskell/stack.git
|
||||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||||
|
|
Loading…
Reference in New Issue