mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-09 19:22:50 -06:00
Reduced clutter in monadic code
+ Eliminated vairous ad-hoc coersion functions between specific monads (IO, Err, IOE, Check) in favor of more general lifting functions (liftIO, liftErr). + Generalized many basic monadic operations from specific monads to arbitrary monads in the appropriate class (MonadIO and/or ErrorMonad), thereby completely eliminating the need for lifting functions in lots of places. This can be considered a small step forward towards a cleaner compiler API and more malleable compiler code in general.
This commit is contained in:
@@ -55,9 +55,9 @@ compileSourceFiles opts fs =
|
||||
|
||||
compileCFFiles :: Options -> [FilePath] -> IOE ()
|
||||
compileCFFiles opts fs =
|
||||
do s <- ioeIO $ fmap unlines $ mapM readFile fs
|
||||
do s <- liftIO $ fmap unlines $ mapM readFile fs
|
||||
let cnc = justModuleName (last fs)
|
||||
gf <- ioeErr $ getCF cnc s
|
||||
gf <- getCF cnc s
|
||||
gr <- compileSourceGrammar opts gf
|
||||
if flag optStopAfterPhase opts == Compile
|
||||
then return ()
|
||||
@@ -76,7 +76,7 @@ unionPGFFiles opts fs =
|
||||
then putStrLnE $ "Refusing to overwrite " ++ pgfFile
|
||||
else writePGF opts pgf
|
||||
writeOutputs opts pgf
|
||||
where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ ioeIO $ readPGF f
|
||||
where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ liftIO $ readPGF f
|
||||
|
||||
writeOutputs :: Options -> PGF -> IOE ()
|
||||
writeOutputs opts pgf = do
|
||||
@@ -93,7 +93,7 @@ writeByteCode opts pgf
|
||||
path = case flag optOutputDir opts of
|
||||
Nothing -> file
|
||||
Just dir -> dir </> file
|
||||
in putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $
|
||||
in putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $
|
||||
bracket
|
||||
(openFile path WriteMode)
|
||||
(hClose)
|
||||
@@ -109,14 +109,14 @@ writeByteCode opts pgf
|
||||
writePGF :: Options -> PGF -> IOE ()
|
||||
writePGF opts pgf = do
|
||||
let outfile = grammarName opts pgf <.> "pgf"
|
||||
putPointE Normal opts ("Writing " ++ outfile ++ "...") $ ioeIO $ encodeFile outfile pgf
|
||||
putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf
|
||||
|
||||
grammarName :: Options -> PGF -> String
|
||||
grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts)
|
||||
|
||||
writeOutput :: Options -> FilePath-> String -> IOE ()
|
||||
writeOutput opts file str =
|
||||
putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $
|
||||
putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $
|
||||
writeUTF8File path str
|
||||
where
|
||||
path = maybe id (</>) (flag optOutputDir opts) file
|
||||
|
||||
Reference in New Issue
Block a user