bdf91b5941
This is purely a mechanical change, not taking advantage of block scope of "let" and "const". Minimizing variable scope will come in the next commit. In general, "var" is converted into "let" and "const" is used only for immutable variables of permanent character (generally spelled in ALL_CAPS). Using it for any immutable variable regardless on its permanence would feel confusing. Any code which is not transpiled and needs to run in ES6 environment (examples, code in grammars embedded in specs, ...) is kept unchanged. This is also true for code generated by PEG.js. See #442.
29 lines
686 B
JavaScript
29 lines
686 B
JavaScript
"use strict";
|
|
|
|
let GrammarError = require("../../grammar-error"),
|
|
visitor = require("../visitor");
|
|
|
|
/* Checks that each rule is defined only once. */
|
|
function reportDuplicateRules(ast) {
|
|
let rules = {};
|
|
|
|
let check = visitor.build({
|
|
rule: function(node) {
|
|
if (rules.hasOwnProperty(node.name)) {
|
|
throw new GrammarError(
|
|
"Rule \"" + node.name + "\" is already defined "
|
|
+ "at line " + rules[node.name].start.line + ", "
|
|
+ "column " + rules[node.name].start.column + ".",
|
|
node.location
|
|
);
|
|
}
|
|
|
|
rules[node.name] = node.location;
|
|
}
|
|
});
|
|
|
|
check(ast);
|
|
}
|
|
|
|
module.exports = reportDuplicateRules;
|