You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
12 years ago
|
var utils = require("../../utils");
|
||
|
|
||
13 years ago
|
/* Checks that all referenced rules exist. */
|
||
12 years ago
|
module.exports = function(ast) {
|
||
13 years ago
|
function nop() {}
|
||
|
|
||
|
function checkExpression(node) { check(node.expression); }
|
||
|
|
||
|
function checkSubnodes(propertyName) {
|
||
12 years ago
|
return function(node) { utils.each(node[propertyName], check); };
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
var check = utils.buildNodeVisitor({
|
||
13 years ago
|
grammar: checkSubnodes("rules"),
|
||
|
rule: checkExpression,
|
||
13 years ago
|
named: checkExpression,
|
||
13 years ago
|
choice: checkSubnodes("alternatives"),
|
||
13 years ago
|
action: checkExpression,
|
||
13 years ago
|
sequence: checkSubnodes("elements"),
|
||
|
labeled: checkExpression,
|
||
|
simple_and: checkExpression,
|
||
|
simple_not: checkExpression,
|
||
|
semantic_and: nop,
|
||
|
semantic_not: nop,
|
||
|
optional: checkExpression,
|
||
|
zero_or_more: checkExpression,
|
||
|
one_or_more: checkExpression,
|
||
|
|
||
|
rule_ref:
|
||
|
function(node) {
|
||
12 years ago
|
if (!utils.findRuleByName(ast, node.name)) {
|
||
13 years ago
|
throw new PEG.GrammarError(
|
||
|
"Referenced rule \"" + node.name + "\" does not exist."
|
||
|
);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
literal: nop,
|
||
13 years ago
|
"class": nop,
|
||
|
any: nop
|
||
13 years ago
|
});
|
||
|
|
||
|
check(ast);
|
||
|
};
|