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
This commit is contained in:
parent
130cbcfaa3
commit
d7d7e87874
|
@ -23,6 +23,7 @@ var asts = {
|
||||||
|
|
||||||
var advances = visitor.build({
|
var advances = visitor.build({
|
||||||
rule: advancesExpression,
|
rule: advancesExpression,
|
||||||
|
named: advancesExpression,
|
||||||
|
|
||||||
choice: function(node) {
|
choice: function(node) {
|
||||||
return arrays.every(node.alternatives, advances);
|
return arrays.every(node.alternatives, advances);
|
||||||
|
|
|
@ -26,6 +26,15 @@ describe("compiler pass |reportInfiniteLoops|", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("computes empty string matching correctly", 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")*');
|
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() {
|
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');
|
expect(pass).toReportError('start = ("a" / "" / "b") start');
|
||||||
expect(pass).toReportError('start = ("a" / "b" / "") start');
|
expect(pass).toReportError('start = ("a" / "b" / "") start');
|
||||||
|
|
Loading…
Reference in a new issue