s/alwaysAdvancesOnSuccess/alwaysConsumesOnSuccess/
Matches terminology change from the previous commit.
This commit is contained in:
parent
6ff005786c
commit
ebf5d969b2
|
@ -13,51 +13,51 @@ var asts = {
|
||||||
return arrays.indexOf(ast.rules, function(r) { return r.name === name; });
|
return arrays.indexOf(ast.rules, function(r) { return r.name === name; });
|
||||||
},
|
},
|
||||||
|
|
||||||
alwaysAdvancesOnSuccess: function(ast, node) {
|
alwaysConsumesOnSuccess: function(ast, node) {
|
||||||
function advancesTrue() { return true; }
|
function consumesTrue() { return true; }
|
||||||
function advancesFalse() { return false; }
|
function consumesFalse() { return false; }
|
||||||
|
|
||||||
function advancesExpression(node) {
|
function consumesExpression(node) {
|
||||||
return advances(node.expression);
|
return consumes(node.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
var advances = visitor.build({
|
var consumes = visitor.build({
|
||||||
rule: advancesExpression,
|
rule: consumesExpression,
|
||||||
named: advancesExpression,
|
named: consumesExpression,
|
||||||
|
|
||||||
choice: function(node) {
|
choice: function(node) {
|
||||||
return arrays.every(node.alternatives, advances);
|
return arrays.every(node.alternatives, consumes);
|
||||||
},
|
},
|
||||||
|
|
||||||
action: advancesExpression,
|
action: consumesExpression,
|
||||||
|
|
||||||
sequence: function(node) {
|
sequence: function(node) {
|
||||||
return arrays.some(node.elements, advances);
|
return arrays.some(node.elements, consumes);
|
||||||
},
|
},
|
||||||
|
|
||||||
labeled: advancesExpression,
|
labeled: consumesExpression,
|
||||||
text: advancesExpression,
|
text: consumesExpression,
|
||||||
simple_and: advancesFalse,
|
simple_and: consumesFalse,
|
||||||
simple_not: advancesFalse,
|
simple_not: consumesFalse,
|
||||||
optional: advancesFalse,
|
optional: consumesFalse,
|
||||||
zero_or_more: advancesFalse,
|
zero_or_more: consumesFalse,
|
||||||
one_or_more: advancesExpression,
|
one_or_more: consumesExpression,
|
||||||
semantic_and: advancesFalse,
|
semantic_and: consumesFalse,
|
||||||
semantic_not: advancesFalse,
|
semantic_not: consumesFalse,
|
||||||
|
|
||||||
rule_ref: function(node) {
|
rule_ref: function(node) {
|
||||||
return advances(asts.findRule(ast, node.name));
|
return consumes(asts.findRule(ast, node.name));
|
||||||
},
|
},
|
||||||
|
|
||||||
literal: function(node) {
|
literal: function(node) {
|
||||||
return node.value !== "";
|
return node.value !== "";
|
||||||
},
|
},
|
||||||
|
|
||||||
"class": advancesTrue,
|
"class": consumesTrue,
|
||||||
any: advancesTrue
|
any: consumesTrue
|
||||||
});
|
});
|
||||||
|
|
||||||
return advances(node);
|
return consumes(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ var GrammarError = require("../../grammar-error"),
|
||||||
function reportInfiniteLoops(ast) {
|
function reportInfiniteLoops(ast) {
|
||||||
var check = visitor.build({
|
var check = visitor.build({
|
||||||
zero_or_more: function(node) {
|
zero_or_more: function(node) {
|
||||||
if (!asts.alwaysAdvancesOnSuccess(ast, node.expression)) {
|
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
|
||||||
throw new GrammarError("Infinite loop detected.", node.location);
|
throw new GrammarError("Infinite loop detected.", node.location);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
one_or_more: function(node) {
|
one_or_more: function(node) {
|
||||||
if (!asts.alwaysAdvancesOnSuccess(ast, node.expression)) {
|
if (!asts.alwaysConsumesOnSuccess(ast, node.expression)) {
|
||||||
throw new GrammarError("Infinite loop detected.", node.location);
|
throw new GrammarError("Infinite loop detected.", node.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ function reportLeftRecursion(ast) {
|
||||||
arrays.every(node.elements, function(element) {
|
arrays.every(node.elements, function(element) {
|
||||||
check(element);
|
check(element);
|
||||||
|
|
||||||
return !asts.alwaysAdvancesOnSuccess(ast, element);
|
return !asts.alwaysConsumesOnSuccess(ast, element);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe("compiler pass |reportInfiniteLoops|", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("computes expressions that always advance on success correctly", function() {
|
it("computes expressions that always consume input on success correctly", function() {
|
||||||
expect(pass).toReportError([
|
expect(pass).toReportError([
|
||||||
'start = a*',
|
'start = a*',
|
||||||
'a "a" = ""'
|
'a "a" = ""'
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe("compiler pass |reportLeftRecursion|", function() {
|
||||||
expect(pass).toReportError('start = "" start?');
|
expect(pass).toReportError('start = "" start?');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("computes expressions that always advance on success correctly", function() {
|
it("computes expressions that always consume input on success correctly", function() {
|
||||||
expect(pass).toReportError([
|
expect(pass).toReportError([
|
||||||
'start = a start',
|
'start = a start',
|
||||||
'a "a" = ""'
|
'a "a" = ""'
|
||||||
|
|
Loading…
Reference in a new issue