HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

ModuleBNFC-2.9.6.3Haskell2010

BNFC.CF

Contents
  1. abstract syntax trees: data type definitions
Synopsis
  • PackageBNFC-2.9.6.3
  • Exports123
  • 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.6.3 · BNFC.CF
  • Eq function => Eq (Rul function)Defined in BNFC-2.9.6.3 · BNFC.CF
  • Pretty function => Pretty (Rul function)Defined in BNFC-2.9.6.3 · BNFC.CF
  • IsFun a => IsFun (Rul a)Defined in BNFC-2.9.6.3 · BNFC.CF
  • FixTokenCats (Rul f)Defined in BNFC-2.9.6.3 · BNFC.GetCF
datadata CFG function

Type of context-free grammars (GFG).

Constructors

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

Type of a rule label.

Constructors

Instances3Eq, Ord, Show
  • Eq TypeDefined in BNFC-2.9.6.3 · BNFC.CF
  • Ord TypeDefined in BNFC-2.9.6.3 · BNFC.CF
  • Show TypeDefined in BNFC-2.9.6.3 · 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.6.3 · BNFC.CF
  • Ord CatDefined in BNFC-2.9.6.3 · BNFC.CF
  • Show CatDefined in BNFC-2.9.6.3 · BNFC.CF

    This instance is for the Hspec test suite.

  • Pretty CatDefined in BNFC-2.9.6.3 · BNFC.CF
  • FixTokenCats CatDefined in BNFC-2.9.6.3 · 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.6.3 · 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
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.

valuefirstEntry :: CF -> Cat

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

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

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

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

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.)

abstract syntax trees: data type definitions

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

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).