aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-16 14:24:46 +0100
committerAkshay <[email protected]>2020-10-16 14:24:46 +0100
commitb19a4a35db4cd951c52e179f3340518c9e2dcc1e (patch)
tree6d3d840a995d0467577ca645f5838a16d78aa3d6 /bin
parent684e09298b8453ee56571d8a225e11d7c57e3746 (diff)
add initial support for variable definition
Diffstat (limited to 'bin')
-rw-r--r--bin/Main.hs29
1 files changed, 18 insertions, 11 deletions
diff --git a/bin/Main.hs b/bin/Main.hs
index 54ed6b2..56ad0cd 100644
--- a/bin/Main.hs
+++ b/bin/Main.hs
@@ -1,7 +1,8 @@
1module Main where 1module Main where
2 2
3import Control.Monad (liftM) 3import Control.Monad (liftM)
4import Control.Monad.Except (throwError) 4import Control.Monad.Except (liftIO, runExceptT, throwError)
5import Environment
5import Error.Base (LispError (..), LispResult (..), 6import Error.Base (LispError (..), LispResult (..),
6 unwrap) 7 unwrap)
7import Error.Pretty (defaults, showError) 8import Error.Pretty (defaults, showError)
@@ -17,25 +18,31 @@ readExpr inp =
17 Left err -> throwError $ Parse err 18 Left err -> throwError $ Parse err
18 Right val -> return val 19 Right val -> return val
19 20
21evalExpr :: Env -> String -> IO (LispResult String)
22evalExpr env inp = runExceptT $ fmap show $
23 (liftLispResult $ readExpr inp) >>= eval env
20 24
21repl :: IO () 25repl :: Env -> IO ()
22repl = do 26repl env = do
23 -- \u2020 - obelisk 27 let pp = showError defaults "(lisk-repl)"
24 inp <- readline "† " 28 inp <- readline "† "
25 case inp of 29 case inp of
26 Nothing -> return () 30 Nothing -> return ()
27 Just ",q" -> return () 31 Just ",q" -> return ()
28 Just line -> do 32 Just i -> do
29 addHistory line 33 out <- evalExpr env i
30 let pp = showError defaults 34 either (putStrLn . pp) putStrLn out
31 either (putStrLn . pp line) print $ readExpr line >>= eval 35 repl env
32 repl 36
33 37
34main :: IO () 38main :: IO ()
35main = do 39main = do
36 args <- getArgs 40 args <- getArgs
41 initEnv <- newEnv
37 if null args 42 if null args
38 then do 43 then do
39 putStrLn ";;; Entering lisk repl ..." 44 putStrLn ";;; Entering lisk repl ..."
40 repl 45 repl initEnv
41 else print $ eval =<< readExpr (head args) 46 else do
47 let pp = showError defaults "(lisk-repl)"
48 evalExpr initEnv (head args) >>= (either (putStrLn . pp) print)