HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleBNFC-2.9.5Haskell2010

BNFC.Backend.Haskell.Utils

  • 22 values
  • PackageBNFC-2.9.5
  • Exports22
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceUtils.hs
valueparserName :: Cat -> Doc
#

Create a valid parser function name for a given category.

Example1 expression
parserName (Cat "Abcd")pAbcd
Example1 expression
parserName (ListCat (Cat "Xyz"))pListXyz
valuecatToType :: (Doc -> Doc) -> Doc -> Cat -> Doc
#

Render a category from the grammar to a Haskell type.

Example3 expressions
catToType id empty (Cat "A")AcatToType id empty (ListCat (Cat "A"))[A]catToType ("Foo." P.<>) empty (TokenCat "Ident")Foo.Ident

Note that there is no haskell type for coerced categories: they should be normalized: >>> catToType id empty (CoercCat Expr 2) Expr

If a type parameter is given it is added to the type name: >>> catToType id (text "a") (Cat A) (A a)

Example1 expression
catToType id (text "a") (ListCat (Cat "A"))[A a]

but not added to Token categories: >>> catToType ("Foo." P.<>) (text "a") (TokenCat Integer) Integer

Example1 expression
catToType id (text "a") (ListCat (TokenCat "Integer"))[Integer]
Example1 expression
catToType id empty (ListCat (CoercCat "Exp" 2))[Exp]
Example1 expression
catToType ("Foo." P.<>) (text "()") (ListCat (CoercCat "Exp" 2))[Foo.Exp ()]
valuecatvars :: [String] -> [Cat] -> [Doc]
#

Gives a list of variables usable for pattern matching.

Example: Given the rule Aba. S ::= A B A ; with the generated data type data S = Aba A B A from the list of categories on the RHS of the rule [A,B,A], we generate the list [a1,b,a2] to be used in a pattern matching like case s of Aba a1 b a2 -> ... ...

Example1 expression
catvars [] [Cat "A", Cat "B", Cat "A"][a1,b,a2]

It should avoid reserved words: >>> catvars ["foo"] [Cat Foo, Cat IF, Cat Case, Cat Type, Cat If] [foo_,if_1,case_,type_,if_2]

It uses a suffix -s to mark lists: >>> catvars [] [Cat A, ListCat (Cat A), ListCat (ListCat (Cat A))] [a,as_,ass]