12345678910111213141516171819202122 |
- module.exports = class TokenStream {
- constructor() {
- this.tokens = []
- this.position = 0
- }
-
- advance() {
- this.position++
- }
-
- eat(tokenType) {
- if (this.peek() && this.peek().type === tokenType) {
- this.advance()
- return this.peek(-1)
- }
- return false
- }
-
- peek(step = 0) {
- return this.tokens[this.position + step]
- }
- }
|