mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 08:32:50 -06:00
Added --sisr option for including SISR tags in generated SRGs.
This commit is contained in:
@@ -17,6 +17,7 @@ import PGF.Data ----
|
|||||||
import PGF.Morphology
|
import PGF.Morphology
|
||||||
import PGF.Quiz
|
import PGF.Quiz
|
||||||
import GF.Compile.Export
|
import GF.Compile.Export
|
||||||
|
import GF.Infra.Option (noOptions)
|
||||||
import GF.Infra.UseIO
|
import GF.Infra.UseIO
|
||||||
import GF.Data.ErrM ----
|
import GF.Data.ErrM ----
|
||||||
import PGF.ExprSyntax (readExp)
|
import PGF.ExprSyntax (readExp)
|
||||||
@@ -446,7 +447,7 @@ allCommands pgf = Map.fromList [
|
|||||||
unlines $ [unwords (la:":": map prCId cs) |
|
unlines $ [unwords (la:":": map prCId cs) |
|
||||||
la <- optLangs opts, let cs = missingLins pgf (mkCId la)]
|
la <- optLangs opts, let cs = missingLins pgf (mkCId la)]
|
||||||
_ -> case valIdOpts "printer" "pgf" opts of
|
_ -> case valIdOpts "printer" "pgf" opts of
|
||||||
v -> prPGF (read v) pgf (prCId (absname pgf))
|
v -> prPGF noOptions (read v) pgf (prCId (absname pgf))
|
||||||
|
|
||||||
morphos opts s =
|
morphos opts s =
|
||||||
[lookupMorpho (buildMorpho pgf (mkCId la)) s | la <- optLangs opts]
|
[lookupMorpho (buildMorpho pgf (mkCId la)) s | la <- optLangs opts]
|
||||||
|
|||||||
@@ -16,19 +16,20 @@ import GF.Text.UTF8
|
|||||||
|
|
||||||
-- top-level access to code generation
|
-- top-level access to code generation
|
||||||
|
|
||||||
prPGF :: OutputFormat
|
prPGF :: Options
|
||||||
|
-> OutputFormat
|
||||||
-> PGF
|
-> PGF
|
||||||
-> String -- ^ Output name, for example used for generated Haskell
|
-> String -- ^ Output name, for example used for generated Haskell
|
||||||
-- module name.
|
-- module name.
|
||||||
-> String
|
-> String
|
||||||
prPGF fmt gr name = case fmt of
|
prPGF opts fmt gr name = case fmt of
|
||||||
FmtPGF -> printPGF gr
|
FmtPGF -> printPGF gr
|
||||||
FmtJavaScript -> pgf2js gr
|
FmtJavaScript -> pgf2js gr
|
||||||
FmtHaskell -> grammar2haskell gr name
|
FmtHaskell -> grammar2haskell gr name
|
||||||
FmtHaskell_GADT -> grammar2haskellGADT gr name
|
FmtHaskell_GADT -> grammar2haskellGADT gr name
|
||||||
FmtBNF -> prCFG $ pgfToCFG gr (outputConcr gr)
|
FmtBNF -> prCFG $ pgfToCFG gr (outputConcr gr)
|
||||||
FmtSRGS_XML -> srgsXmlPrinter Nothing gr (outputConcr gr)
|
FmtSRGS_XML -> srgsXmlPrinter (flag optSISR opts) gr (outputConcr gr)
|
||||||
FmtJSGF -> jsgfPrinter Nothing gr (outputConcr gr)
|
FmtJSGF -> jsgfPrinter (flag optSISR opts) gr (outputConcr gr)
|
||||||
FmtVoiceXML -> grammar2vxml gr (outputConcr gr)
|
FmtVoiceXML -> grammar2vxml gr (outputConcr gr)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ module GF.Infra.Option
|
|||||||
-- * Option types
|
-- * Option types
|
||||||
Options, ModuleOptions,
|
Options, ModuleOptions,
|
||||||
Flags(..), ModuleFlags(..),
|
Flags(..), ModuleFlags(..),
|
||||||
Mode(..), Phase(..), Verbosity(..), Encoding(..), OutputFormat(..), Optimization(..),
|
Mode(..), Phase(..), Verbosity(..), Encoding(..), OutputFormat(..),
|
||||||
|
SISRFormat(..), Optimization(..),
|
||||||
Dump(..), Printer(..), Recomp(..),
|
Dump(..), Printer(..), Recomp(..),
|
||||||
-- * Option parsing
|
-- * Option parsing
|
||||||
parseOptions, parseModuleOptions,
|
parseOptions, parseModuleOptions,
|
||||||
@@ -93,6 +94,13 @@ data OutputFormat = FmtPGF
|
|||||||
| FmtFA
|
| FmtFA
|
||||||
deriving (Eq,Ord)
|
deriving (Eq,Ord)
|
||||||
|
|
||||||
|
data SISRFormat =
|
||||||
|
-- | SISR Working draft 1 April 2003
|
||||||
|
-- <http://www.w3.org/TR/2003/WD-semantic-interpretation-20030401/>
|
||||||
|
SISR_WD20030401
|
||||||
|
| SISR_1_0
|
||||||
|
deriving (Show,Eq,Ord)
|
||||||
|
|
||||||
data Optimization = OptStem | OptCSE | OptExpand | OptParametrize | OptValues
|
data Optimization = OptStem | OptCSE | OptExpand | OptParametrize | OptValues
|
||||||
deriving (Show,Eq,Ord)
|
deriving (Show,Eq,Ord)
|
||||||
|
|
||||||
@@ -137,6 +145,7 @@ data Flags = Flags {
|
|||||||
optEmitGFO :: Bool,
|
optEmitGFO :: Bool,
|
||||||
optGFODir :: FilePath,
|
optGFODir :: FilePath,
|
||||||
optOutputFormats :: [OutputFormat],
|
optOutputFormats :: [OutputFormat],
|
||||||
|
optSISR :: Maybe SISRFormat,
|
||||||
optOutputFile :: Maybe FilePath,
|
optOutputFile :: Maybe FilePath,
|
||||||
optOutputDir :: Maybe FilePath,
|
optOutputDir :: Maybe FilePath,
|
||||||
optRecomp :: Recomp,
|
optRecomp :: Recomp,
|
||||||
@@ -279,6 +288,7 @@ defaultFlags = Flags {
|
|||||||
optEmitGFO = True,
|
optEmitGFO = True,
|
||||||
optGFODir = ".",
|
optGFODir = ".",
|
||||||
optOutputFormats = [FmtPGF],
|
optOutputFormats = [FmtPGF],
|
||||||
|
optSISR = Nothing,
|
||||||
optOutputFile = Nothing,
|
optOutputFile = Nothing,
|
||||||
optOutputDir = Nothing,
|
optOutputDir = Nothing,
|
||||||
optRecomp = RecompIfNewer,
|
optRecomp = RecompIfNewer,
|
||||||
@@ -383,6 +393,9 @@ optDescr =
|
|||||||
"Multiple concrete: pgf (default), gar, js, ...",
|
"Multiple concrete: pgf (default), gar, js, ...",
|
||||||
"Single concrete only: cf, bnf, lbnf, gsl, srgs_xml, srgs_abnf, ...",
|
"Single concrete only: cf, bnf, lbnf, gsl, srgs_xml, srgs_abnf, ...",
|
||||||
"Abstract only: haskell, ..."]),
|
"Abstract only: haskell, ..."]),
|
||||||
|
Option [] ["sisr"] (ReqArg sisrFmt "FMT")
|
||||||
|
(unlines ["Include SISR tags in generated speech recognition grammars.",
|
||||||
|
"FMT can be one of: old, 1.0"]),
|
||||||
Option ['o'] ["output-file"] (ReqArg outFile "FILE")
|
Option ['o'] ["output-file"] (ReqArg outFile "FILE")
|
||||||
"Save output in FILE (default is out.X, where X depends on output format.",
|
"Save output in FILE (default is out.X, where X depends on output format.",
|
||||||
Option ['D'] ["output-dir"] (ReqArg outDir "DIR")
|
Option ['D'] ["output-dir"] (ReqArg outDir "DIR")
|
||||||
@@ -410,6 +423,10 @@ optDescr =
|
|||||||
gfoDir x = set $ \o -> o { optGFODir = x }
|
gfoDir x = set $ \o -> o { optGFODir = x }
|
||||||
outFmt x = readOutputFormat x >>= \f ->
|
outFmt x = readOutputFormat x >>= \f ->
|
||||||
set $ \o -> o { optOutputFormats = optOutputFormats o ++ [f] }
|
set $ \o -> o { optOutputFormats = optOutputFormats o ++ [f] }
|
||||||
|
sisrFmt x = case x of
|
||||||
|
"old" -> set $ \o -> o { optSISR = Just SISR_WD20030401 }
|
||||||
|
"1.0" -> set $ \o -> o { optSISR = Just SISR_1_0 }
|
||||||
|
_ -> fail $ "Unknown SISR format: " ++ show x
|
||||||
outFile x = set $ \o -> o { optOutputFile = Just x }
|
outFile x = set $ \o -> o { optOutputFile = Just x }
|
||||||
outDir x = set $ \o -> o { optOutputDir = Just x }
|
outDir x = set $ \o -> o { optOutputDir = Just x }
|
||||||
recomp x = set $ \o -> o { optRecomp = x }
|
recomp x = set $ \o -> o { optRecomp = x }
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import Data.List
|
|||||||
|
|
||||||
import GF.Data.Utilities
|
import GF.Data.Utilities
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
|
import GF.Infra.Option (SISRFormat(..))
|
||||||
import GF.Speech.CFG
|
import GF.Speech.CFG
|
||||||
import GF.Speech.SRG (SRGNT)
|
import GF.Speech.SRG (SRGNT)
|
||||||
import PGF.CId
|
import PGF.CId
|
||||||
@@ -19,12 +20,6 @@ import PGF.CId
|
|||||||
import qualified GF.JavaScript.AbsJS as JS
|
import qualified GF.JavaScript.AbsJS as JS
|
||||||
import qualified GF.JavaScript.PrintJS as JS
|
import qualified GF.JavaScript.PrintJS as JS
|
||||||
|
|
||||||
data SISRFormat =
|
|
||||||
-- SISR Working draft 1 April 2003
|
|
||||||
-- http://www.w3.org/TR/2003/WD-semantic-interpretation-20030401/
|
|
||||||
SISROld
|
|
||||||
deriving Show
|
|
||||||
|
|
||||||
type SISRTag = [JS.DeclOrExpr]
|
type SISRTag = [JS.DeclOrExpr]
|
||||||
|
|
||||||
|
|
||||||
@@ -62,9 +57,9 @@ profileFinalSISR term fmt = [JS.DExpr $ fmtOut fmt `ass` f term]
|
|||||||
f (CFVar v) = JS.EVar (var v)
|
f (CFVar v) = JS.EVar (var v)
|
||||||
f (CFMeta typ) = obj [("name",JS.EStr "?"), ("type",JS.EStr (prCId typ))]
|
f (CFMeta typ) = obj [("name",JS.EStr "?"), ("type",JS.EStr (prCId typ))]
|
||||||
|
|
||||||
fmtOut SISROld = JS.EVar (JS.Ident "$")
|
fmtOut SISR_WD20030401 = JS.EVar (JS.Ident "$")
|
||||||
|
|
||||||
fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c))
|
fmtRef SISR_WD20030401 c = JS.EVar (JS.Ident ("$" ++ c))
|
||||||
|
|
||||||
args = JS.Ident "a"
|
args = JS.Ident "a"
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ writeOutput :: Options -> OutputFormat-> PGF -> IOE ()
|
|||||||
writeOutput opts fmt pgf =
|
writeOutput opts fmt pgf =
|
||||||
do let name = fromMaybe (prCId (absname pgf)) (moduleFlag optName opts)
|
do let name = fromMaybe (prCId (absname pgf)) (moduleFlag optName opts)
|
||||||
path = outputFilePath opts fmt name
|
path = outputFilePath opts fmt name
|
||||||
s = prPGF fmt pgf name
|
s = prPGF opts fmt pgf name
|
||||||
writeOutputFile path s
|
writeOutputFile path s
|
||||||
|
|
||||||
outputFilePath :: Options -> OutputFormat -> String -> FilePath
|
outputFilePath :: Options -> OutputFormat -> String -> FilePath
|
||||||
|
|||||||
Reference in New Issue
Block a user