summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbringert <bringert@cs.chalmers.se>2006-12-20 21:50:16 +0000
committerbringert <bringert@cs.chalmers.se>2006-12-20 21:50:16 +0000
commit514a8d6afa9bd587ff7a52c894e263b165fcec2b (patch)
tree43d92dc825dab4579b8af6a14c921a142c7149cd /src
parent642809fd3b193c6e51c42914543a4381902a2d0f (diff)
More JSGF pretty-printing.
Diffstat (limited to 'src')
-rw-r--r--src/GF/Speech/PrJSGF.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/GF/Speech/PrJSGF.hs b/src/GF/Speech/PrJSGF.hs
index ffb5d6630..f284f941d 100644
--- a/src/GF/Speech/PrJSGF.hs
+++ b/src/GF/Speech/PrJSGF.hs
@@ -47,18 +47,18 @@ jsgfPrinter name start opts sisr probs cfg = show (prJSGF srg sisr)
prJSGF :: SRG -> Maybe SISRFormat -> Doc
prJSGF srg@(SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs}) sisr
- = header $$ mainCat $$ vcat topCatRules $$ vcat (map prRule rs)
+ = header $++$ mainCat $++$ vcat topCatRules $++$ foldr ($++$) empty (map prRule rs)
where
header = text "#JSGF V1.0 UTF-8;" $$
comment ("JSGF speech recognition grammar for " ++ name) $$
comment "Generated by GF" $$
- text ("grammar " ++ name ++ ";") $$ emptyLine
+ text ("grammar " ++ name ++ ";")
mainCat = comment ("Start category: " ++ origStart) $$
- rule True "MAIN" [prCat start] $$ emptyLine
+ rule True "MAIN" [prCat start]
prRule (SRGRule cat origCat rhs) =
comment origCat $$
-- rule False cat (map prAlt (ebnfSRGAlts rhs))
- rule False cat (map prAlt rhs) $$ emptyLine
+ rule False cat (map prAlt rhs)
-- FIXME: use the probability
-- prAlt (EBnfSRGAlt mp n rhs) = tag sisr (profileInitSISR n) . showChar ' '. prItem sisr rhs
prAlt (SRGAlt mp n rhs) = initTag <+> prItem sisr n rhs <+> finalTag
@@ -120,6 +120,15 @@ isPunct c = c `elem` "-_.;.,?!"
comment :: String -> Doc
comment s = text "//" <+> text s
+
+
+rule :: Bool -> SRGCat -> [Doc] -> Doc
+rule pub c xs = p <+> prCat c <+> char '='
+ $$ nest 2 (sep (prepunctuate (text "| ") xs) <+> char ';')
+ where p = if pub then text "public" else empty
+
+-- Pretty-printing utilities
+
emptyLine :: Doc
emptyLine = text ""
@@ -127,7 +136,5 @@ prepunctuate :: Doc -> [Doc] -> [Doc]
prepunctuate _ [] = []
prepunctuate p (x:xs) = x : map (p <>) xs
-rule :: Bool -> SRGCat -> [Doc] -> Doc
-rule pub c xs = p <+> prCat c <+> char '='
- $$ nest 2 (sep (prepunctuate (text "| ") xs) <+> char ';')
- where p = if pub then text "public" else empty \ No newline at end of file
+($++$) :: Doc -> Doc -> Doc
+x $++$ y = x $$ emptyLine $$ y