mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-15 15:59:32 -06:00
+ References to modules under src/compiler have been eliminated from the PGF library (under src/runtime/haskell). Only two functions had to be moved (from GF.Data.Utilities to PGF.Utilities) to make this possible, other apparent dependencies turned out to be vacuous. + In gf.cabal, the GF executable no longer directly depends on the PGF library source directory, but only on the exposed library modules. This means that there is less duplication in gf.cabal and that the 30 modules in the PGF library will no longer be compiled twice while building GF. To make this possible, additional PGF library modules have been exposed, even though they should probably be considered for internal use only. They could be collected in a PGF.Internal module, or marked as "unstable", to make this explicit. + Also, by using the -fwarn-unused-imports flag, ~220 redundant imports were found and removed, reducing the total number of imports by ~15%.
67 lines
2.4 KiB
Haskell
67 lines
2.4 KiB
Haskell
module GF.Compile.Export where
|
|
|
|
import PGF
|
|
import PGF.Printer(ppPGF)
|
|
import GF.Compile.PGFtoHaskell
|
|
import GF.Compile.PGFtoProlog
|
|
import GF.Compile.PGFtoLProlog
|
|
import GF.Compile.PGFtoJS
|
|
import GF.Compile.PGFtoPython
|
|
import GF.Infra.Option
|
|
--import GF.Speech.CFG
|
|
import GF.Speech.PGFToCFG
|
|
import GF.Speech.SRGS_ABNF
|
|
import GF.Speech.SRGS_XML
|
|
import GF.Speech.JSGF
|
|
import GF.Speech.GSL
|
|
import GF.Speech.SRG
|
|
import GF.Speech.VoiceXML
|
|
import GF.Speech.SLF
|
|
import GF.Speech.PrRegExp
|
|
|
|
import Data.Maybe
|
|
import System.FilePath
|
|
import Text.PrettyPrint
|
|
|
|
-- top-level access to code generation
|
|
|
|
exportPGF :: Options
|
|
-> OutputFormat
|
|
-> PGF
|
|
-> [(FilePath,String)] -- ^ List of recommended file names and contents.
|
|
exportPGF opts fmt pgf =
|
|
case fmt of
|
|
FmtPGFPretty -> multi "txt" (render . ppPGF)
|
|
FmtJavaScript -> multi "js" pgf2js
|
|
FmtPython -> multi "py" pgf2python
|
|
FmtHaskell -> multi "hs" (grammar2haskell opts name)
|
|
FmtProlog -> multi "pl" grammar2prolog
|
|
FmtLambdaProlog -> multi "mod" grammar2lambdaprolog_mod ++ multi "sig" grammar2lambdaprolog_sig
|
|
FmtBNF -> single "bnf" bnfPrinter
|
|
FmtEBNF -> single "ebnf" (ebnfPrinter opts)
|
|
FmtSRGS_XML -> single "grxml" (srgsXmlPrinter opts)
|
|
FmtSRGS_XML_NonRec -> single "grxml" (srgsXmlNonRecursivePrinter opts)
|
|
FmtSRGS_ABNF -> single "gram" (srgsAbnfPrinter opts)
|
|
FmtSRGS_ABNF_NonRec -> single "gram" (srgsAbnfNonRecursivePrinter opts)
|
|
FmtJSGF -> single "jsgf" (jsgfPrinter opts)
|
|
FmtGSL -> single "gsl" (gslPrinter opts)
|
|
FmtVoiceXML -> single "vxml" grammar2vxml
|
|
FmtSLF -> single "slf" slfPrinter
|
|
FmtRegExp -> single "rexp" regexpPrinter
|
|
FmtFA -> single "dot" slfGraphvizPrinter
|
|
where
|
|
name = fromMaybe (showCId (abstractName pgf)) (flag optName opts)
|
|
|
|
multi :: String -> (PGF -> String) -> [(FilePath,String)]
|
|
multi ext pr = [(name <.> ext, pr pgf)]
|
|
|
|
single :: String -> (PGF -> CId -> String) -> [(FilePath,String)]
|
|
single ext pr = [(showCId cnc <.> ext, pr pgf cnc) | cnc <- languages pgf]
|
|
|
|
-- | Get the name of the concrete syntax to generate output from.
|
|
-- FIXME: there should be an option to change this.
|
|
outputConcr :: PGF -> CId
|
|
outputConcr pgf = case languages pgf of
|
|
[] -> error "No concrete syntax."
|
|
cnc:_ -> cnc
|