1 | var TokenIterator = module.exports = function(tokens, startIndex) {
|
2 | this._tokens = tokens;
|
3 | this._startIndex = startIndex || 0;
|
4 | };
|
5 |
|
6 | TokenIterator.prototype.head = function() {
|
7 | return this._tokens[this._startIndex];
|
8 | };
|
9 |
|
10 | TokenIterator.prototype.tail = function(startIndex) {
|
11 | return new TokenIterator(this._tokens, this._startIndex + 1);
|
12 | };
|
13 |
|
14 | TokenIterator.prototype.toArray = function() {
|
15 | return this._tokens.slice(this._startIndex);
|
16 | };
|
17 |
|
18 | TokenIterator.prototype.end = function() {
|
19 | return this._tokens[this._tokens.length - 1];
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 | TokenIterator.prototype.to = function(end) {
|
25 | var start = this.head().source;
|
26 | var endToken = end.head() || end.end();
|
27 | return start.to(endToken.source);
|
28 | };
|