Production

data class Production<out N : Node>(val leftRecursion: Boolean, val pattern: SequenceElement, val producer: Node.ParserCapture.() -> N)

Represents one alternative pattern that a Rule is allowed to match against input.

A Production defines a sequence of PatternElements to match, and a factory function/lambda (producer) to construct the resulting Node from captured tokens and child nodes.

The leftRecursion flag indicates whether this production begins with a reference to its own rule, enabling special handling for left-recursive grammars. (Note: do not include an explicit reference to this Rule as first element in the production pattern; left-recursion is handled in a mechanism separate to the primary pattern logic within parse and extendLeftRecursion.)

The produced Node's children is automatically populated with the captured tokens and child nodes; custom producers should only be used to populate additional computed data relevant to the production/node. If you have no additional data to compute, you can produce a Generic Node with the no-argument produces function instead.

Parameters

N

The type of Node produced by this production

Constructors

Link copied to clipboard
constructor(leftRecursion: Boolean, pattern: SequenceElement, producer: Node.ParserCapture.() -> N)

Properties

Link copied to clipboard

Whether this production is left-recursive (i.e. starts with a reference to itself)

Link copied to clipboard

The sequence of PatternElements to match

Link copied to clipboard

A factory lambda that constructs an instance of N from the captured elements