mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 16:42:51 -06:00
bnf and ebnf printer: align ::= symbols.
This commit is contained in:
@@ -273,11 +273,18 @@ countRules :: CFG -> Int
|
|||||||
countRules = length . allRules
|
countRules = length . allRules
|
||||||
|
|
||||||
prCFG :: CFG -> String
|
prCFG :: CFG -> String
|
||||||
prCFG = unlines . map prRule . allRules
|
prCFG = prProductions . map prRule . allRules
|
||||||
where
|
where
|
||||||
prRule r = lhsCat r ++ " ::= " ++ unwords (map prSym (ruleRhs r))
|
prRule r = (lhsCat r, unwords (map prSym (ruleRhs r)))
|
||||||
prSym = symbol id (\t -> "\""++ t ++"\"")
|
prSym = symbol id (\t -> "\""++ t ++"\"")
|
||||||
|
|
||||||
|
prProductions :: [(Cat,String)] -> String
|
||||||
|
prProductions prods =
|
||||||
|
unlines [rpad maxLHSWidth lhs ++ " ::= " ++ rhs | (lhs,rhs) <- prods]
|
||||||
|
where
|
||||||
|
maxLHSWidth = maximum $ 0:(map (length . fst) prods)
|
||||||
|
rpad n s = s ++ replicate (n - length s) ' '
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * CFRule Utilities
|
-- * CFRule Utilities
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -175,9 +175,9 @@ ungroupTokens = joinRE . mapRE (symbol (RESymbol . NonTerminal) (REConcat . map
|
|||||||
--
|
--
|
||||||
|
|
||||||
prSRG :: SRG -> String
|
prSRG :: SRG -> String
|
||||||
prSRG = unlines . map prRule . srgRules
|
prSRG = prProductions . map prRule . srgRules
|
||||||
where
|
where
|
||||||
prRule (SRGRule c alts) = c ++ " ::= " ++ unwords (intersperse "|" (map prAlt alts))
|
prRule (SRGRule c alts) = (c,unwords (intersperse "|" (map prAlt alts)))
|
||||||
prAlt (SRGAlt _ _ rhs) = prRE prSym rhs
|
prAlt (SRGAlt _ _ rhs) = prRE prSym rhs
|
||||||
prSym = symbol fst (\t -> "\""++ t ++"\"")
|
prSym = symbol fst (\t -> "\""++ t ++"\"")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user