pegjs/lib/compiler/passes/report-undefined-rules.js
2016-10-10 10:58:05 +02:00

24 lines
510 B
JavaScript

"use strict";
let GrammarError = require("../../grammar-error");
let asts = require("../asts");
let visitor = require("../visitor");
// Checks that all referenced rules exist.
function reportUndefinedRules(ast) {
let check = visitor.build({
rule_ref(node) {
if (!asts.findRule(ast, node.name)) {
throw new GrammarError(
"Rule \"" + node.name + "\" is not defined.",
node.location
);
}
}
});
check(ast);
}
module.exports = reportUndefinedRules;