Fix a bug in param name fixup code for sequences

redux
David Majda 12 years ago
parent 4d5b1d58aa
commit f47da5c682

@ -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);
}

@ -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