rittenhop-dev/versions/5.94.2/node_modules/nearley/lib/lint.js

29 lines
699 B
JavaScript
Raw Normal View History

2024-09-23 19:40:12 -04:00
// Node-only
var warn = function (opts, str) {
opts.out.write("WARN"+"\t" + str + "\n");
}
function lintNames(grm, opts) {
var all = [];
grm.rules.forEach(function(rule) {
all.push(rule.name);
});
grm.rules.forEach(function(rule) {
rule.symbols.forEach(function(symbol) {
if (!symbol.literal && !symbol.token && symbol.constructor !== RegExp) {
if (all.indexOf(symbol) === -1) {
warn(opts,"Undefined symbol `" + symbol + "` used.");
}
}
});
});
}
function lint(grm, opts) {
if (!opts.out) opts.out = process.stderr;
lintNames(grm, opts);
}
module.exports = lint;