Builder

class Builder

A DSL builder for constructing Grammar instances.

Builder provides methods to define lexemes and rules that comprise a Grammar. Use lexeme to register lexeme definitions and rule to define production rules. Once all components are defined, call build to construct the final Grammar instance.

Typically accessed through the Grammar companion object's invoke operators rather than constructed directly.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun build(startRule: String? = null): Grammar

Constructs a Grammar from the registered lexemes and rules.

Link copied to clipboard
fun <T : Token> lexeme(lexeme: Lexeme<T>): Lexeme<T>

Registers a lexeme definition with this Grammar Builder.

fun <T : Token> lexeme(lexeme: Lexeme<T>, factoryOverride: (value: CharSequence) -> T): Lexeme<T>

Registers a lexeme definition with this Grammar Builder and assigns a factoryOverride for it.

Link copied to clipboard
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.