| 1 | "use strict"; |
| 2 | |
| 3 | var GrammarError = require("../../grammar-error"), |
| 4 | asts = require("../asts"), |
| 5 | visitor = require("../visitor"); |
| 6 | |
| 7 | /* Checks that all referenced rules exist. */ |
| 8 | function reportUndefinedRules(ast) { |
| 9 | var check = visitor.build({ |
| 10 | rule_ref: function(node) { |
| 11 | if (!asts.findRule(ast, node.name)) { |
| 12 | throw new GrammarError( |
| 13 | "Rule \"" + node.name + "\" is not defined.", |
| 14 | node.location |
| 15 | ); |
| 16 | } |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | check(ast); |
| 21 | } |
| 22 | |
| 23 | module.exports = reportUndefinedRules; |