small steps towards actual error handling

This commit is contained in:
crumbtoo
2023-11-27 17:38:46 -07:00
parent 6fffb1345b
commit 77f0e7521e
2 changed files with 17 additions and 11 deletions

View File

@@ -50,33 +50,37 @@ debugFlagReader = maybeReader $ Just . \case
----------------------------------------------------------------------------------
-- temp
data CompilerError = CompilerError String
main :: IO ()
main = do
opts <- execParser optParser
evalRLPCIO opts driver
(_, es) <- evalRLPCIO opts driver
forM_ es $ \ (CompilerError e) -> print $ "warning: " <> e
pure ()
driver :: RLPCIO () ()
driver :: RLPCIO CompilerError ()
driver = sequence_
[ dshowFlags
, ddumpEval
]
dshowFlags :: RLPCIO () ()
dshowFlags :: RLPCIO CompilerError ()
dshowFlags = whenFlag flagDDumpOpts do
ask >>= liftIO . print
liftIO $ exitSuccess
ddumpEval :: RLPCIO () ()
ddumpEval :: RLPCIO CompilerError ()
ddumpEval = whenFlag flagDDumpEval do
fs <- view rlpcInputFiles
forM_ fs $ \f -> liftIO (readFile f) >>= doProg
where
doProg :: String -> RLPCIO () ()
doProg :: String -> RLPCIO CompilerError ()
doProg s = ask >>= \o -> case parseProg o s of
-- TODO: error handling
Left e -> error $ show e
Left e -> addFatal . CompilerError $ show e
Right (a,_) -> do
log <- view rlpcLogFile
case log of