Fix |resultStackDepth| computation for sequences

The |1 + ...| was wrong -- sequence does not need its own variable since
it reuses the one used by the first item.

Part of a fix for GH-53.
redux
David Majda 13 years ago
parent 9c3da347cc
commit 756b6fc473

@ -153,7 +153,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4;
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
@ -219,7 +219,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -265,7 +265,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5;
var result0, result1, result2, result3, result4;
var pos0, pos1, pos2;
pos0 = pos;
@ -332,7 +332,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5;
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -416,7 +416,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -495,7 +495,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -550,7 +550,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -682,7 +682,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -786,7 +786,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4;
var result0, result1, result2;
var pos0, pos1, pos2, pos3, pos4;
pos0 = pos;
@ -899,7 +899,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
reportFailures++;
@ -944,7 +944,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -1083,7 +1083,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1131,7 +1131,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1179,7 +1179,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1227,7 +1227,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1275,7 +1275,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1323,7 +1323,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1371,7 +1371,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1419,7 +1419,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1467,7 +1467,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1515,7 +1515,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1563,7 +1563,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1611,7 +1611,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -1659,7 +1659,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
reportFailures++;
@ -1789,7 +1789,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
reportFailures++;
@ -1858,7 +1858,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
reportFailures++;
@ -1906,7 +1906,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -2008,7 +2008,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -2087,7 +2087,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -2189,7 +2189,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -2268,7 +2268,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5, result6;
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2;
reportFailures++;
@ -2398,7 +2398,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -2532,7 +2532,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -2611,7 +2611,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -2715,7 +2715,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -2772,7 +2772,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2;
pos0 = pos;
@ -2828,7 +2828,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5;
var result0, result1, result2, result3, result4;
var pos0, pos1, pos2;
pos0 = pos;
@ -2896,7 +2896,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2;
var result0, result1;
var pos0, pos1, pos2;
pos0 = pos;
@ -3144,7 +3144,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5;
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
@ -3250,7 +3250,7 @@ PEG.parser = (function(){
return cachedResult.result;
}
var result0, result1, result2, result3, result4, result5;
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;

@ -124,7 +124,7 @@ PEG.compiler.passes = {
sequence:
function(node) {
each(node.elements, compute);
node.resultStackDepth = 1 + Math.max.apply(
node.resultStackDepth = Math.max.apply(
null,
map(node.elements, function(e, i) { return i + e.resultStackDepth; })
);

@ -169,42 +169,42 @@ test("computes stack depths", function() {
/* Sequence */
{
grammar: 'start = "a" "b" "c"',
resultStackDepth: 4,
resultStackDepth: 3,
posStackDepth: 2
},
{
grammar: 'start = "a" "b" "c"*',
resultStackDepth: 5,
resultStackDepth: 4,
posStackDepth: 2
},
{
grammar: 'start = "a" "b"* "c"',
resultStackDepth: 4,
resultStackDepth: 3,
posStackDepth: 2
},
{
grammar: 'start = "a" ("b"*)* "c"',
resultStackDepth: 5,
resultStackDepth: 4,
posStackDepth: 2
},
{
grammar: 'start = "a"* "b" "c"',
resultStackDepth: 4,
resultStackDepth: 3,
posStackDepth: 2
},
{
grammar: 'start = ("a"*)* "b" "c"',
resultStackDepth: 4,
resultStackDepth: 3,
posStackDepth: 2
},
{
grammar: 'start = (("a"*)*)* "b" "c"',
resultStackDepth: 5,
resultStackDepth: 4,
posStackDepth: 2
},
{
grammar: 'start = "a" &"b" "c"',
resultStackDepth: 4,
resultStackDepth: 3,
posStackDepth: 3
},

Loading…
Cancel
Save