rule

fun <N : Node> rule(name: String, pattern: RuleBuilder<N>.() -> Unit): Rule<N>

Defines a production rule with the given name using the DSL provided by RuleBuilder.

The pattern lambda receives a RuleBuilder context where productions can be defined using DSL methods like RuleBuilder.token, RuleBuilder.reference, and RuleBuilder.produces. The constructed rule is returned to allow capturing it for later reference.

Return

The constructed Rule

Parameters

N

The Node type produced by this rule

name

The unique name for this rule

pattern

A lambda defining the rule's productions

See also

Throws

if a rule with this name is already defined in this Grammar