parse

inline fun <N : Node> parse(input: List<Token>): N

Parses the input token sequence into an AST node of type N using this Grammar's default startRule.

The parser attempts to match the entire input token sequence against the grammar's startRule. Parsing succeeds only if the entire input is consumed and produces a node of type N.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The list of tokens to parse

Throws

if the root node is not of type N

if parsing fails


inline fun <N : Node> parse(input: List<Token>, rule: String): N

Parses the input token sequence into an AST node of type N using the specified rule name.

The parser attempts to match the entire input token sequence against the named rule. Parsing succeeds only if the entire input is consumed and produces a node of type N.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The list of tokens to parse

rule

The name of the rule to use as the parse root

Throws

if the named rule is not found in this Grammar

if the root node is not of type N

if parsing fails


inline fun <N : Node> parse(input: List<Token>, rule: Rule<Node>): N

Parses the input token sequence into an AST node of type N using the specified rule.

The parser attempts to match the entire input token sequence against the given rule. Parsing succeeds only if the entire input is consumed and produces a node of type N.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The list of tokens to parse

rule

The rule to use as the parse root

Throws

if the rule is not part of this Grammar

if the root node is not of type N

if parsing fails or not all input is consumed


inline fun <N : Node> parse(input: CharSequence, lexerDiscardEnabled: Boolean = true): N

Parses the input CharSequence into an AST node of type N using this Grammar's default startRule.

This convenience method combines lexing and parsing in a single call. The input is first tokenized using tokenize, then parsed using the Grammar's startRule. When lexerDiscardEnabled is true, discardable tokens are excluded before parsing.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The character sequence to lex and parse

lexerDiscardEnabled

Whether to exclude discardable tokens during parsing

Throws

if the input cannot be fully tokenized

if the root node is not of type N

if parsing fails


inline fun <N : Node> parse(input: CharSequence, rule: String, lexerDiscardEnabled: Boolean = true): N

Parses the input CharSequence into an AST node of type N using the specified rule name.

This convenience method combines lexing and parsing in a single call. The input is first tokenized using tokenize, then parsed using the named rule. When lexerDiscardEnabled is true, discardable tokens are excluded before parsing.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The character sequence to lex and parse

rule

The name of the rule to use as the parse root

lexerDiscardEnabled

Whether to exclude discardable tokens during lexing

Throws

if the input cannot be fully tokenized

if the named rule is not found in this Grammar

if the root node is not of type N

if parsing fails


inline fun <N : Node> parse(input: CharSequence, rule: Rule<Node>, lexerDiscardEnabled: Boolean = true): N

Parses character input into an AST node of type N using the specified rule.

This convenience method combines lexing and parsing in a single call. The input is first tokenized using tokenize, then parsed using the given rule. When lexerDiscardEnabled is true, discardable tokens are excluded before parsing.

Return

The root AST node of type N

Parameters

N

The expected root node type

input

The character sequence to lex and parse

rule

The rule to use as the parse root

lexerDiscardEnabled

Whether to exclude discardable tokens during lexing

Throws

if the input cannot be fully tokenized

if the rule is not part of this Grammar

if the root node is not of type N

if parsing fails