Make infinite loop and left recursion detectors work with named rules

Add missing |named| case to the visitor in lib/compiler/asts.js, which
makes the infinite loop and left recursion detectors work correctly with
named rules.

The missing case caused |make parser| to fail with:

  140:34: Infinite loop detected.
  make: *** [parser] Error 1
redux
David Majda 9 years ago
parent 130cbcfaa3
commit d7d7e87874

@ -22,7 +22,8 @@ var asts = {
}
var advances = visitor.build({
rule: advancesExpression,
rule: advancesExpression,
named: advancesExpression,
choice: function(node) {
return arrays.every(node.alternatives, advances);

@ -26,6 +26,15 @@ describe("compiler pass |reportInfiniteLoops|", function() {
});
it("computes empty string matching correctly", function() {
expect(pass).toReportError([
'start = a*',
'a "a" = ""'
].join('\n'));
expect(pass).not.toReportError([
'start = a*',
'a "a" = "a"'
].join('\n'));
expect(pass).toReportError('start = ("" / "a" / "b")*');
expect(pass).toReportError('start = ("a" / "" / "b")*');
expect(pass).toReportError('start = ("a" / "b" / "")*');

@ -40,6 +40,15 @@ describe("compiler pass |reportLeftRecursion|", function() {
});
it("computes empty string matching correctly", function() {
expect(pass).toReportError([
'start = a start',
'a "a" = ""'
].join('\n'));
expect(pass).not.toReportError([
'start = a start',
'a "a" = "a"'
].join('\n'));
expect(pass).toReportError('start = ("" / "a" / "b") start');
expect(pass).toReportError('start = ("a" / "" / "b") start');
expect(pass).toReportError('start = ("a" / "b" / "") start');

Loading…
Cancel
Save