mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 08:32:50 -06:00
Use [] in JSGF printing.
This commit is contained in:
@@ -31,14 +31,16 @@ import GF.Speech.SISR
|
|||||||
import GF.Speech.SRG
|
import GF.Speech.SRG
|
||||||
import GF.Speech.RegExp
|
import GF.Speech.RegExp
|
||||||
|
|
||||||
|
import Data.List
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
|
|
||||||
jsgfPrinter :: Ident -- ^ Grammar name
|
jsgfPrinter :: Ident -- ^ Grammar name
|
||||||
-> String -- ^ Start category
|
-> String -- ^ Start category
|
||||||
-> Options
|
-> Options
|
||||||
-> Maybe SISRFormat
|
-> Maybe SISRFormat
|
||||||
-> Maybe Probs -> CGrammar -> String
|
-> 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
|
where srg = makeSimpleSRG name start opts probs cfg
|
||||||
|
|
||||||
prJSGF :: SRG -> Maybe SISRFormat -> ShowS
|
prJSGF :: SRG -> Maybe SISRFormat -> ShowS
|
||||||
@@ -77,7 +79,10 @@ prItem :: Maybe SISRFormat -> EBnfSRGItem -> ShowS
|
|||||||
prItem sisr = f 1
|
prItem sisr = f 1
|
||||||
where
|
where
|
||||||
f _ (REUnion []) = showString "<VOID>"
|
f _ (REUnion []) = showString "<VOID>"
|
||||||
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 "<NULL>"
|
f _ (REConcat []) = showString "<NULL>"
|
||||||
f p (REConcat xs) = (if p >= 3 then paren else id) (unwordsS (map (f 2) xs))
|
f p (REConcat xs) = (if p >= 3 then paren else id) (unwordsS (map (f 2) xs))
|
||||||
f p (RERepeat x) = f 3 x . showString "*"
|
f p (RERepeat x) = f 3 x . showString "*"
|
||||||
|
|||||||
Reference in New Issue
Block a user