From 491106c347ca9a62e527b94ba284a56ee51ca3b2 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 11 Sep 2015 14:58:53 +0200 Subject: [PATCH] Report left recursion and infinite loops only as "possible" A semantic predicate can prevent the parser to actually enter infinite recursion or loop. This is undetectable at compile-time. --- lib/compiler/passes/report-infinite-loops.js | 4 ++-- lib/compiler/passes/report-left-recursion.js | 2 +- spec/unit/compiler/passes/report-infinite-loops.spec.js | 4 ++-- spec/unit/compiler/passes/report-left-recursion.spec.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/compiler/passes/report-infinite-loops.js b/lib/compiler/passes/report-infinite-loops.js index f4481f1..9b6a6dc 100644 --- a/lib/compiler/passes/report-infinite-loops.js +++ b/lib/compiler/passes/report-infinite-loops.js @@ -12,13 +12,13 @@ function reportInfiniteLoops(ast) { var check = visitor.build({ zero_or_more: function(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { - throw new GrammarError("Infinite loop detected.", node.location); + throw new GrammarError("Possible infinite loop detected.", node.location); } }, one_or_more: function(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { - throw new GrammarError("Infinite loop detected.", node.location); + throw new GrammarError("Possible infinite loop detected.", node.location); } } }); diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index 252c172..02f5900 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -38,7 +38,7 @@ function reportLeftRecursion(ast) { rule_ref: function(node) { if (arrays.contains(visitedRules, node.name)) { throw new GrammarError( - "Left recursion detected for rule \"" + node.name + "\".", + "Possible left recursion detected for rule \"" + node.name + "\".", node.location ); } diff --git a/spec/unit/compiler/passes/report-infinite-loops.spec.js b/spec/unit/compiler/passes/report-infinite-loops.spec.js index 21f8e57..24d0366 100644 --- a/spec/unit/compiler/passes/report-infinite-loops.spec.js +++ b/spec/unit/compiler/passes/report-infinite-loops.spec.js @@ -8,7 +8,7 @@ describe("compiler pass |reportInfiniteLoops|", function() { it("reports infinite loops for zero_or_more", function() { expect(pass).toReportError('start = ("")*', { - message: "Infinite loop detected.", + message: "Possible infinite loop detected.", location: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 13, line: 1, column: 14 } @@ -18,7 +18,7 @@ describe("compiler pass |reportInfiniteLoops|", function() { it("reports infinite loops for one_or_more", function() { expect(pass).toReportError('start = ("")+', { - message: "Infinite loop detected.", + message: "Possible infinite loop detected.", location: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 13, line: 1, column: 14 } diff --git a/spec/unit/compiler/passes/report-left-recursion.spec.js b/spec/unit/compiler/passes/report-left-recursion.spec.js index 272af3a..4a1e73f 100644 --- a/spec/unit/compiler/passes/report-left-recursion.spec.js +++ b/spec/unit/compiler/passes/report-left-recursion.spec.js @@ -8,7 +8,7 @@ describe("compiler pass |reportLeftRecursion|", function() { it("reports direct left recursion", function() { expect(pass).toReportError('start = start', { - message: 'Left recursion detected for rule \"start\".', + message: 'Possible left recursion detected for rule \"start\".', location: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 13, line: 1, column: 14 } @@ -21,7 +21,7 @@ describe("compiler pass |reportLeftRecursion|", function() { 'start = stop', 'stop = start' ].join("\n"), { - message: 'Left recursion detected for rule \"start\".', + message: 'Possible left recursion detected for rule \"start\".', location: { start: { offset: 21, line: 2, column: 9 }, end: { offset: 26, line: 2, column: 14 }