class

Pegmatite::Pattern::Choice

Inherits Pegmatite::Pattern < Pegmatite::DSL::Methods < Reference < Object

Pattern::Choice is used to specify an ordered choice of patterns.

Returns the result of the first child pattern that matched. Returns the longest-length failure of all child patterns fail.

Constructors

new(children : Array(Pegmatite::Pattern) = [] of Pattern)
Source

Instance methods

_match(source, offset, state) : MatchResult
Source
|(other)

Override this DSL operator to accrue into the existing choice.

Source
description
Source
dsl_name
Source
inspect(io)
Source
match(source, offset, state) : MatchResult

Explicitly memoize Choice patterns, which happens to have a significant speedup on otherwise troublesome grammars with a lot of backtracking. We don't do this for other patterns.

Source