interp

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2018 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package interp contains functions to interpret the grammar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasRecursion

func HasRecursion(g *ast.Grammar) bool

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

func Interpret(g *ast.Grammar, parser parser.Interface) (bool, error)

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.

func Nullable

func Nullable(refs ast.RefLookup, p *ast.Pattern) bool

Nullable returns whether the input Pattern p also matches the empty string. This is a naive implementation and it does not handle left recursion.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL