pegjs/lib/compiler/passes/report-undefined-rules.js

36 lines
662 B
JavaScript
Raw Normal View History

"use strict";
2016-09-17 16:28:28 +02:00
// Checks that all referenced rules exist.
2018-01-30 03:38:49 +01:00
function reportUndefinedRules( ast, session, options ) {
2018-01-30 03:38:49 +01:00
const check = session.buildVisitor( {
rule_ref( node ) {
2018-01-26 08:49:34 +01:00
if ( ! ast.findRule( node.name ) ) {
2018-02-02 05:32:39 +01:00
session.error(
`Rule "${ node.name }" is not defined.`,
node.location
);
}
}
} );
check( ast );
options.allowedStartRules.forEach( rule => {
2018-01-26 08:49:34 +01:00
if ( ! ast.findRule( rule ) ) {
2018-02-02 05:32:39 +01:00
session.error( `Start rule "${ rule }" is not defined.` );
}
} );
}
module.exports = reportUndefinedRules;