summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Command
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-11-10 16:20:01 +0000
committerhallgren <hallgren@chalmers.se>2014-11-10 16:20:01 +0000
commitc707575bd7751ac3b03371edba478e37d3488448 (patch)
tree4d16d9dabed27b5d977d3d4d84a4bb317dff4a4a /src/compiler/GF/Command
parent33571ba44f2a42502722a3b025b448efe1f0ab88 (diff)
Documentation improvements and cleanup relating to the IOE monad
Renamed appIOE to tryIOE (it is analogous to 'try' in the standard libraries). Removed unused IOE operations & documented the remaining ones. Removed/simplified superfluous uses of IOE operations.
Diffstat (limited to 'src/compiler/GF/Command')
-rw-r--r--src/compiler/GF/Command/Importing.hs19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/compiler/GF/Command/Importing.hs b/src/compiler/GF/Command/Importing.hs
index e2284aa58..4ef966f77 100644
--- a/src/compiler/GF/Command/Importing.hs
+++ b/src/compiler/GF/Command/Importing.hs
@@ -10,7 +10,7 @@ import GF.Grammar (SourceGrammar) -- for cc command
import GF.Grammar.CFG
import GF.Grammar.EBNF
import GF.Compile.CFGtoPGF
-import GF.Infra.UseIO
+import GF.Infra.UseIO(die,tryIOE,useIOE)
import GF.Infra.Option
import GF.Data.ErrM
@@ -29,7 +29,7 @@ importGrammar pgf0 opts files =
let cs = concatMap snd ascss
importGrammar pgf0 opts cs
s | elem s [".gf",".gfo"] -> do
- res <- appIOE $ compileToPGF opts files
+ res <- tryIOE $ compileToPGF opts files
case res of
Ok pgf2 -> ioUnionPGF pgf0 pgf2
Bad msg -> do putStrLn ('\n':'\n':msg)
@@ -46,19 +46,10 @@ ioUnionPGF one two = case msgUnionPGF one two of
importSource :: SourceGrammar -> Options -> [FilePath] -> IO SourceGrammar
importSource src0 opts files = do
- src <- appIOE $ batchCompile opts files
- case src of
- Ok (_,(_,gr)) -> return gr
- Bad msg -> do
- putStrLn msg
- return src0
+ useIOE src0 (fmap (snd.snd) (batchCompile opts files))
-- for different cf formats
-importCF opts files get convert = do
- res <- appIOE impCF
- case res of
- Ok pgf -> return pgf
- Bad s -> error s
+importCF opts files get convert = impCF
where
impCF = do
rules <- fmap (convert . concat) $ mapM (get opts) files
@@ -66,6 +57,6 @@ importCF opts files get convert = do
(CFRule cat _ _ : _) -> return cat
_ -> fail "empty CFG"
let pgf = cf2pgf (last files) (uniqueFuns (mkCFG startCat Set.empty rules))
- probs <- liftIO (maybe (return . defaultProbabilities) readProbabilitiesFromFile (flag optProbsFile opts) pgf)
+ probs <- maybe (return . defaultProbabilities) readProbabilitiesFromFile (flag optProbsFile opts) pgf
return $ setProbabilities probs
$ if flag optOptimizePGF opts then optimizePGF pgf else pgf