aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-04 08:50:55 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-04 08:50:55 +0100
commitd4d7e4faa62bf32ca99e7fe2277bea905cda508d (patch)
treeca7e7ea760da525621bbb066d6711d6e99e5daa6 /src
parent70b68c91e008efb7a7b5baf638140cb76380f931 (diff)
downloadmicro-lang-hs-d4d7e4faa62bf32ca99e7fe2277bea905cda508d.tar.gz
micro-lang-hs-d4d7e4faa62bf32ca99e7fe2277bea905cda508d.zip
Parse only flag
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 8959329..6e57ba4 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -17,23 +17,30 @@ import System.IO (hPutStr, hPutStrLn, stderr, stdout)
version = "0.1.0"
data Options = Options
- { optHelp :: Bool,
+ { optParse :: Bool,
+ optHelp :: Bool,
optVersion :: Bool
}
defOptions =
Options
- { optHelp = False,
+ { optParse = False,
+ optHelp = False,
optVersion = False
}
options :: [OptDescr (Options -> Options)]
options =
[ Option
+ ['p']
+ ["parse"]
+ (NoArg (\opts -> opts {optParse = True}))
+ "only parse, reporting any errors",
+ Option
['h']
["help"]
(NoArg (\opts -> opts {optHelp = True}))
- "show help and exit",
+ "show help",
Option
['v']
["version"]
@@ -57,15 +64,15 @@ usage progName errs
helpText =
usageInfo header options
-compileFile :: String -> IO ()
-compileFile filename = do
+compileFile :: String -> Bool -> IO ()
+compileFile filename onlyParse = do
res <- parseFromFile (scan parse) filename
case res of
Left err -> hPutStrLn stderr (showParserError err) >> exitFailure
Right ast -> do
res <- return $ evalState (compileAll ast) startState
case res of
- Right _ -> print ast
+ Right _ -> if onlyParse then exitSuccess else print ast
Left errs -> hPutStr stderr (showErrorList errs) >> exitFailure
main :: IO ()
@@ -78,7 +85,7 @@ main = do
when (optHelp opts) $ usage progName []
when (optVersion opts) $ putStrLn (progName ++ " " ++ version) >> exitSuccess
case n of
- [filename] -> compileFile filename
+ [filename] -> compileFile filename $ optParse opts
_ -> usage progName []
where
opts = foldl (flip id) defOptions o