Comparing version 0.0.1 to 0.0.2
@@ -133,11 +133,12 @@ /* | ||
var regexn = this._regexn, | ||
startRe = string[this._id]|| 0, | ||
matches = [], found = false, offset, | ||
startRe = string[this._id] || 0, | ||
matches = [], found = false, | ||
that = this, resolveMatch; | ||
resolveMatch = function (match, i, lastIndex, noMatch) { | ||
that._spec.resolveMatch(match, i).forEach(function (res) { | ||
if (res[0] && _.some(res[1], _.isString)) { | ||
that.emit(res[0], res[0], res[1].concat(lastIndex)); | ||
} | ||
matches.push(res[1]); | ||
var hasStrings = _.some(res[1], _.isString), | ||
match = hasStrings ? res[1].concat(lastIndex) : res[1]; | ||
if (!noMatch && res[0] && hasStrings) | ||
that.emit(res[0], res[0], match); | ||
matches.push(match); | ||
}); | ||
@@ -154,3 +155,2 @@ }; | ||
resolveMatch(match, i, re.lastIndex); | ||
offset = re.lastIndex; | ||
found = true; | ||
@@ -163,5 +163,3 @@ } else { | ||
if (!found) | ||
string[this._id] = 0; | ||
else | ||
matches.push(offset); | ||
delete string[this._id]; | ||
return found ? matches : false; | ||
@@ -168,0 +166,0 @@ }; |
{ | ||
"name": "remix", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "regular expression alternation for tokenizers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -55,3 +55,3 @@ /* | ||
it("should match simple", function () { | ||
this.re.add(/(foo)o/).exec('fooo').should.deep.equal([['fooo', 'foo'], 4]); | ||
this.re.add(/(foo)o/).exec('fooo').should.deep.equal([['fooo', 'foo', 4]]); | ||
}); | ||
@@ -61,4 +61,4 @@ it("should match multiple", function () { | ||
this.re.add(/(foo)/, /bar/); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo'], [undefined], 3]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined], ['bar'], 6]); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo', 3], [undefined]]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined], ['bar', 6]]); | ||
this.re._regexn.should.deep.equal([/((foo))|(bar)/g]); | ||
@@ -69,4 +69,4 @@ }); | ||
this.re.add(/(foo)o/, /(bar)r/i); | ||
this.re.exec(str).should.deep.equal([['fooo', 'foo'], [undefined, undefined], 4]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined], ['Barr', 'Bar'], 8]); | ||
this.re.exec(str).should.deep.equal([['fooo', 'foo', 4], [undefined, undefined]]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined], ['Barr', 'Bar', 8]]); | ||
this.re._regexn.should.deep.equal([/((foo)o)/g, /((bar)r)/ig]); | ||
@@ -106,6 +106,6 @@ }); | ||
this.re.add(/(foo)/); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo'], 3]); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo', 3]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo'], 3]); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo'], 9]); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo', 3]]); | ||
this.re.exec(str).should.deep.equal([['foo', 'foo', 9]]); | ||
}); | ||
@@ -115,6 +115,6 @@ it("should reject length", function () { | ||
this.re.add(/(ooo|rrr)/); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo'], 4]); | ||
this.re.exec(str).should.deep.equal([['rrr', 'rrr'], 11]); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo', 4]]); | ||
this.re.exec(str).should.deep.equal([['rrr', 'rrr', 11]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo'], 4]); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo', 4]]); | ||
}); | ||
@@ -124,8 +124,8 @@ it("should reject multi", function () { | ||
this.re.add(/(ooo)/, /rrr/); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo', 4], [undefined]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined],['rrr'], 11]); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo', 4], [undefined]]); | ||
this.re.exec(str).should.deep.equal([[undefined, undefined],['rrr', 11]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([['ooo', 'ooo', 4], [undefined]]); | ||
}); | ||
@@ -135,8 +135,8 @@ it("should reject multi no-join", function () { | ||
this.re.add(/ooo/, /rrr/i); | ||
this.re.exec(str).should.deep.equal([['ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([['ooo', 4], [undefined]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([[undefined], ['rrr'], 11]); | ||
this.re.exec(str).should.deep.equal([['ooo', 4], [undefined]]); | ||
this.re.exec(str).should.deep.equal([[undefined], ['rrr', 11]]); | ||
this.re.reject(str); | ||
this.re.exec(str).should.deep.equal([['ooo'], [undefined], 4]); | ||
this.re.exec(str).should.deep.equal([['ooo', 4], [undefined]]); | ||
}); | ||
@@ -143,0 +143,0 @@ it("should allow named regex", function (done) { |
23396
554