From 2fcafc2022df61aab3b80010b9c7925ac827e9ae Mon Sep 17 00:00:00 2001 From: bringert Date: Sun, 21 Jan 2007 16:01:36 +0000 Subject: [PATCH] SRGS ABNF generation: semicolon after meta decls, no $NULL before initTag since the standard doesn't require it, and it crashes Opera, include tag-format declaration. --- src/GF/Speech/PrSRGS_ABNF.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/GF/Speech/PrSRGS_ABNF.hs b/src/GF/Speech/PrSRGS_ABNF.hs index 5549fb068..2b965e9cb 100644 --- a/src/GF/Speech/PrSRGS_ABNF.hs +++ b/src/GF/Speech/PrSRGS_ABNF.hs @@ -35,6 +35,7 @@ import GF.Today import Data.Char import Data.List +import Data.Maybe import Text.PrettyPrint.HughesPJ import Debug.Trace @@ -48,23 +49,24 @@ srgsAbnfPrinter sisr probs opts s = show $ prABNF sisr probs $ makeSimpleSRG opt prABNF :: Maybe SISRFormat -> Bool -> SRG -> Doc prABNF sisr probs srg@(SRG{grammarName=name,grammarLanguage = l, startCat=start,origStartCat=origStart,rules=rs}) - = header $++$ mainCat $++$ vcat topCatRules $++$ foldr ($++$) empty (map prRule rs) + = header $++$ vcat topCatRules $++$ foldr ($++$) empty (map prRule rs) where header = text "#ABNF 1.0 UTF-8;" $$ meta "description" ("Speech recognition grammar for " ++ name ++ ". " ++ "Original start category: " ++ origStart) $$ meta "generator" ("Grammatical Framework " ++ version) $$ - text "language" <+> text l <> char ';' + language $$ tagFormat $$ mainCat + language = text "language" <+> text l <> char ';' + tagFormat | isJust sisr = text "tag-format" <+> text "" <> char ';' + | otherwise = empty mainCat = text "root" <+> prCat start <> char ';' prRule (SRGRule cat origCat rhs) = comment origCat $$ rule False cat (map prAlt (ebnfSRGAlts rhs)) -- FIXME: use the probability prAlt (EBnfSRGAlt mp n rhs) = sep [initTag, parens (prItem sisr n rhs), finalTag] - where initTag | isEmpty t = empty - | otherwise = text "$NULL" <+> t - where t = tag sisr (profileInitSISR n) + where initTag = tag sisr (profileInitSISR n) finalTag = tag sisr (profileFinalSISR n) topCatRules = [rule True (catFormId tc) (map (it tc) cs) | (tc,cs) <- srgTopCats srg] @@ -119,7 +121,7 @@ rule pub c xs = sep [p <+> prCat c <+> char '=', nest 2 (alts xs) <+> char ';'] where p = if pub then text "public" else empty meta :: String -> String -> Doc -meta n v = text "meta" <+> text (show n) <+> text "is" <+> text (show v) +meta n v = text "meta" <+> text (show n) <+> text "is" <+> text (show v) <> char ';' -- Pretty-printing utilities