mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-17 11:51:31 +00:00
24 lines
529 B
Kotlin
24 lines
529 B
Kotlin
package gay.pizza.pork.parser
|
|
|
|
class TokenStreamSource(val stream: TokenStream) : TokenSource {
|
|
private var index = 0
|
|
override val currentIndex: Int
|
|
get() = index
|
|
|
|
override fun next(): Token {
|
|
if (index == stream.tokens.size) {
|
|
return Token.endOfFile(stream.tokens.size)
|
|
}
|
|
val char = stream.tokens[index]
|
|
index++
|
|
return char
|
|
}
|
|
|
|
override fun peek(): Token {
|
|
if (index == stream.tokens.size) {
|
|
return Token.endOfFile(stream.tokens.size)
|
|
}
|
|
return stream.tokens[index]
|
|
}
|
|
}
|