Fix left recursion detection in sequences
Report left recursion also in cases where the recursive rule invocation is not a direct element of a sequence, but is wrapped inside an expression. Fixes #359.
This commit is contained in:
parent
9eb62051be
commit
ad27a300a8
|
@ -29,9 +29,7 @@ function reportLeftRecursion(ast) {
|
||||||
|
|
||||||
sequence: function(node) {
|
sequence: function(node) {
|
||||||
arrays.every(node.elements, function(element) {
|
arrays.every(node.elements, function(element) {
|
||||||
if (element.type === "rule_ref") {
|
|
||||||
check(element);
|
check(element);
|
||||||
}
|
|
||||||
|
|
||||||
return !asts.alwaysAdvancesOnSuccess(ast, element);
|
return !asts.alwaysAdvancesOnSuccess(ast, element);
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,6 +39,11 @@ describe("compiler pass |reportLeftRecursion|", function() {
|
||||||
expect(pass).not.toReportError('start = "" "" "a" start');
|
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() {
|
it("computes expressions that always advance on success correctly", function() {
|
||||||
expect(pass).toReportError([
|
expect(pass).toReportError([
|
||||||
'start = a start',
|
'start = a start',
|
||||||
|
|
Loading…
Reference in a new issue