Made it easier to print out a plain String after processing the command-line options

This commit is contained in:
Neil Brown 2009-04-04 12:27:56 +00:00
parent c9f9eb8587
commit 18f37a0d96

29
Main.hs
View File

@ -54,7 +54,11 @@ import PrettyShow
import ShowCode import ShowCode
import Utils import Utils
type OptFunc = CompState -> IO CompState -- Either gives back options, or an exact string to print out:
type OptFunc = CompState -> ErrorT String IO CompState
printString :: String -> ErrorT String IO a
printString = throwError
optionsNoWarnings :: [OptDescr OptFunc] optionsNoWarnings :: [OptDescr OptFunc]
optionsNoWarnings = optionsNoWarnings =
@ -153,10 +157,10 @@ optOutput :: String -> OptFunc
optOutput s ps = return $ ps { csOutputFile = s } optOutput s ps = return $ ps { csOutputFile = s }
optPrintHelp :: OptFunc optPrintHelp :: OptFunc
optPrintHelp _ = dieIO (Nothing, usageInfo "Usage: tock [OPTION...] SOURCEFILE" optionsNoWarnings) optPrintHelp _ = printString $ usageInfo "Usage: tock [OPTION...] SOURCEFILE" optionsNoWarnings
optPrintWarningHelp :: OptFunc optPrintWarningHelp :: OptFunc
optPrintWarningHelp _ = dieIO (Nothing, usageInfo "Usage: tock [OPTION...] SOURCEFILE" optionsWarnings) optPrintWarningHelp _ = printString $ usageInfo "Usage: tock [OPTION...] SOURCEFILE" optionsWarnings
optOnOff :: (String, Bool -> CompState -> CompState) -> String -> OptFunc optOnOff :: (String, Bool -> CompState -> CompState) -> String -> OptFunc
optOnOff (n, f) s ps optOnOff (n, f) s ps
@ -210,19 +214,20 @@ main = do
Just $ take (length fn - length ".rain") fn) Just $ take (length fn - length ".rain") fn)
else (id, Nothing) else (id, Nothing)
initState <- foldl (>>=) (return $ frontendGuess emptyState) opts res <- runErrorT $ foldl (>>=) (return $ frontendGuess emptyState) opts
case res of
let operation Left str -> putStrLn str
= case csMode initState of Right initState -> do
let operation = case csMode initState of
ModePostC -> useOutputOptions (postCAnalyse fn) ModePostC -> useOutputOptions (postCAnalyse fn)
ModeFull -> evalStateT (compileFull fn fileStem) [] ModeFull -> evalStateT (compileFull fn fileStem) []
mode -> useOutputOptions (compile mode fn) mode -> useOutputOptions (compile mode fn)
-- Run the compiler. -- Run the compiler.
v <- runPassM initState operation v <- runPassM initState operation
case v of case v of
(Left e, cs) -> showWarnings (csWarnings cs) >> dieIO e (Left e, cs) -> showWarnings (csWarnings cs) >> dieIO e
(Right r, cs) -> showWarnings (csWarnings cs) (Right r, cs) -> showWarnings (csWarnings cs)
removeFiles :: [FilePath] -> IO () removeFiles :: [FilePath] -> IO ()
removeFiles = mapM_ (\file -> catch (removeFile file) doNothing) removeFiles = mapM_ (\file -> catch (removeFile file) doNothing)