BNFC-2.9.4.1: A compiler front-end generator.
Safe HaskellNone
LanguageHaskell2010

BNFC.Backend.Haskell.CFtoPrinter

Synopsis

Documentation

cf2Printer Source #

Arguments

:: TokenText

Are identifiers ByteStrings or Text rather than Strings? (Option --bytestrings and --text)

-> Bool

Option --functor?

-> Bool

--haskell-gadt?

-> String

Name of created Haskell module.

-> AbsMod

Name of Haskell module for abstract syntax.

-> CF

Grammar.

-> Doc 

Derive pretty-printer from a BNF grammar.

compareRules :: IsFun f => Rul f -> Rul f -> Ordering Source #

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