Adds "compiler" and CLI argument handling

This commit is contained in:
James Eversole
2024-12-29 21:49:57 -06:00
parent 467e11edb3
commit 2abeab9c04
7 changed files with 69 additions and 12 deletions

View File

@ -1,5 +1,6 @@
module Main where
import Compiler
import Eval (evalTricu, result)
import Library (library)
import Parser (parseTricu)
@ -7,16 +8,40 @@ import REPL (repl)
import Research (T)
import Text.Megaparsec (runParser)
import System.Console.CmdArgs
import qualified Data.Map as Map
data TricuArgs
= Repl
| Compile { file :: FilePath }
deriving (Show, Data, Typeable)
replMode :: TricuArgs
replMode = Repl
&= help "Start interactive REPL"
&= auto
&= name "repl"
compileMode :: TricuArgs
compileMode = Compile { file = def &= typ "FILE" &= help "Relative or absolute path to compile" }
&= help "Compile a file and return the result of the expression in the final line"
&= explicit
&= name "compile"
main :: IO ()
main = do
putStrLn "Welcome to the tricu Interpreter"
putStrLn "You can exit at any time by typing and entering: "
putStrLn ":_exit"
repl library
args <- cmdArgs $ modes [replMode, compileMode]
&= help "tricu: Exploring Tree Calculus"
&= program "tricu"
&= summary "tricu - compiler and repl"
case args of
Repl -> do
putStrLn "Welcome to the tricu REPL"
putStrLn "You can exit with `CTRL+D` or the `:_exit` command.`"
repl Map.empty
Compile filePath -> do
result <- evaluateFile filePath
print result
runTricu :: String -> T
runTricu s = result (evalTricu Map.empty $ parseTricu s)
runTricuEnv env s = result (evalTricu env $ parseTricu s)