From d7d7e87874bbea05ed2a6a7bd4c415db5e08b831 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 3 Aug 2015 16:56:57 +0200 Subject: [PATCH] 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 --- lib/compiler/asts.js | 3 ++- spec/unit/compiler/passes/report-infinite-loops.spec.js | 9 +++++++++ spec/unit/compiler/passes/report-left-recursion.spec.js | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index 67344de..aad50a6 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -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); diff --git a/spec/unit/compiler/passes/report-infinite-loops.spec.js b/spec/unit/compiler/passes/report-infinite-loops.spec.js index 4efd821..fac311d 100644 --- a/spec/unit/compiler/passes/report-infinite-loops.spec.js +++ b/spec/unit/compiler/passes/report-infinite-loops.spec.js @@ -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" / "")*'); diff --git a/spec/unit/compiler/passes/report-left-recursion.spec.js b/spec/unit/compiler/passes/report-left-recursion.spec.js index 3897619..e2e4999 100644 --- a/spec/unit/compiler/passes/report-left-recursion.spec.js +++ b/spec/unit/compiler/passes/report-left-recursion.spec.js @@ -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');