You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
553 B
JavaScript
27 lines
553 B
JavaScript
8 years ago
|
"use strict";
|
||
|
|
||
|
var GrammarError = require("../../grammar-error"),
|
||
|
visitor = require("../visitor");
|
||
|
|
||
|
/* Checks that each rule is defined only once. */
|
||
|
function reportDuplicateRules(ast) {
|
||
|
var rules = {};
|
||
|
|
||
|
var check = visitor.build({
|
||
|
rule: function(node) {
|
||
|
if (rules.hasOwnProperty(node.name)) {
|
||
|
throw new GrammarError(
|
||
|
"Rule \"" + node.name + "\" is already defined.",
|
||
|
node.location
|
||
|
);
|
||
|
}
|
||
|
|
||
|
rules[node.name] = true;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
check(ast);
|
||
|
}
|
||
|
|
||
|
module.exports = reportDuplicateRules;
|