From 4e592d495e402bb8e73f860197315654c3958ae4 Mon Sep 17 00:00:00 2001 From: bringert Date: Sun, 17 Dec 2006 18:16:20 +0000 Subject: [PATCH] Use [] in JSGF printing. --- src/GF/Speech/PrJSGF.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GF/Speech/PrJSGF.hs b/src/GF/Speech/PrJSGF.hs index 26421d36c..90e8678f1 100644 --- a/src/GF/Speech/PrJSGF.hs +++ b/src/GF/Speech/PrJSGF.hs @@ -31,14 +31,16 @@ import GF.Speech.SISR import GF.Speech.SRG import GF.Speech.RegExp +import Data.List import Debug.Trace + jsgfPrinter :: Ident -- ^ Grammar name -> String -- ^ Start category -> Options -> Maybe SISRFormat -> Maybe Probs -> CGrammar -> String -jsgfPrinter name start opts sisr probs cfg = trace (show srg) $ prJSGF srg sisr "" +jsgfPrinter name start opts sisr probs cfg = prJSGF srg sisr "" where srg = makeSimpleSRG name start opts probs cfg prJSGF :: SRG -> Maybe SISRFormat -> ShowS @@ -77,7 +79,10 @@ prItem :: Maybe SISRFormat -> EBnfSRGItem -> ShowS prItem sisr = f 1 where f _ (REUnion []) = showString "" - f p (REUnion xs) = (if p >= 1 then paren else id) (joinS " | " (map (f 1) xs)) + f p (REUnion xs) + | not (null es) = wrap "[" (f 0 (REUnion nes)) "]" + | otherwise = (if p >= 1 then paren else id) (joinS " | " (map (f 1) xs)) + where (es,nes) = partition (== REConcat []) xs f _ (REConcat []) = showString "" f p (REConcat xs) = (if p >= 3 then paren else id) (unwordsS (map (f 2) xs)) f p (RERepeat x) = f 3 x . showString "*"