diff options
author | Akshay <[email protected]> | 2020-10-08 06:23:41 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-10-08 06:23:41 +0100 |
commit | 0775dea2bc79cb1b5ee56f74f8076fc30a394127 (patch) | |
tree | 749e3d9534c3bea145a31cfe332c758720f71d3c /bin | |
parent | 4e60f9745e09959d0ce82810998d683372c0a1d4 (diff) |
init
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 | ||