|
|
|
@ -13,50 +13,50 @@ var asts = {
|
|
|
|
|
return arrays.indexOf(ast.rules, function(r) { return r.name === name; });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
matchesEmpty: function(ast, node) {
|
|
|
|
|
function matchesTrue() { return true; }
|
|
|
|
|
function matchesFalse() { return false; }
|
|
|
|
|
alwaysAdvancesOnSuccess: function(ast, node) {
|
|
|
|
|
function advancesTrue() { return true; }
|
|
|
|
|
function advancesFalse() { return false; }
|
|
|
|
|
|
|
|
|
|
function matchesExpression(node) {
|
|
|
|
|
return matches(node.expression);
|
|
|
|
|
function advancesExpression(node) {
|
|
|
|
|
return advances(node.expression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var matches = visitor.build({
|
|
|
|
|
rule: matchesExpression,
|
|
|
|
|
var advances = visitor.build({
|
|
|
|
|
rule: advancesExpression,
|
|
|
|
|
|
|
|
|
|
choice: function(node) {
|
|
|
|
|
return arrays.some(node.alternatives, matches);
|
|
|
|
|
return arrays.every(node.alternatives, advances);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
action: matchesExpression,
|
|
|
|
|
action: advancesExpression,
|
|
|
|
|
|
|
|
|
|
sequence: function(node) {
|
|
|
|
|
return arrays.every(node.elements, matches);
|
|
|
|
|
return arrays.some(node.elements, advances);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
labeled: matchesExpression,
|
|
|
|
|
text: matchesExpression,
|
|
|
|
|
simple_and: matchesTrue,
|
|
|
|
|
simple_not: matchesTrue,
|
|
|
|
|
optional: matchesTrue,
|
|
|
|
|
zero_or_more: matchesTrue,
|
|
|
|
|
one_or_more: matchesExpression,
|
|
|
|
|
semantic_and: matchesTrue,
|
|
|
|
|
semantic_not: matchesTrue,
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
|
|
rule_ref: function(node) {
|
|
|
|
|
return matches(asts.findRule(ast, node.name));
|
|
|
|
|
return advances(asts.findRule(ast, node.name));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
literal: function(node) {
|
|
|
|
|
return node.value === "";
|
|
|
|
|
return node.value !== "";
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"class": matchesFalse,
|
|
|
|
|
any: matchesFalse
|
|
|
|
|
"class": advancesTrue,
|
|
|
|
|
any: advancesTrue
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return matches(node);
|
|
|
|
|
return advances(node);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|