mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-21 10:49:33 -06:00
Added OPTIONS class to make options handling somewhat nicer. Next, I will merge Flags and ModuleFlags.
This commit is contained in:
@@ -15,7 +15,7 @@ encodeStringsInModule = codeSourceModule encodeUTF8
|
||||
|
||||
decodeStringsInModule :: SourceModule -> SourceModule
|
||||
decodeStringsInModule mo = case mo of
|
||||
(_,ModMod m) -> case moduleFlag optEncoding (moduleOptions (flags m)) of
|
||||
(_,ModMod m) -> case flag optEncoding (flags m) of
|
||||
UTF_8 -> codeSourceModule decodeUTF8 mo
|
||||
CP_1251 -> codeSourceModule decodeCP1251 mo
|
||||
_ -> mo
|
||||
|
||||
@@ -51,7 +51,7 @@ exportPGF opts fmt pgf =
|
||||
FmtRegExp -> single "rexp" regexpPrinter
|
||||
FmtFA -> single "dot" slfGraphvizPrinter
|
||||
where
|
||||
name = fromMaybe (prCId (absname pgf)) (moduleFlag optName opts)
|
||||
name = fromMaybe (prCId (absname pgf)) (flag optName opts)
|
||||
|
||||
multi :: String -> (PGF -> String) -> [(FilePath,String)]
|
||||
multi ext pr = [(name <.> ext, pr pgf)]
|
||||
|
||||
@@ -38,7 +38,7 @@ import System.Cmd (system)
|
||||
|
||||
getSourceModule :: Options -> FilePath -> IOE SourceModule
|
||||
getSourceModule opts file0 = do
|
||||
file <- foldM runPreprocessor file0 (moduleFlag optPreprocessors opts)
|
||||
file <- foldM runPreprocessor file0 (flag optPreprocessors opts)
|
||||
string <- readFileIOE file
|
||||
let tokens = myLexer string
|
||||
mo1 <- ioeErr $ pModDef tokens
|
||||
|
||||
@@ -240,13 +240,13 @@ reorder abs cg = M.MGrammar $
|
||||
predefADefs =
|
||||
[(c, AbsCat (Yes []) Nope) | c <- [cFloat,cInt,cString]]
|
||||
aflags =
|
||||
concatModuleOptions [M.flags mo | (_,mo) <- M.allModMod cg, M.isModAbs mo]
|
||||
concatOptions [M.flags mo | (_,mo) <- M.allModMod cg, M.isModAbs mo]
|
||||
|
||||
cncs = sortIds [(lang, concr lang) | lang <- M.allConcretes cg abs]
|
||||
concr la = (flags,
|
||||
sortIds (predefCDefs ++ jments)) where
|
||||
jments = Look.allOrigInfos cg la
|
||||
flags = concatModuleOptions
|
||||
flags = concatOptions
|
||||
[M.flags mo |
|
||||
(i,mo) <- mos, M.isModCnc mo,
|
||||
Just r <- [lookup i (M.allExtendSpecs cg la)]]
|
||||
|
||||
@@ -58,8 +58,8 @@ optimizeModule opts mse@(ms,eenv) mo@(_,mi) = case mi of
|
||||
return (mo2,eenv)
|
||||
_ -> evalModule oopts mse mo
|
||||
where
|
||||
oopts = addOptions opts (moduleOptions (flagsModule mo))
|
||||
optim = moduleFlag optOptimizations oopts
|
||||
oopts = opts `addOptions` toOptions (flagsModule mo)
|
||||
optim = flag optOptimizations oopts
|
||||
|
||||
evalModule :: Options -> ([(Ident,SourceModInfo)],EEnv) -> (Ident,SourceModInfo) ->
|
||||
Err ((Ident,SourceModInfo),EEnv)
|
||||
@@ -102,7 +102,7 @@ evalResInfo oopts gr (c,info) = case info of
|
||||
where
|
||||
comp = if optres then computeConcrete gr else computeConcreteRec gr
|
||||
eIn cat = errIn ("Error optimizing" +++ cat +++ prt c +++ ":")
|
||||
optim = moduleFlag optOptimizations oopts
|
||||
optim = flag optOptimizations oopts
|
||||
optres = OptExpand `Set.member` optim
|
||||
|
||||
|
||||
|
||||
@@ -210,4 +210,4 @@ getOptionsFromFile file = do
|
||||
s <- ioeIO $ readFileIfStrict file
|
||||
let ls = filter (BS.isPrefixOf (BS.pack "--#")) $ BS.lines s
|
||||
fs = map (BS.unpack . BS.unwords . BS.words . BS.drop 3) ls
|
||||
ioeErr $ liftM moduleOptions $ parseModuleOptions fs
|
||||
ioeErr $ liftM toOptions $ parseModuleOptions fs
|
||||
|
||||
@@ -81,7 +81,7 @@ rebuildModule ms mo@(i,mi) = do
|
||||
++ [oSimple i | i <- map snd insts] ----
|
||||
|
||||
--- check if me is incomplete
|
||||
let fs1 = addModuleOptions fs fs_ -- new flags have priority
|
||||
let fs1 = fs `addOptions` fs_ -- new flags have priority
|
||||
let js0 = [ci | ci@(c,_) <- tree2list js, isInherited incl c]
|
||||
let js1 = buildTree (tree2list js_ ++ js0)
|
||||
let ps1 = buildTree (tree2list ps_ ++ tree2list ps0)
|
||||
|
||||
Reference in New Issue
Block a user