1
0
forked from GitHub/gf-core

Fewer redundant parantheses in JSGF and SRGS ABNF.

This commit is contained in:
bringert
2007-06-26 16:51:09 +00:00
parent ee39e2c742
commit 9cf1ae6112
2 changed files with 6 additions and 4 deletions

View File

@@ -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 "<NULL>" <+> 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 "<VOID>"
f p (REUnion xs)

View File

@@ -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)