Compare commits
2 Commits
a615c2110c
...
24ed67ae71
Author | SHA1 | Date |
---|---|---|
Ivy | 24ed67ae71 | |
Ivy | 2e3f9d321e |
11
README.md
11
README.md
|
@ -10,4 +10,15 @@ cherry> (+ 2 3 4)
|
||||||
9
|
9
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
```
|
||||||
|
# apt install haskell-stack
|
||||||
|
$ git clone https://git.fai.su/Suguivy/cherry-lisp
|
||||||
|
$ cd cherry-lisp
|
||||||
|
# stack upgrade
|
||||||
|
$ stack build
|
||||||
|
$ stack install
|
||||||
|
$ cherry
|
||||||
|
```
|
||||||
|
|
||||||
Work in progress...
|
Work in progress...
|
||||||
|
|
|
@ -28,4 +28,5 @@ 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,24 +3,22 @@ module Main where
|
||||||
import Evaluator
|
import Evaluator
|
||||||
import ExprParser
|
import ExprParser
|
||||||
import Text.Parsec.Error
|
import Text.Parsec.Error
|
||||||
import Data.Either
|
import Control.Monad
|
||||||
import System.IO
|
import Data.Maybe
|
||||||
|
import System.Console.Haskeline
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
putStrLn ""
|
putStrLn logo
|
||||||
putLogo
|
runInputT defaultSettings loop
|
||||||
putStrLn ""
|
where loop = do
|
||||||
cycle
|
line <- getInputLine "cherry> "
|
||||||
where cycle = do
|
unless (isNothing line) $ do
|
||||||
putPrompt
|
let r = readEval $ fromJust line
|
||||||
hFlush stdout
|
outputStrLn $ case r of
|
||||||
s <- getLine
|
Right res -> res
|
||||||
let r = readEval s
|
Left err -> show err
|
||||||
putStrLn $ case r of
|
loop
|
||||||
(Right res) -> res
|
|
||||||
(Left err) -> show err
|
|
||||||
cycle
|
|
||||||
|
|
||||||
readEval :: String -> Either ParseError String
|
readEval :: String -> Either ParseError String
|
||||||
readEval s = do
|
readEval s = do
|
||||||
|
@ -28,8 +26,5 @@ readEval s = do
|
||||||
let result = eval expr
|
let result = eval expr
|
||||||
return $ show result
|
return $ show result
|
||||||
|
|
||||||
putLogo :: IO ()
|
logo :: String
|
||||||
putLogo = putStr . concat $ map (++"\n") [" /\\", " | \\", " @ @"]
|
logo = unlines [""," /\\", " | \\", " @ @",""]
|
||||||
|
|
||||||
putPrompt :: IO ()
|
|
||||||
putPrompt = putStr "chery> "
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ 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