|
|
|
@ -5,7 +5,7 @@ let asts = require("../asts");
|
|
|
|
|
let visitor = require("../visitor");
|
|
|
|
|
|
|
|
|
|
// Checks that all referenced rules exist.
|
|
|
|
|
function reportUndefinedRules(ast) {
|
|
|
|
|
function reportUndefinedRules(ast, options) {
|
|
|
|
|
let check = visitor.build({
|
|
|
|
|
rule_ref(node) {
|
|
|
|
|
if (!asts.findRule(ast, node.name)) {
|
|
|
|
@ -18,6 +18,15 @@ function reportUndefinedRules(ast) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
check(ast);
|
|
|
|
|
|
|
|
|
|
if (options.allowedStartRules) {
|
|
|
|
|
options.allowedStartRules.forEach(rule => {
|
|
|
|
|
if (!asts.findRule(ast, rule)) {
|
|
|
|
|
throw new GrammarError(
|
|
|
|
|
"Start rule \"" + rule + "\" is not defined.");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = reportUndefinedRules;
|
|
|
|
|