diff --git a/lib/reparse.js b/lib/reparse.js index 3751dad..c786647 100644 --- a/lib/reparse.js +++ b/lib/reparse.js @@ -1,61 +1,35 @@ -// Generated by CoffeeScript 1.3.1 +// Generated by CoffeeScript 1.5.0 (function() { var ReParse, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; exports.ReParse = ReParse = (function() { - ReParse.name = 'ReParse'; - function ReParse() { this.chainl1 = __bind(this.chainl1, this); - this.chainl = __bind(this.chainl, this); - this.sepEndBy1 = __bind(this.sepEndBy1, this); - this.sepEndBy = __bind(this.sepEndBy, this); - this.endBy1 = __bind(this.endBy1, this); - this.endBy = __bind(this.endBy, this); - this.sepBy1 = __bind(this.sepBy1, this); - this.sepBy = __bind(this.sepBy, this); - this.many1 = __bind(this.many1, this); - this.many = __bind(this.many, this); - this.skipWS = __bind(this.skipWS, this); - this.skip1 = __bind(this.skip1, this); - this.skip = __bind(this.skip, this); - this.seq = __bind(this.seq, this); - this.choice = __bind(this.choice, this); - this.between = __bind(this.between, this); - this.option = __bind(this.option, this); - this.maybe = __bind(this.maybe, this); - - this.match = __bind(this.match, this); - + this.m = __bind(this.m, this); this.start = __bind(this.start, this); - this.produce = __bind(this.produce, this); - this.fail = __bind(this.fail, this); - this.eof = __bind(this.eof, this); - this.parse = __bind(this.parse, this); - } ReParse.prototype.ignorews = false; @@ -77,7 +51,7 @@ ReParse.prototype.produce = function(method) { var val; - val = method instanceof RegExp ? this.match(method) : method.call(this); + val = (method instanceof RegExp) || (typeof method === 'string') ? this.m(method) : method.call(this); if (this.ignorews) { this.skipWS(); } @@ -101,11 +75,18 @@ throw new Error("Could not parse '" + this.input + "'."); }; - ReParse.prototype.match = function(pattern, putback) { + ReParse.prototype.m = function(pattern, putback) { var probe; if (putback == null) { putback = false; } + if (typeof pattern === 'string') { + if (this.input.substr(0, pattern.length) === pattern) { + this.input = this.input.substr(pattern.length); + return pattern; + } + return this.fail(); + } probe = this.input.match(pattern); if (!probe) { return this.fail(); @@ -226,7 +207,7 @@ }; ReParse.prototype.skipWS = function() { - this.match(/^\s*/); + this.m(/^\s*/); return this; };