don't emit tokens when doing a lookahead

This commit is contained in:
Sebastian McKenzie 2015-04-09 06:44:16 -07:00
parent 1e398e45ff
commit c9e7c306cc
2 changed files with 8 additions and 6 deletions

View File

@ -18,17 +18,19 @@ var STATE_KEYS = [
];
pp.getState = function () {
var state = {};
var state = {}
for (var i = 0; i < STATE_KEYS.length; i++) {
var key = STATE_KEYS[i];
state[key] = this[key];
var key = STATE_KEYS[i]
state[key] = this[key]
}
return state;
return state
};
pp.lookahead = function() {
var old = this.getState();
this.next();
this.isLookahead = true
this.next()
this.isLookahead = false
var curr = this.getState();
for (var key in old) this[key] = old[key];
return curr;

View File

@ -28,7 +28,7 @@ const pp = Parser.prototype
// Move to the next token
pp.next = function() {
if (this.options.onToken)
if (this.options.onToken && !this.isLookahead)
this.options.onToken(new Token(this))
this.lastTokEnd = this.end