par package:BNFC

Create a valid parser function name for a given category.
>>> parserName (Cat "Abcd")
pAbcd
>>> parserName (ListCat (Cat "Xyz"))
pListXyz
Entrypoint.
Main parsing function
Put parens around document if given condition is true.
>>> parensIf True "foo"
(foo)
>>> parensIf False "bar"
bar
Wrap in parentheses if condition holds.
ordinary rule (also for parser)
C (False) or C++ no STL (True) mode, with name to use as prefix.
C++ mode, with optional package name
Define an ordering on lists' rules with the following properties:
  • rules with a higher coercion level should come first, i.e. the rules for [Foo3] are before rules for [Foo1] and they are both lower than rules for [Foo].
  • [] < [_] < _:_
This is desiged to correctly order the rules in the prt function for lists so that the pattern matching works as expectd.
>>> compareRules (npRule "[]" (ListCat (CoercCat "Foo" 3)) [] Parsable) (npRule "[]" (ListCat (CoercCat "Foo" 1)) [] Parsable)
LT
>>> compareRules (npRule "[]" (ListCat (CoercCat "Foo" 3)) [] Parsable) (npRule "[]" (ListCat (Cat "Foo")) [] Parsable)
LT
>>> compareRules (npRule "[]" (ListCat (Cat "Foo")) [] Parsable) (npRule "(:[])" (ListCat (Cat "Foo")) [] Parsable)
LT
>>> compareRules (npRule "(:[])" (ListCat (Cat "Foo")) [] Parsable) (npRule "(:)" (ListCat (Cat "Foo")) [] Parsable)
LT