Compare commits

..

1 Commits

Author SHA1 Message Date
Suguivy a615c2110c Added instructions on README.md 2021-01-28 02:15:07 +00:00
3 changed files with 22 additions and 19 deletions

View File

@ -28,5 +28,4 @@ executable cherry
build-depends: base >= 4.7 && < 5,
containers,
parsec,
haskeline
parsec

View File

@ -3,22 +3,24 @@ module Main where
import Evaluator
import ExprParser
import Text.Parsec.Error
import Control.Monad
import Data.Maybe
import System.Console.Haskeline
import Data.Either
import System.IO
main :: IO ()
main = do
putStrLn logo
runInputT defaultSettings loop
where loop = do
line <- getInputLine "cherry> "
unless (isNothing line) $ do
let r = readEval $ fromJust line
outputStrLn $ case r of
Right res -> res
Left err -> show err
loop
putStrLn ""
putLogo
putStrLn ""
cycle
where cycle = do
putPrompt
hFlush stdout
s <- getLine
let r = readEval s
putStrLn $ case r of
(Right res) -> res
(Left err) -> show err
cycle
readEval :: String -> Either ParseError String
readEval s = do
@ -26,5 +28,8 @@ readEval s = do
let result = eval expr
return $ show result
logo :: String
logo = unlines [""," /\\", " | \\", " @ @",""]
putLogo :: IO ()
putLogo = putStr . concat $ map (++"\n") [" /\\", " | \\", " @ @"]
putPrompt :: IO ()
putPrompt = putStr "chery> "

View File

@ -34,8 +34,7 @@ packages:
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
extra-deps:
#- readline-1.0.3.0
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a