diff --git a/examples/simple.js b/examples/simple.js index 2360c45..de84259 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -31,6 +31,10 @@ sys.inherits(MyParser, Parser); MyParser.prototype.number = function number(token, type, next) { //console.log('current queue in number', this._queue); + if ('eof' === type) { + return; + } + assert.equal(type, 'number', "unexpected token "+token+"("+type+"). expecting number"); var nb = parseInt(token); for (var i = 0; i < nb; ++i) { diff --git a/lib/Parser.js b/lib/Parser.js index 3e667ec..d0164f2 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -34,6 +34,9 @@ function Parser (tokenizer) { this._tokenizer.on('end', function() { self._newToken('', 'eof'); }); + this._tokenizer.on('data', function() { + //consume or 'end' will never be emitted + }); this._tokenizer.on('token', function(token, type) { self._newToken(token, type); });