aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-11 20:28:58 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-11 20:28:58 +0100
commit0a49f4e86d61c14e2d457e03cb56c65c764d8e55 (patch)
treebafcbdb417e8141e1a4926d64a9f02c9e4b6f517 /app
parentb8f7dd3220564fa641f4f0b23adadce7b2543436 (diff)
downloadmicro-lang-hs-0a49f4e86d61c14e2d457e03cb56c65c764d8e55.tar.gz
micro-lang-hs-0a49f4e86d61c14e2d457e03cb56c65c764d8e55.zip
Better job splitting constnt folding
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 4a3128a..5c07165 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -15,6 +15,7 @@ import System.IO (hPutStr, hPutStrLn, stderr, stdout)
data Options = Options
{ optParse :: Bool,
+ optAst :: Bool,
optHelp :: Bool,
optVersion :: Bool
}
@@ -22,6 +23,7 @@ data Options = Options
defOptions =
Options
{ optParse = False,
+ optAst = False,
optHelp = False,
optVersion = False
}
@@ -34,6 +36,11 @@ options =
(NoArg (\opts -> opts {optParse = True}))
"only parse, reporting any errors",
Option
+ ['a']
+ ["ast"]
+ (NoArg (\opts -> opts {optAst = True}))
+ "parse and output the AST",
+ Option
['h']
["help"]
(NoArg (\opts -> opts {optHelp = True}))
@@ -61,13 +68,13 @@ usage progName errs
helpText =
usageInfo header options
-compileFile :: String -> Bool -> IO ()
-compileFile filename onlyParse = do
+compileFile :: String -> Bool -> Bool -> IO ()
+compileFile filename onlyParse showAst = do
res <- parseFromFile filename
case res of
Left err -> hPutStrLn stderr (showParserError err) >> exitFailure
Right ast -> do
- res <- return $ compile ast
+ res <- return $ if showAst then fmap (\ast -> show ast) (compileToAst ast) else compile ast
case res of
Right out -> if onlyParse then exitSuccess else hPutStrLn stdout out
Left errs -> hPutStr stderr (showErrorList errs) >> exitFailure
@@ -82,7 +89,7 @@ main = do
when (optHelp opts) $ usage progName []
when (optVersion opts) $ putStrLn (progName ++ " " ++ version) >> exitSuccess
case n of
- [filename] -> compileFile filename $ optParse opts
+ [filename] -> compileFile filename (optParse opts) (optAst opts)
_ -> usage progName []
where
opts = foldl (flip id) defOptions o