diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Main.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/Main.hs b/bin/Main.hs new file mode 100644 index 0000000..2942566 --- /dev/null +++ b/bin/Main.hs | |||
@@ -0,0 +1,26 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Evaluator (eval) | ||
4 | import Parser (Expr (..), parseLispValue) | ||
5 | import System.Console.Readline | ||
6 | import Text.ParserCombinators.Parsec | ||
7 | |||
8 | readExpr :: String -> Expr | ||
9 | readExpr inp = | ||
10 | case parse parseLispValue "(unknown)" inp of | ||
11 | Left err -> StringLiteral $ show err | ||
12 | Right val -> val | ||
13 | |||
14 | repl :: IO () | ||
15 | repl = do | ||
16 | inp <- readline "(lisk)> " | ||
17 | case inp of | ||
18 | Nothing -> return () | ||
19 | Just ",q" -> return () | ||
20 | Just line -> do | ||
21 | addHistory line | ||
22 | print . eval . readExpr $ line | ||
23 | repl | ||
24 | |||
25 | main :: IO () | ||
26 | main = repl | ||