Browse Source

Fix a bug in param name fixup code for sequences

redux
David Majda 10 years ago
parent
commit
f47da5c682
  1. 2
      src/passes.js
  2. 10
      test/passes-test.js

2
src/passes.js

@ -364,7 +364,7 @@ PEG.compiler.passes = {
function fixup(name) {
each(pluck(node.elements, "resultVar"), function(resultVar, i) {
if (env[name].substr(0, resultVar.length) === resultVar) {
if ((new RegExp("^" + resultVar + "(\\[\\d+\\])*$")).test(env[name])) {
env[name] = node.resultVar + "[" + i + "]"
+ env[name].substr(resultVar.length);
}

10
test/passes-test.js

@ -579,6 +579,16 @@ test("computes params", function() {
d: "result0[1][2]",
e: "result0[2]"
}
},
/*
* Regression tests for a bug where e.g. resultVar names like |result10|
* were incorrectly treated as names derived from |result1|, leading to
* incorrect substitution.
*/
{
grammar: 'start = ("a" "b" "c" "d" "e" "f" "g" "h" "i" j:"j" { })*',
extractor: extractExpression,
params: { j: "result1[9]" } // Buggy code put "result1[0]0" here.
}
];

Loading…
Cancel
Save