2015-06-08 20:21:19 +02:00
|
|
|
"use strict";
|
|
|
|
|
2016-09-17 15:08:47 +02:00
|
|
|
let GrammarError = require("../../grammar-error");
|
2016-09-22 09:25:31 +02:00
|
|
|
let asts = require("../asts");
|
|
|
|
let visitor = require("../visitor");
|
2012-11-10 09:47:22 +01:00
|
|
|
|
2016-09-17 16:28:28 +02:00
|
|
|
// Checks that all referenced rules exist.
|
2016-07-29 15:16:56 +02:00
|
|
|
function reportUndefinedRules(ast) {
|
2016-09-08 16:04:36 +02:00
|
|
|
let check = visitor.build({
|
2016-10-07 17:03:10 +02:00
|
|
|
rule_ref(node) {
|
2014-06-04 07:23:34 +02:00
|
|
|
if (!asts.findRule(ast, node.name)) {
|
|
|
|
throw new GrammarError(
|
2016-07-03 17:43:56 +02:00
|
|
|
"Rule \"" + node.name + "\" is not defined.",
|
2015-04-06 10:34:07 +02:00
|
|
|
node.location
|
2014-06-04 07:23:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 14:23:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
check(ast);
|
2014-05-04 14:11:44 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 15:16:56 +02:00
|
|
|
module.exports = reportUndefinedRules;
|