diff --git a/lib/compiler.js b/lib/compiler.js index eb73fd0..511e56a 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -394,8 +394,8 @@ PEG.Grammar.Rule.prototype.compile = function() { return PEG.Compiler.formatCode( "result._parse_${name} = function(context) {", - " this._cache[${name|string}] = this._cache[${name|string}] || [];", - " var cachedResult = this._cache[${name|string}][this._pos];", + " var cacheKey = ${name|string} + '@' + this._pos;", + " var cachedResult = this._cache[cacheKey];", " if (cachedResult !== undefined) {", " this._pos = cachedResult.nextPos;", " return cachedResult.result;", @@ -408,7 +408,7 @@ PEG.Grammar.Rule.prototype.compile = function() { " ${restoreReportMatchFailuresCode}", " ${reportMatchFailureCode}", " ", - " this._cache[${name|string}][pos] = {", + " this._cache[cacheKey] = {", " nextPos: this._pos,", " result: ${resultVar}", " };",