pegjs/lib/compiler/passes/report-missing-rules.js
David Majda 898a7b5a2d Simplify visitors by providing default visit functions
The |visitor.build| function now supplies default visit functions for
visitors it builds. These functions don't do anything beside traversing
the tree and passing arguments around to child visit functions.

Having the default visit functions allowed to simplify several visitors.
2014-06-04 07:41:00 +02:00

21 lines
503 B
JavaScript

var GrammarError = require("../../grammar-error"),
asts = require("../asts"),
visitor = require("../visitor");
/* Checks that all referenced rules exist. */
function reportMissingRules(ast) {
var check = visitor.build({
rule_ref: function(node) {
if (!asts.findRule(ast, node.name)) {
throw new GrammarError(
"Referenced rule \"" + node.name + "\" does not exist."
);
}
}
});
check(ast);
}
module.exports = reportMissingRules;