diff options
| author | bjorn <bjorn@bringert.net> | 2008-06-17 12:29:11 +0000 |
|---|---|---|
| committer | bjorn <bjorn@bringert.net> | 2008-06-17 12:29:11 +0000 |
| commit | d13b32ea48d255c71670321c9b8d0d611afe0a17 (patch) | |
| tree | 0e4a98d507eb02f7c4e83815f66667d273d36a16 /src-3.0/GFC.hs | |
| parent | 2cf7a7d07eaa394c56ca020f7383ba747d9374a3 (diff) | |
Refactor grammar export code.
Diffstat (limited to 'src-3.0/GFC.hs')
| -rw-r--r-- | src-3.0/GFC.hs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src-3.0/GFC.hs b/src-3.0/GFC.hs index c663f46c9..17c95eb30 100644 --- a/src-3.0/GFC.hs +++ b/src-3.0/GFC.hs @@ -26,30 +26,17 @@ mainGFC opts fs = writeOutputs opts pgf writeOutputs :: Options -> PGF -> IOE () -writeOutputs opts pgf = mapM_ (\fmt -> writeOutput opts fmt pgf) (flag optOutputFormats opts) - -writeOutput :: Options -> OutputFormat-> PGF -> IOE () -writeOutput opts fmt pgf = - do let name = fromMaybe (prCId (absname pgf)) (moduleFlag optName opts) - path = outputFilePath opts fmt name - s = prPGF opts fmt pgf name - writeOutputFile path s - -outputFilePath :: Options -> OutputFormat -> String -> FilePath -outputFilePath opts fmt name0 = addDir name <.> fmtExtension fmt - where name = fromMaybe name0 (moduleFlag optName opts) - addDir = maybe id (</>) (flag optOutputDir opts) - -fmtExtension :: OutputFormat -> String -fmtExtension FmtPGF = "pgf" -fmtExtension FmtJavaScript = "js" -fmtExtension FmtHaskell = "hs" -fmtExtension FmtHaskell_GADT = "hs" -fmtExtension FmtBNF = "bnf" -fmtExtension FmtSRGS_XML = "grxml" -fmtExtension FmtJSGF = "jsgf" -fmtExtension FmtGSL = "gsl" -fmtExtension FmtVoiceXML = "vxml" +writeOutputs opts pgf = + sequence_ [writeOutput opts name str + | fmt <- flag optOutputFormats opts, + (name,str) <- exportPGF opts fmt pgf] + +writeOutput :: Options -> FilePath-> String -> IOE () +writeOutput opts file str = + do let path = case flag optOutputDir opts of + Nothing -> file + Just dir -> dir </> file + writeOutputFile path str writeOutputFile :: FilePath -> String -> IOE () writeOutputFile outfile output = ioeIO $ |
