ParserContext

interface ParserContext<T, E>

A parsing context, created by a Parser.parse call, which exposes an interface for pratt-parsing.

Author

AdrianTodt

Parameters

T

The parser's (and grammar's) token type.

E

The parser's (and grammar's) expression result.

Functions

back
Link copied to clipboard
common
abstract fun back(): Token<T>
Move the index backwards one token and returns it.
eat
Link copied to clipboard
common
abstract fun eat(): Token<T>
Eats the current token, advancing the index by one.
abstract fun eat(type: T): Token<T>
Eats the current token, advancing the index by one.
match
Link copied to clipboard
common
abstract fun match(type: T): Boolean
Equivalent to nextIs, but eats the current token if true.
matchAny
Link copied to clipboard
common
abstract fun matchAny(vararg type: T): Boolean
Equivalent to nextIsAny, but eats the current token if true.
nextIs
Link copied to clipboard
common
abstract fun nextIs(type: T): Boolean
Peeks the next token and if the token types are equal, returns true.
nextIsAny
Link copied to clipboard
common
abstract fun nextIsAny(vararg types: T): Boolean
Peeks the next token and if the token type is equal to any of the types, returns true.
parseExpression
Link copied to clipboard
common
abstract fun parseExpression(precedence: Int = 0): E
Parses the expression using this parser's grammar.
open fun Grammar<T, E>.parseExpression(precedence: Int = 0): E
Parses the expression using another grammar.
peek
Link copied to clipboard
common
abstract fun peek(distance: Int = 0): Token<T>
Peeks a token a distance far away of the reader.
peekAheadUntil
Link copied to clipboard
common
abstract fun peekAheadUntil(vararg type: T): List<Token<T>>
Peeks the tokens ahead until a token of any of the types is found.
skipUntil
Link copied to clipboard
common
abstract fun skipUntil(vararg type: T)
Skips tokens ahead until a token of any of the types is found.
withGrammar
Link copied to clipboard
common
abstract fun withGrammar(grammar: Grammar<T, E>): ParserContext<T, E>
Creates a child parser context with the specified grammar.

Properties

eof
Link copied to clipboard
common
abstract val eof: Boolean
A property which is true if there's no more tokens.
grammar
Link copied to clipboard
common
abstract val grammar: Grammar<T, E>
The grammar of this parser's context.
index
Link copied to clipboard
common
abstract val index: Int
The current index in the list of tokens.
last
Link copied to clipboard
common
abstract val last: Token<T>
A property which contains the last token.

Inheritors

ParserImpl
Link copied to clipboard
ParserImpl.ContextImpl
Link copied to clipboard

Extensions

eatMulti
Link copied to clipboard
common
fun <T> ParserContext<T, *>.eatMulti(vararg types: T): List<Token<T>>
Eats tokens in a row.
ensureEOF
Link copied to clipboard
common
fun <R> ParserContext<*, *>.ensureEOF(block: () -> R): R
Ensures there's no character files after this block of code.