pinchot-0.24.0.0: Write grammars, not parsers

Safe HaskellNone
LanguageHaskell2010

Pinchot.Terminalize

Synopsis

Documentation

terminalizers Source #

Arguments

:: Qualifier

Qualifier for the module containing the data types created from the Rules

-> [Rule t] 
-> Q [Dec] 

For all the given rules and their ancestors, creates declarations that reduce the rule and all its ancestors to terminal symbols. Each rule gets a declaration named t'RULE_NAME where RULE_NAME is the name of the rule. The type of the declaration is either

Production a -> [(t, a)]

or

Production a -> NonEmpty (t, a)

where Production is the production corresponding to the given Rule, t is the terminal token type (often Char), and a is arbitrary metadata about each token (often Loc). NonEmpty is returned for productions that must always contain at least one terminal symbol; for those that can be empty, Seq is returned.

Example: Pinchot.Examples.Terminalize.

terminalizer Source #

Arguments

:: Qualifier

Qualifier for the module containing the data types created from the Rules

-> Rule t 
-> Q [Dec] 

For the given rule, creates declarations that reduce the rule to terminal symbols. No ancestors are handled. Each rule gets a declaration named t'RULE_NAME where RULE_NAME is the name of the rule. The type of the declaration is either

Production a -> [(t, a)]

or

Production a -> NonEmpty (t, a)

where Production is the production corresponding to the given Rule, t is the terminal token type (often Char), and a is arbitrary metadata about each token (often Loc). NonEmpty is returned for productions that must always contain at least one terminal symbol; for those that can be empty, Seq is returned.

terminalizeRuleExp :: Qualifier -> Rule t -> Q Exp Source #

For the given rule, returns an expression that has type of either

Production a -> [(t, a)]

or

Production a -> NonEmpty (t, a)

where Production is the production corresponding to the given Rule, and t is the terminal token type. NonEmpty is returned for productions that must always contain at least one terminal symbol; for those that can be empty, Seq is returned.

Example: terminalizeAddress.

ruleLookupMap :: Foldable c => c (Rule t) -> Q (Map RuleName Name) Source #

Creates a Map where each key is the name of the Rule and each value is a name corresponding to that Rule. No ancestors are used.

terminalizeSingleRule Source #

Arguments

:: Qualifier

Module qualifier for module containing the generated types corresponding to all Rules

-> Map RuleName Name

For a given Rule, looks up the name of the expression that will terminalize that rule.

-> Rule t 
-> Q Exp 

For the given rule, returns an expression that has type of either

Production a -> [(t, a)]

or

Production a -> NonEmpty (t, a)

where Production is the production corresponding to the given Rule, and t is the terminal token type. NonEmpty is returned for productions that must always contain at least one terminal symbol; for those that can be empty, Seq is returned. Gets no ancestors.

terminalizeProductAllowsZero Source #

Arguments

:: Qualifier 
-> Map RuleName Name 
-> String

Rule name or branch name, as applicable

-> [Rule t] 
-> Q (PatQ, ExpQ) 

terminalizeProductAtLeastOne Source #

Arguments

:: Qualifier 
-> Map RuleName Name 
-> String

Rule name or branch name, as applicable

-> [Rule t] 
-> Q (PatQ, ExpQ) 

atLeastOne Source #

Arguments

:: Rule t 
-> Bool

True if the rule will always have at least one terminal symbol.

Examines a rule to determine whether when terminalizing it will always return at least one terminal symbol.