diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index 8decd1b..9745fce 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -29,9 +29,7 @@ function reportLeftRecursion(ast) { sequence: function(node) { arrays.every(node.elements, function(element) { - if (element.type === "rule_ref") { - check(element); - } + check(element); return !asts.alwaysAdvancesOnSuccess(ast, element); }); diff --git a/spec/unit/compiler/passes/report-left-recursion.spec.js b/spec/unit/compiler/passes/report-left-recursion.spec.js index f9cfa84..aa8fa21 100644 --- a/spec/unit/compiler/passes/report-left-recursion.spec.js +++ b/spec/unit/compiler/passes/report-left-recursion.spec.js @@ -39,6 +39,11 @@ describe("compiler pass |reportLeftRecursion|", function() { expect(pass).not.toReportError('start = "" "" "a" start'); }); + /* Regression test for #359. */ + it("reports left recursion when rule reference is wrapped in an expression", function() { + expect(pass).toReportError('start = "" start?'); + }); + it("computes expressions that always advance on success correctly", function() { expect(pass).toReportError([ 'start = a start',