Permalink
Browse files

add support for `expand`

when a handler returns `true` then the next handler is called with
the same token
  • Loading branch information...
1 parent 0d2b472 commit fe4cfab297841b9e48621a4c175073cc6c4700e2 @Floby committed Apr 13, 2011
Showing with 13 additions and 10 deletions.
  1. +13 −10 lib/Parser.js
View
@@ -61,16 +61,19 @@ Parser.prototype.defaultHandler = function defaultHandler(h) {
Parser.prototype._newToken = function _newToken(token, type) {
if(!this._haveDefault) this.defaultHandler(makeIgnore(0));
// this is a really naive implementation
- var f = this._queue.shift();
- if(!f) {
- this.emit('error', new SyntaxError("unexpected token "+token));
- return;
- }
- queue = this._queue;
- function next(fun) {
- queue.unshift.apply(queue, arguments);
- }
- f.call(this, token, type, next);
+ var expand = false;
+ do {
+ var f = this._queue.shift();
+ if(!f) {
+ this.emit('error', new SyntaxError("no handler for "+token));
+ return;
+ }
+ queue = this._queue;
+ function next(fun) {
+ queue.unshift.apply(queue, arguments);
+ }
+ expand = f.call(this, token, type, next);
+ } while(expand === true)
};
Parser.prototype._reachedEnd = function _reachedEnd() {

0 comments on commit fe4cfab

Please sign in to comment.