From d13b32ea48d255c71670321c9b8d0d611afe0a17 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 17 Jun 2008 12:29:11 +0000 Subject: Refactor grammar export code. --- src-3.0/GFC.hs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'src-3.0/GFC.hs') 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 $ -- cgit v1.2.3