ModuleBNFC-2.9.5Haskell2010
BNFC.CF
- 32 types
- 1 class
- 89 values
- PackageBNFC-2.9.5
- Exports122
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceCF.hs
A context free grammar consists of a set of rules and some extended information (e.g. pragmas, literals, symbols, keywords).
A rule consists of a function name, a main category and a sequence of terminals and non-terminals.
function_name . Main_Cat ::= sequence
Polymorphic rule type.
Constructors
RulefunRule :: functionThe 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 :: RCatThe value category, i.e., the defined non-terminal.
rhsRule :: SentFormThe sentential form, i.e., the list of (non)terminals in the right-hand-side of a rule.
internal :: InternalRuleIs this an "internal" rule only for the AST and printing, not for parsing?
Instances5Functor, Eq, Pretty, IsFun, FixTokenCats
Instances1Eq
Eq InternalRuleDefined in BNFC-2.9.5 · BNFC.CF
A sentential form is a sequence of non-terminals or terminals.
Type of context-free grammars (GFG).
Constructors
CFGcfgPragmas :: [Pragma]cfgUsedCats :: Set CatCategories used by the parser.
cfgLiterals :: [Literal]Char, String, Ident, Integer, Double.Strings are quoted strings, andIdents are unquoted.cfgSymbols :: [Symbol]Symbols in the grammar, e.g. “*”, “->”.
cfgKeywords :: [KeyWord]Reserved words, e.g.
if,while.cfgReversibleCats :: [Cat]Categories that can be made left-recursive.
cfgRules :: [Rul function]cfgSignature :: SignatureTypes of rule labels, computed from cfgRules.
Types of the rule labels, together with the position of the rule label.
Type of a non-terminal.
Placeholder for a type.
Placeholder for a function type.
Expressions for function definitions.
Pragmas.
Instances1FixTokenCats
FixTokenCats PragmaDefined in BNFC-2.9.5 · BNFC.GetCF
Function arguments with type.
For use with partitionEithers.
All define pragmas of the grammar.
List delimiters.
Instances1Show
Show DelimitersDefined in BNFC-2.9.5 · BNFC.CF
User-defined regular expression tokens
The names of all user-defined tokens.
Literal: builtin-token types Char, String, Ident, Integer, Double.
Source positions.
Constructors
Instances10Functor, IsString, Foldable, Traversable, Eq, Ord, …
Functor WithPositionDefined in BNFC-2.9.5 · BNFC.CFIsString RFunDefined in BNFC-2.9.5 · BNFC.CFFoldable WithPositionDefined in BNFC-2.9.5 · BNFC.CFTraversable WithPositionDefined in BNFC-2.9.5 · BNFC.CFEq a => Eq (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFIgnore position in equality and ordering.
Ord a => Ord (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFShow a => Show (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFPretty a => Pretty (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFIsFun a => IsFun (WithPosition a)Defined in BNFC-2.9.5 · BNFC.CFFixTokenCats a => FixTokenCats (WithPosition a)Defined in BNFC-2.9.5 · BNFC.GetCF
A "ranged string" (terminology from Agda code base).
Prefix string with pretty-printed position information.
Categories are the non-terminals of the grammar.
Instances6Eq, Ord, Show, Pretty, FixTokenCats
Eq CatDefined in BNFC-2.9.5 · BNFC.CFOrd CatDefined in BNFC-2.9.5 · BNFC.CFShow CatDefined in BNFC-2.9.5 · BNFC.CFThis instance is for the Hspec test suite.
Pretty CatDefined in BNFC-2.9.5 · BNFC.CFFixTokenCats CatDefined in BNFC-2.9.5 · BNFC.GetCFChange the constructor of categories with the given names from Cat to TokenCat >>> fixTokenCats [
A] (CatA) == TokenCatATrue >>> fixTokenCats [A] (ListCat (CatA)) == ListCat (TokenCatA) True >>> fixTokenCats [A] (CatB) == CatBTrueFixTokenCats (Either Cat String)Defined in BNFC-2.9.5 · BNFC.GetCF
Render category symbols as strings
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.
Token categories corresponding to base types.
Does the category correspond to a data type?
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.
sameCat (Cat "Abc") (CoercCat "Abc" 44)True
Removes precedence information. C1 => C, [C2] => [C]
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)
Reconstruct (non-coercion) category from a type, given a list of what should be the token categories.
Get the underlying category identifier.
Unwraps the list constructor from the category name.
E.g. [C1] => C1.
Fun is the function name of a rule.
The abstract syntax of a grammar.
firstEntry returns the first of the entrypoints,
or (if none), the first parsable Category appearing in the grammar.
Constructors and categories.
Get all elements with more than one occurrence.
Extract the comment pragmas.
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
As rulesForCat, but this version doesn't exclude internal rules.
Get all categories of a grammar matching the filter. (No Cat w/o production returned; no duplicates.)
Get all categories of a grammar. (No Cat w/o production returned; no duplicates.)
Gets all normalized identified Categories
Get all normalized Cat
Get all normalized Cat
Is the category is used on an rhs? Includes internal rules.
Group all parsable categories with their rules. Deletes whitespace separators, as they will not become part of the parsing rules.
Group all categories with their rules including internal rules.
Get all literals of a grammar. (e.g. String, Double)
Get the keywords of a grammar.
Canonical, numbered list of symbols and reserved words. (These do not end up in the AST.)
Comments can be defined by the comment pragma
Number of block comment forms defined in the grammar file.
Whether the grammar uses the predefined Ident type.
Categories corresponding to tokens. These end up in the AST. (unlike tokens returned by cfTokens)
abstract syntax trees: data type definitions
22 declarationsReturn 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
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.
Get the type of a rule label.
Checks if the rule is parsable.
Gets the singleton rule out of the rules for a list.
Sort rules by descending precedence.
Is the given category a list category parsing also empty lists?
Returns the precedence of a category symbol.
E.g.
>>> precCat (CoercCat Abc 4)
4
Defines or uses the grammar token types like Ident?
Excludes position tokens.
Defines or uses the grammar token types or Ident?
Is there a position token declaration in the grammar?
Does the category have a position stored in AST?
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).