29 lines
699 B
JavaScript
29 lines
699 B
JavaScript
|
// 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;
|