Node

abstract class Node

Represents a node in an Abstract Syntax Tree (AST) produced by parsing.

A Node encapsulates the hierarchical structure of parsed input, containing references to child nodes and tokens captured during parsing. Nodes provide methods to access their children, extract tokens, and navigate the parse tree structure.

Custom node types should extend this class to represent specific syntactic constructs in your Grammar.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard

A ParserCapture subclass produced by AlternationElement.

Link copied to clipboard
open class Generic : Node

A generic Node implementation that can hold arbitrary children.

Link copied to clipboard
open class ParserCapture : Node

A mutable container for capturing tokens and nodes during production matching.

Link copied to clipboard

A ParserCapture subclass produced by RepeatableElement.

Link copied to clipboard
class TokenNode<out T : Token> : Node

A Node implementation that wraps a single Token.

Properties

Link copied to clipboard
open lateinit var children: List<Node>

The child nodes and tokens captured by this node's production.

Link copied to clipboard

Returns true if this node is an AlternationCapture.

Link copied to clipboard

Returns true if this node is a RepeatableCapture.

Link copied to clipboard
open val nodes: <Error class: unknown class>

Returns only the child subnodes, excluding tokens.

Link copied to clipboard
open lateinit var stack: List<ParserContext.Frame>

The parser stack frames active when this Node was created.

Link copied to clipboard
open val tokens: <Error class: unknown class>

Returns only the tokens directly captured by this node, excluding tokens captured by subnodes.

Functions

Link copied to clipboard
fun <R> asAlternation(block: Node.AlternationCapture.() -> R): R?

Executes the block with this node as an AlternationCapture receiver if it is one.

Link copied to clipboard
fun <R> asRepeatable(block: Node.RepeatableCapture.() -> R): R?

Executes the block with this node as a RepeatableCapture receiver if it is one.

Link copied to clipboard
fun isNodeAt(index: Int): Boolean

Returns true if the child at index is a node (excluding TokenNode).

fun isNodeAt(index: Int, predicate: (node: Node) -> Boolean): Boolean

Returns true if the child at index is a node that satisfies the predicate.

Link copied to clipboard
inline fun <N : Node> isNodeAtAs(index: Int): Boolean

Returns true if the child at index is a node of type N.

inline fun <N : Node> isNodeAtAs(index: Int, noinline predicate: (node: N) -> Boolean): Boolean

Returns true if the child at index is a node of type N that satisfies the predicate.

Link copied to clipboard
fun isTokenAt(index: Int): Boolean

Returns true if the child at index is a token (i.e. a TokenNode).

fun isTokenAt(index: Int, predicate: (token: Token) -> Boolean): Boolean

Returns true if the child at index is a token that satisfies the predicate.

Link copied to clipboard
inline fun <T : Token> isTokenAtAs(index: Int): Boolean

Returns true if the child at index is a token of type T.

inline fun <T : Token> isTokenAtAs(index: Int, noinline predicate: (token: T) -> Boolean): Boolean

Returns true if the child at index is a token of type T that satisfies the predicate.

Link copied to clipboard
fun nodeAt(index: Int): Node

Returns the child node at the specified index in this node's children.

Link copied to clipboard
inline fun <N : Node> nodeAtAs(index: Int): N

Returns the child node at the specified index, cast to type N.

Link copied to clipboard
open fun tokenAt(index: Int): Token

Returns the Token at the specified index in this node's children.

Link copied to clipboard
inline fun <T : Token> tokenAtAs(index: Int): T

Returns the Token at the specified index, cast to type T.

Link copied to clipboard
open fun tokensRecursively(): <Error class: unknown class>

Returns all tokens captured by this Node, and its descendant subnodes, recursively.