TokenElement

A PatternElement that matches a single Token based on a matcher criterion.

TokenElement uses a TokenMatcher to determine whether a token at the current position should be matched. Different matcher implementations support matching by token type, lexeme, or custom predicate.

When this PatternElement matches, exactly 1 TokenNode is added to the current capture.

Constructors

Link copied to clipboard
constructor(matcher: TokenElement.TokenMatcher)

Types

Link copied to clipboard

A matcher that matches tokens if they were produced by a specific lexeme.

Link copied to clipboard
class PredicateMatcher<K : Token>(val type: KClass<K>, val predicate: (K) -> Boolean) : TokenElement.TokenMatcher

A matcher that matches tokens by type and a custom predicate.

Link copied to clipboard
sealed interface TokenMatcher

Defines a criterion for matching tokens.

Link copied to clipboard

A matcher that matches tokens by their runtime type. Returns true if the token is an instance of K (including any subclass of K).

Properties

Link copied to clipboard

The matcher that determines whether a token should be matched

Functions

Link copied to clipboard
open override fun captureAt(tokenIndex: Int, capture: Node.ParserCapture): Int