Documentation ¶
Overview ¶
Package builder generates the parser code for a given grammar. It makes no attempt to verify the correctness of the grammar.
Index ¶
- Variables
- func BasicLatinLookup(chars, ranges []rune, unicodeClasses []string, ignoreCase bool) (basicLatinChars [128]bool)
- func BuildParser(w io.Writer, g *ast.Grammar, opts ...Option) error
- func ComputeLeftRecursives(rules map[string]*ast.Rule) (bool, error)
- func ComputeNullables(rules map[string]*ast.Rule)
- func FindCyclesInSCC(graph map[string]map[string]struct{}, scc map[string]struct{}, start string) ([][]string, error)
- func MakeFirstGraph(rules map[string]*ast.Rule) map[string]map[string]struct{}
- func PrepareGrammar(grammar *ast.Grammar) (bool, error)
- func StronglyConnectedComponents(vertices []string, edges map[string]map[string]struct{}) []map[string]struct{}
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoLeader is no leader error. ErrNoLeader = errors.New( "SCC has no leadership candidate (no element is included in all cycles)") // ErrHaveLeftRecursion is recursion error. ErrHaveLeftRecursion = errors.New("grammar contains left recursion") )
var ErrInvalidParameters = errors.New("invalid parameters passed to function")
ErrInvalidParameters is parameters error.
Functions ¶
func BasicLatinLookup ¶ added in v1.1.0
func BasicLatinLookup(chars, ranges []rune, unicodeClasses []string, ignoreCase bool) (basicLatinChars [128]bool)
BasicLatinLookup calculates the decision results for the first 256 characters of the UTF-8 character set for a given set of chars, ranges and unicodeClasses to speedup the CharClassMatcher.
func BuildParser ¶
BuildParser builds the PEG parser using the provider grammar. The code is written to the specified w.
func ComputeLeftRecursives ¶ added in v1.2.0
ComputeLeftRecursives evaluates left recursion.
func ComputeNullables ¶ added in v1.2.0
ComputeNullables evaluates nullable nodes.
func FindCyclesInSCC ¶ added in v1.2.0
func FindCyclesInSCC( graph map[string]map[string]struct{}, scc map[string]struct{}, start string, ) ([][]string, error)
FindCyclesInSCC find cycles in SCC emanating from start. Yields lists of the form ['A', 'B', 'C', 'A'], which means there's a path from A -> B -> C -> A. The first item is always the start argument, but the last item may be another element, e.g. ['A', 'B', 'C', 'B'] means there's a path from A to B and there's a cycle from B to C and back.
func MakeFirstGraph ¶ added in v1.2.0
MakeFirstGraph compute the graph of left-invocations. There's an edge from A to B if A may invoke B at its initial position. Note that this requires the nullable flags to have been computed.
func PrepareGrammar ¶ added in v1.2.0
PrepareGrammar evaluates parameters associated with left recursion.
Types ¶
type Option ¶
type Option func(*builder) Option
Option is a function that can set an option on the builder. It returns the previous setting as an Option.
func BasicLatinLookupTable ¶ added in v1.1.0
BasicLatinLookupTable returns an option that specifies the basicLatinLookup option If basicLatinLookup is true, a lookup slice for the first 128 chars of the Unicode table (Basic Latin) is generated for each CharClassMatcher to increase the character matching.
func Nolint ¶ added in v1.1.0
Nolint returns an option that specifies the nolint option If nolint is true, special '// nolint: ...' comments are added to the generated parser to suppress warnings by gometalinter or golangci-lint.
func Optimize ¶ added in v1.1.0
Optimize returns an option that specifies the optimize option If optimize is true, the Debug and Memoize code is completely removed from the resulting parser
func ReceiverName ¶
ReceiverName returns an option that specifies the receiver name to use for the current struct (which is the struct on which all code blocks except the initializer are generated).
func SupportLeftRecursion ¶ added in v1.2.0
SupportLeftRecursion returns an option that specifies the supportLeftRecursion option. If supportLeftRecursion is true, LeftRecursion code is added to the resulting parser.