LexemeMatch

data class LexemeMatch<out T : Token>(val length: Int, val factory: () -> T? = null)

Represents a successful Lexeme match result.

A LexemeMatch describes how many characters were matched (length), and optionally provides a factory function for creating the corresponding T. The token factory is invoked by the Lexer after validating the match.

If factory is (or can be) null, the Lexeme producing this LexemeMatch must implement Lexeme.defaultFactory.

Matches must have a positive length; zero or negative lengths will cause the Lexer to throw an exception.

Parameters

T

The type of Token produced by this match

Constructors

Link copied to clipboard
constructor(length: Int, factory: () -> T? = null)

Properties

Link copied to clipboard
val factory: () -> T? = null

A function that creates a new instance of T for this match; if null, falls back to Lexeme.defaultFactory

Link copied to clipboard
val length: Int

The (positive, non-zero) number of characters matched by the Lexeme