TokenNode

class TokenNode<out T : Token> : Node

A Node implementation that wraps a single Token.

This class is used internally by PatternElements when they successfully match a token. Use tokenAt to retrieve the wrapped token.

TokenNodes do not count as Node instances for the purposes of the nodes property. You may retrieve children directly on a parent Node to include both non-TokenNodes and TokenNodes in a well-defined order.

Properties

Link copied to clipboard
open override 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 override val nodes: List<Node>

Returns only the child subnodes, excluding tokens.

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

The parser stack frames active when this Node was created.

Link copied to clipboard
val token: T
Link copied to clipboard
open override val tokens: List<Token>

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 override fun tokenAt(index: Int): T

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 override fun tokensRecursively(): <Error class: unknown class>

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