跳到主要内容

tokenReader.js

class TokenReader {
constructor(tokens) {
this.tokens = tokens;
this.pos = 0;
}
read() {
if (this.pos < this.tokens.length) {
return this.tokens[this.pos++];
}
return null;
}
peek() {
if (this.pos < this.tokens.length) {
return this.tokens[this.pos];
}
return null;
}
unread() {
if (this.pos > 0) {
this.pos--;
}
}
}

module.exports = TokenReader;