{---- - Repl.hs - the noodle read-eval-print-loop ---- - Author: Jesse Rudolph - See LICENSE for licensing details ----------------------------------------------------------------- -} module Main ( main ) where import System.Environment import Data.List import System.IO import qualified Language.Noodle.Banner as Banner import Language.Noodle.DepTree import Language.Noodle.Evaluation import Language.Noodle.Lib.Basic import Language.Noodle.Syntax import Language.Noodle.Parsing.String import Language.Noodle.Parsing.Noodle main = do args <- getArgs case args of [] -> repl env [filepath] -> exec filepath _ -> error "invalid command line arguments" -- execute a source file exec :: FilePath -> IO () exec file = do val <- compileFile env file case val of Module e -> do env <- e repl env Error err -> error ("Uncaught Error\n" ++ show err) v -> error $ file ++ " compiled to something other than a module (bug)" repl :: Env -> IO () repl e = do putStr "noodle> " hFlush stdout i <- getLine case (runp comp (startPos,()) i) of Success res _ _ -> do v <- compute e res putStrLn $ " ==>" ++ show v Failure msg ((_,rel,line),_) -> putStrLn $ (show $ Error $ BadParse i line rel msg) putStr "\n" repl e