aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Eval.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-04-12 00:09:35 +0200
committerMarvin Borner2022-04-12 00:09:35 +0200
commit32515bf8bf04958f22ce2cfe98edebc7b892774c (patch)
tree9432af890bb7d863e185fe3e2ae47bfa3e69dc52 /src/Eval.hs
Initial commit
Diffstat (limited to 'src/Eval.hs')
-rw-r--r--src/Eval.hs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Eval.hs b/src/Eval.hs
new file mode 100644
index 0000000..72c8985
--- /dev/null
+++ b/src/Eval.hs
@@ -0,0 +1,45 @@
+module Eval
+ ( evalMain
+ ) where
+
+import Control.Exception
+import Control.Monad.State
+import System.Console.Haskeline
+import System.Environment
+import System.Exit
+import System.IO
+
+type Environment = [String]
+
+eval :: String -> IO ()
+eval code = putStrLn "ok"
+
+evalFile :: String -> IO ()
+evalFile path = do
+ file <- try $ readFile path :: IO (Either IOError String)
+ case file of
+ Left exception -> print (exception :: IOError)
+ Right file -> eval file
+
+evalRepl :: String -> Environment -> InputT IO Environment
+evalRepl line env = outputStrLn (show env) >> pure env
+
+repl :: Environment -> InputT IO ()
+repl env =
+ getInputLine ":: "
+ >>= (\case
+ Nothing -> pure ()
+ Just line -> evalRepl line env >>= repl
+ )
+
+usage :: IO ()
+usage = putStrLn "Invalid arguments. Use 'bruijn [file]' instead"
+
+evalMain :: IO ()
+evalMain = do
+ args <- getArgs
+ case args of
+ [] -> runInputT defaultSettings { historyFile = Just ".brown-history" }
+ $ repl []
+ [path] -> evalFile path
+ _ -> usage