From f5e43f842cd9a809bd81b70fab81eee5136c0364 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 3 Jul 2016 17:56:25 +0200 Subject: [PATCH] Grammar error messages 2/3: Improve the infinite loop message New wording is more explanatory. Part of #371. --- lib/compiler/passes/report-infinite-loops.js | 10 ++++++++-- .../unit/compiler/passes/report-infinite-loops.spec.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/compiler/passes/report-infinite-loops.js b/lib/compiler/passes/report-infinite-loops.js index 9b6a6dc..766df22 100644 --- a/lib/compiler/passes/report-infinite-loops.js +++ b/lib/compiler/passes/report-infinite-loops.js @@ -12,13 +12,19 @@ function reportInfiniteLoops(ast) { var check = visitor.build({ zero_or_more: function(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { - throw new GrammarError("Possible infinite loop detected.", node.location); + throw new GrammarError( + "Possible infinite loop when parsing (repetition used with with an expression that may not consume any input).", + node.location + ); } }, one_or_more: function(node) { if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) { - throw new GrammarError("Possible infinite loop detected.", node.location); + throw new GrammarError( + "Possible infinite loop when parsing (repetition used with with an expression that may not consume any input).", + 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 28ba3b6..9339d05 100644 --- a/spec/unit/compiler/passes/report-infinite-loops.spec.js +++ b/spec/unit/compiler/passes/report-infinite-loops.spec.js @@ -7,7 +7,7 @@ describe("compiler pass |reportInfiniteLoops|", function() { it("reports infinite loops for zero_or_more", function() { expect(pass).toReportError('start = ("")*', { - message: "Possible infinite loop detected.", + message: "Possible infinite loop when parsing (repetition used with with an expression that may not consume any input).", location: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 13, line: 1, column: 14 } @@ -17,7 +17,7 @@ describe("compiler pass |reportInfiniteLoops|", function() { it("reports infinite loops for one_or_more", function() { expect(pass).toReportError('start = ("")+', { - message: "Possible infinite loop detected.", + message: "Possible infinite loop when parsing (repetition used with with an expression that may not consume any input).", location: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 13, line: 1, column: 14 }