ParserInput
An immutable, position-aware view into a token sequence, optionally carrying a user-defined context value.
Every successful parse step produces a new ParserInput advanced past the consumed tokens; the underlying input list and userContext are shared by reference, so advancing is allocation-light.
Type parameters
I — the token type (e.g.
Char). Covariant: aParserInput<Char, U>can be read wherever aParserInput<Any, U>is expected.U — the user context type. Invariant. Use Unit when no context is needed.
Example
data class ParseState(val source: String)
val input = ParserInput.of("hello".toList(), ParseState("hello.kt"))
println(input.current()) // 'h'
println(input.advance().current()) // 'e'
println(input.userContext.source) // "hello.kt"Content copied to clipboard
Parameters
input
the full token sequence being parsed.
index
the current position within input.
userContext
an arbitrary value threaded through parsing unchanged.
See also
Properties
Functions
Link copied to clipboard
Returns a new ParserInput advanced by one position, sharing the same input list and userContext.