From 0b7fef1a33db15593493b80f8a65aa96c6530f5c Mon Sep 17 00:00:00 2001 From: bringert Date: Tue, 12 Dec 2006 14:01:42 +0000 Subject: Use ebnf srg generation in PrSRGS. --- src/GF/Speech/SRG.hs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/GF/Speech/SRG.hs') diff --git a/src/GF/Speech/SRG.hs b/src/GF/Speech/SRG.hs index b55475f1f..9082fa1f4 100644 --- a/src/GF/Speech/SRG.hs +++ b/src/GF/Speech/SRG.hs @@ -22,7 +22,10 @@ module GF.Speech.SRG (SRG(..), SRGRule(..), SRGAlt(..), SRGCat, SRGNT, makeSimpleSRG, makeSRG , lookupFM_, prtS - , topDownFilter) where + , topDownFilter + , EBnfSRGAlt(..), EBnfSRGItem(..) + , ebnfSRGAlts + ) where import GF.Data.Operations import GF.Data.Utilities @@ -163,6 +166,26 @@ topDownFilter srg@(SRG { startCat = start, rules = rs }) = srg { rules = rs' } allSRGCats :: SRG -> [String] allSRGCats SRG { rules = rs } = [c | SRGRule c _ _ <- rs] +-- +-- * Size-optimized EBNF SRGs +-- + +data EBnfSRGAlt = EBnfSRGAlt (Maybe Double) Name EBnfSRGItem + deriving (Eq,Show) + +data EBnfSRGItem = + EBnfOneOf [EBnfSRGItem] + | EBnfSeq [EBnfSRGItem] + | EBnfSymbol (Symbol SRGNT Token) + deriving (Eq,Show) + +ebnfSRGAlts :: [SRGAlt] -> [EBnfSRGAlt] +ebnfSRGAlts alts = [EBnfSRGAlt p n (ebnfSRGItem sss) + | ((p,n),sss) <- buildMultiMap [((p,n),ss) | SRGAlt p n ss <- alts]] + +ebnfSRGItem :: [[Symbol SRGNT Token]] -> EBnfSRGItem +ebnfSRGItem sss = EBnfOneOf (map (EBnfSeq . map EBnfSymbol) sss) + -- -- * Utilities for building and printing SRGs -- -- cgit v1.2.3