From 9cf1ae61128ae8687cf01f0a94df384c4ac6fe87 Mon Sep 17 00:00:00 2001 From: bringert Date: Tue, 26 Jun 2007 16:51:09 +0000 Subject: [PATCH] Fewer redundant parantheses in JSGF and SRGS ABNF. --- src/GF/Speech/PrJSGF.hs | 5 +++-- src/GF/Speech/PrSRGS_ABNF.hs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/GF/Speech/PrJSGF.hs b/src/GF/Speech/PrJSGF.hs index efdce4d75..72910235e 100644 --- a/src/GF/Speech/PrJSGF.hs +++ b/src/GF/Speech/PrJSGF.hs @@ -63,12 +63,13 @@ prJSGF sisr srg@(SRG{grammarName=name,grammarLanguage=ml, rule False cat (map prAlt rhs) -- rule False cat (map prAlt rhs) -- FIXME: use the probability - prAlt (SRGAlt mp n rhs) = sep [initTag, parens (prItem sisr n rhs), finalTag] + prAlt (SRGAlt mp n rhs) = sep [initTag, p (prItem sisr n rhs), finalTag] -- prAlt (SRGAlt mp n rhs) = initTag <+> prItem sisr n rhs <+> finalTag where initTag | isEmpty t = empty | otherwise = text "" <+> t where t = tag sisr (profileInitSISR n) finalTag = tag sisr (profileFinalSISR n) + p = if isEmpty initTag && isEmpty finalTag then id else parens topCatRules = [rule True (catFormId tc) (map (it tc) cs) | (tc,cs) <- srgTopCats srg] where it i c = prCat c <+> tag sisr (topCatSISR c) @@ -80,7 +81,7 @@ prCat :: SRGCat -> Doc prCat c = char '<' <> text c <> char '>' prItem :: Maybe SISRFormat -> CFTerm -> SRGItem -> Doc -prItem sisr t = f 1 +prItem sisr t = f 0 where f _ (REUnion []) = text "" f p (REUnion xs) diff --git a/src/GF/Speech/PrSRGS_ABNF.hs b/src/GF/Speech/PrSRGS_ABNF.hs index 34f5e7731..244a00816 100644 --- a/src/GF/Speech/PrSRGS_ABNF.hs +++ b/src/GF/Speech/PrSRGS_ABNF.hs @@ -70,9 +70,10 @@ prABNF sisr probs srg@(SRG{grammarName=name,grammarLanguage=ml, comment origCat $$ rule False cat (map prAlt rhs) -- FIXME: use the probability - prAlt (SRGAlt mp n rhs) = sep [initTag, parens (prItem sisr n rhs), finalTag] + prAlt (SRGAlt mp n rhs) = sep [initTag, p (prItem sisr n rhs), finalTag] where initTag = tag sisr (profileInitSISR n) finalTag = tag sisr (profileFinalSISR n) + p = if isEmpty initTag && isEmpty finalTag then id else parens topCatRules = [rule True (catFormId tc) (map (it tc) cs) | (tc,cs) <- srgTopCats srg] where it i c = prCat c <+> tag sisr (topCatSISR c) @@ -84,7 +85,7 @@ prCat :: SRGCat -> Doc prCat c = char '$' <> text c prItem :: Maybe SISRFormat -> CFTerm -> SRGItem -> Doc -prItem sisr t = f 1 +prItem sisr t = f 0 where f _ (REUnion []) = text "$VOID" f p (REUnion xs)