Documentation
¶
Overview ¶
Package interp contains functions to interpret the grammar.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasRecursion ¶
HasRecursion returns whether the grammar contains any references that does not have a TreeNode pattern in between. For example:
#main = @main #main = (A:* | @main)
Recursion can still be used when a TreeNode pattern is placed between references, for example:
#main = (A:@main | <empty>)
func Interpret ¶
Interpret interprets the grammar given the parser and returns whether the parser is valid given the grammar. Interpret uses derivatives and simplification to recusively derive the resulting grammar. This resulting grammar's nullability then represents the result of the function. This implementation does not handle immediate recursion, see the HasRecursion function.
Types ¶
type Simplifier ¶
type Simplifier interface { //Simplify returns a pattern that has been simplified, transformed to an equivalent, but smaller or equal pattern. Simplify(p *ast.Pattern) *ast.Pattern //Grammar returns a grammar that has been simplified, transformed to an equivalent, but smaller or equal grammar. Grammar() *ast.Grammar //OptimizeForRecord optimizes the simplifier to also takes into account the fact the structure being validated is a record. //A record can be json, protobuf, reflected go structures or any structure that have unique field names for each structure. //XML would be an example of a structure for which this simplification is NOT appropriate. OptimizeForRecord() Simplifier }
Simplifier simplifies the patterns of a given grammar.
func NewSimplifier ¶
func NewSimplifier(g *ast.Grammar) Simplifier
NewSimplifier returns a new Simplifier that is used to simplify a grammar and its patterns.