|
|
|
@ -13,51 +13,51 @@ var asts = {
|
|
|
|
|
return arrays.indexOf(ast.rules, function(r) { return r.name === name; });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
alwaysAdvancesOnSuccess: function(ast, node) {
|
|
|
|
|
function advancesTrue() { return true; }
|
|
|
|
|
function advancesFalse() { return false; }
|
|
|
|
|
alwaysConsumesOnSuccess: function(ast, node) {
|
|
|
|
|
function consumesTrue() { return true; }
|
|
|
|
|
function consumesFalse() { return false; }
|
|
|
|
|
|
|
|
|
|
function advancesExpression(node) {
|
|
|
|
|
return advances(node.expression);
|
|
|
|
|
function consumesExpression(node) {
|
|
|
|
|
return consumes(node.expression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var advances = visitor.build({
|
|
|
|
|
rule: advancesExpression,
|
|
|
|
|
named: advancesExpression,
|
|
|
|
|
var consumes = visitor.build({
|
|
|
|
|
rule: consumesExpression,
|
|
|
|
|
named: consumesExpression,
|
|
|
|
|
|
|
|
|
|
choice: function(node) {
|
|
|
|
|
return arrays.every(node.alternatives, advances);
|
|
|
|
|
return arrays.every(node.alternatives, consumes);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
action: advancesExpression,
|
|
|
|
|
action: consumesExpression,
|
|
|
|
|
|
|
|
|
|
sequence: function(node) {
|
|
|
|
|
return arrays.some(node.elements, advances);
|
|
|
|
|
return arrays.some(node.elements, consumes);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
labeled: advancesExpression,
|
|
|
|
|
text: advancesExpression,
|
|
|
|
|
simple_and: advancesFalse,
|
|
|
|
|
simple_not: advancesFalse,
|
|
|
|
|
optional: advancesFalse,
|
|
|
|
|
zero_or_more: advancesFalse,
|
|
|
|
|
one_or_more: advancesExpression,
|
|
|
|
|
semantic_and: advancesFalse,
|
|
|
|
|
semantic_not: advancesFalse,
|
|
|
|
|
labeled: consumesExpression,
|
|
|
|
|
text: consumesExpression,
|
|
|
|
|
simple_and: consumesFalse,
|
|
|
|
|
simple_not: consumesFalse,
|
|
|
|
|
optional: consumesFalse,
|
|
|
|
|
zero_or_more: consumesFalse,
|
|
|
|
|
one_or_more: consumesExpression,
|
|
|
|
|
semantic_and: consumesFalse,
|
|
|
|
|
semantic_not: consumesFalse,
|
|
|
|
|
|
|
|
|
|
rule_ref: function(node) {
|
|
|
|
|
return advances(asts.findRule(ast, node.name));
|
|
|
|
|
return consumes(asts.findRule(ast, node.name));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
literal: function(node) {
|
|
|
|
|
return node.value !== "";
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"class": advancesTrue,
|
|
|
|
|
any: advancesTrue
|
|
|
|
|
"class": consumesTrue,
|
|
|
|
|
any: consumesTrue
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return advances(node);
|
|
|
|
|
return consumes(node);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|