fcs
2025-04-10 0163870d662dc5b7d69ceff977490ede594f7d82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
 
module.exports = TokenStream;
function TokenStream(tokens) {
  if (!Array.isArray(tokens)) {
    throw new TypeError('tokens must be passed to TokenStream as an array.');
  }
  this._tokens = tokens;
}
TokenStream.prototype.lookahead = function (index) {
  if (this._tokens.length <= index) {
    throw new Error('Cannot read past the end of a stream');
  }
  return this._tokens[index];
};
TokenStream.prototype.peek = function () {
  if (this._tokens.length === 0) {
    throw new Error('Cannot read past the end of a stream');
  }
  return this._tokens[0];
};
TokenStream.prototype.advance = function () {
  if (this._tokens.length === 0) {
    throw new Error('Cannot read past the end of a stream');
  }
  return this._tokens.shift();
};
TokenStream.prototype.defer = function (token) {
  this._tokens.unshift(token);
};