LexerContext

interface LexerContext<T>

A lexing context, created by a Lexer.parse call, which exposes an interface for advanced lexing.

Author

AdrianTodt

Parameters

T

The type of tokens the lexer generates.

Functions

hasNext
Link copied to clipboard
common
abstract fun hasNext(): Boolean
Checks if there's more characters ahead.
match
Link copied to clipboard
common
abstract fun match(expect: Char): Boolean
Peeks the next character and, if equals the expected character, consumes it.
next
Link copied to clipboard
common
abstract fun next(): Char
Returns the next character of the reader.
nextString
Link copied to clipboard
common
abstract fun nextString(length: Int): String
Returns a predefined length of characters of the reader, as a String.
parseOnce
Link copied to clipboard
common
abstract fun parseOnce(): List<T>
Lexes once and return the processed tokens.
peek
Link copied to clipboard
common
abstract fun peek(): Char
Peeks the next character of the reader.
abstract fun peek(distance: Int): Char
Peeks a character a distance far away of the reader.
peekString
Link copied to clipboard
common
abstract fun peekString(length: Int): String
Peeks a string with a predefined length of the reader.
process
Link copied to clipboard
common
abstract fun process(token: T)
Calls the Lexer.parse's token consumer.

Properties

lineIndex
Link copied to clipboard
common
abstract val lineIndex: Int
The current line index.
lineNumber
Link copied to clipboard
common
abstract val lineNumber: Int
The current line number.
reader
Link copied to clipboard
common
abstract val reader: StringReader
This context' reader.
source
Link copied to clipboard
common
abstract val source: Source
The original source of this context.

Inheritors

LexerImpl
Link copied to clipboard
LexerImpl.ContextImpl
Link copied to clipboard

Extensions

makeToken
Link copied to clipboard
common
fun <T> LexerContext<Token<T>>.makeToken(tokenType: T, offset: Int = 1): Token<T>
Creates a token.
fun <T> LexerContext<Token<T>>.makeToken(tokenType: T, string: String, offset: Int = 0): Token<T>
Creates a token.
readIdentifier
Link copied to clipboard
common
fun LexerContext<*>.readIdentifier(firstChar: Char? = null): String
Reads a C-like identifier.
readNumber
Link copied to clipboard
common
fun LexerContext<*>.readNumber(c: Char): LexicalNumber
Reads a number.
readString
Link copied to clipboard
common
fun LexerContext<*>.readString(delimiter: Char): String
Reads a String up until a delimiter.
section
Link copied to clipboard
common
fun LexerContext<*>.section(offset: Int, length: Int = 0): Section
Creates a section.