From 730730604ad66c0430c73a02776b9591f308e964 Mon Sep 17 00:00:00 2001 From: ertrzyiks Date: Sat, 25 Oct 2014 22:22:06 +0200 Subject: [PATCH] fixed handling of eof --- examples/simple.js | 4 ++++ lib/Parser.js | 3 +++ 2 files changed, 7 insertions(+) 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); });