ExpectedToken

class ExpectedToken<T>(tokenType: TokenType, withValue: String? = null, stateCallback: StateCallback<T, String, *>? = null) : Expectation<T, String>

An expectation that expects a token to be present at this point.

For example:

"Hello!"
Tokens: [QUOTE = ", STRING_CONTENT = Hello!, QUOTE = "]

You could define a "string value" node with three expectations:

  • For the first ", an expectation for a QUOTE token (see ExpectedToken)

  • For the string content in the middle, an expectation for a STRING_CONTENT token.

  • For the second ", an expectation for a QUOTE token.

Constructors

Link copied to clipboard
constructor(tokenType: TokenType, withValue: String? = null, stateCallback: StateCallback<T, String, *>? = null)

Properties

Link copied to clipboard

The name of the argument where the result of this expectation should be stored, or null if the matched value of this expectation should not or cannot be stored.

Link copied to clipboard
open override val title: String

Title of this expectation. This should be a shortened description of what this expectation is. For example, an expectation for a node could have the title expect(SomeNode). If possible and legible, this title should be similar to the DSL expression for creating the expectation

Functions

Link copied to clipboard
open override fun matches(context: ParsingContext, index: Int): ExpectationResult<T>

Check if this expectation matches the given context at the given index among the context's tokens list.