reference

fun reference(rule: () -> Rule<*>): RuleBuilder<N>

Adds a nonterminal ReferenceElement that matches the given rule.

The rule parameter is a lazily-evaluated lambda to support forward/lateinit references to rules that haven't been defined yet. The lambda is evaluated during parsing, not during Grammar construction.

Note: Left-recursive patterns are supported only via leftRecursion. The parser will fail if a left-recursive pattern is created by adding a reference to the same Rule currently being built as the first element in any production. (Any other self-referencing recursive patterns (e.g. right-recursion) are supported by this function.)

Return

this RuleBuilder for chaining

Parameters

rule

A lambda that returns the rule to reference