HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleBNFC-2.9.5Haskell2010

BNFC.CF

  • 32 types
  • 1 class
  • 89 values
  • PackageBNFC-2.9.5
  • Exports122
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceCF.hs
typetype CF = CFG RFun
#

A context free grammar consists of a set of rules and some extended information (e.g. pragmas, literals, symbols, keywords).

typetype Rule = Rul RFun
#

A rule consists of a function name, a main category and a sequence of terminals and non-terminals.

  function_name . Main_Cat ::= sequence
datadata Rul function
#

Polymorphic rule type.

Constructors

  • Rule
    • funRule :: function

      The function (semantic action) of a rule. In order to be able to generate data types this must be a constructor (or an identity function).

    • valRCat :: RCat

      The value category, i.e., the defined non-terminal.

    • rhsRule :: SentForm

      The sentential form, i.e., the list of (non)terminals in the right-hand-side of a rule.

    • internal :: InternalRule

      Is this an "internal" rule only for the AST and printing, not for parsing?

Instances5Functor, Eq, Pretty, IsFun, FixTokenCats
  • Functor RulDefined in BNFC-2.9.5 · BNFC.CF
  • Eq function => Eq (Rul function)Defined in BNFC-2.9.5 · BNFC.CF
  • Pretty function => Pretty (Rul function)Defined in BNFC-2.9.5 · BNFC.CF
  • IsFun a => IsFun (Rul a)Defined in BNFC-2.9.5 · BNFC.CF
  • FixTokenCats (Rul f)Defined in BNFC-2.9.5 · BNFC.GetCF
datadata CFG function
#

Type of context-free grammars (GFG).

Constructors

Instances2Functor, FixTokenCats
  • Functor CFGDefined in BNFC-2.9.5 · BNFC.CF
  • FixTokenCats (CFG f)Defined in BNFC-2.9.5 · BNFC.GetCF
datadata Type
#

Type of a rule label.

Constructors

Instances3Eq, Ord, Show
  • Eq TypeDefined in BNFC-2.9.5 · BNFC.CF
  • Ord TypeDefined in BNFC-2.9.5 · BNFC.CF
  • Show TypeDefined in BNFC-2.9.5 · BNFC.CF
typetype Literal = String
#

Literal: builtin-token types Char, String, Ident, Integer, Double.

datadata WithPosition a
#
Instances10Functor, IsString, Foldable, Traversable, Eq, Ord, …
datadata Cat
#

Categories are the non-terminals of the grammar.

Constructors

Instances6Eq, Ord, Show, Pretty, FixTokenCats
  • Eq CatDefined in BNFC-2.9.5 · BNFC.CF
  • Ord CatDefined in BNFC-2.9.5 · BNFC.CF
  • Show CatDefined in BNFC-2.9.5 · BNFC.CF

    This instance is for the Hspec test suite.

  • Pretty CatDefined in BNFC-2.9.5 · BNFC.CF
  • FixTokenCats CatDefined in BNFC-2.9.5 · BNFC.GetCF

    Change the constructor of categories with the given names from Cat to TokenCat >>> fixTokenCats [A] (Cat A) == TokenCat A True >>> fixTokenCats [A] (ListCat (Cat A)) == ListCat (TokenCat A) True >>> fixTokenCats [A] (Cat B) == Cat B True

  • FixTokenCats (Either Cat String)Defined in BNFC-2.9.5 · BNFC.GetCF
valuestrToCat :: String -> Cat
#

Reads a string into a category. This should only need to handle the case of simple categories (with or without coercion) since list categories are parsed in the grammar already. To be on the safe side here, we still call the parser function that parses categries.

valuesameCat :: Cat -> Cat -> Bool
#

Categories C1, C2,... (one digit at the end) are variants of C. This function returns true if two category are variants of the same abstract category. E.g.

Example1 expression
sameCat (Cat "Abc") (CoercCat "Abc" 44)True
valuenormCat :: Cat -> Cat
#

Removes precedence information. C1 => C, [C2] => [C]

valueidentCat :: Cat -> String
#

When given a list Cat, i.e. '[C]', it removes the square brackets, and adds the prefix List, i.e. ListC. (for Happy and Latex)

valuecatOfType :: [TokenCat] -> Base -> Cat
#

Reconstruct (non-coercion) category from a type, given a list of what should be the token categories.

valuecatOfList :: Cat -> Cat
#

Unwraps the list constructor from the category name. E.g. [C1] => C1.

typetype Fun = String
#

Fun is the function name of a rule.

valuefirstEntry :: CF -> Cat
#

firstEntry returns the first of the entrypoints, or (if none), the first parsable Category appearing in the grammar.

valuefilterNonUnique :: Ord a => [a] -> [a]
#

Get all elements with more than one occurrence.

valuerulesForCat :: CF -> Cat -> [Rule]
#

Returns all parseable rules that construct the given Cat. Whitespace separators have been removed.

valuerulesForNormalizedCat :: CF -> Cat -> [Rule]
#

Like rulesForCat but for normalized value categories. I.e., `rulesForCat (Cat Exp)` will return rules for category Exp but also Exp1, Exp2... in case of coercion

valuerulesForCat' :: CF -> Cat -> [Rule]
#

As rulesForCat, but this version doesn't exclude internal rules.

valueallCats :: (InternalRule -> Bool) -> CFG f -> [Cat]
#

Get all categories of a grammar matching the filter. (No Cat w/o production returned; no duplicates.)

valuereallyAllCats :: CFG f -> [Cat]
#

Get all categories of a grammar. (No Cat w/o production returned; no duplicates.)

valueisUsedCat :: CFG f -> Cat -> Bool
#

Is the category is used on an rhs? Includes internal rules.

valueruleGroups :: CF -> [(Cat, [Rule])]
#

Group all parsable categories with their rules. Deletes whitespace separators, as they will not become part of the parsing rules.

valuecfTokens :: CFG f -> [(String, Int)]
#

Canonical, numbered list of symbols and reserved words. (These do not end up in the AST.)

valuehasIdent :: CFG f -> Bool
#

Whether the grammar uses the predefined Ident type.

abstract syntax trees: data type definitions

22 declarations
valuegetAbstractSyntax :: CF -> [Data]
#

Return the abstract syntax of the grammar. All categories are normalized, so a rule like: EAdd . Exp2 ::= Exp2 "+" Exp3 ; Will give the following signature: EAdd : Exp -> Exp -> Exp

valuecf2data' :: (Cat -> Bool) -> CF -> [Data]
#

All the functions below implement the idea of getting the abstract syntax of the grammar with some variation but they seem to do a poor job at handling corner cases involving coercions. Use getAbstractSyntax instead if possible.

valueprecCat :: Cat -> Integer
#

Returns the precedence of a category symbol. E.g. >>> precCat (CoercCat Abc 4) 4

valueallEntryPoints :: CFG f -> List1 Cat
#

Categories that are entry points to the parser.

These are either the declared entrypoints (in the original order), or, if no entrypoints were declared explicitly, all parsable categories (in the order of declaration in the grammar file).