2015-06-08 20:21:19 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-25 20:19:42 +02:00
|
|
|
const GrammarError = require( "../../grammar-error" );
|
2012-11-10 09:47:22 +01:00
|
|
|
|
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 ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2018-01-30 03:38:49 +01:00
|
|
|
const check = session.buildVisitor( {
|
2017-10-25 20:19:42 +02:00
|
|
|
rule_ref( node ) {
|
|
|
|
|
2018-01-26 08:49:34 +01:00
|
|
|
if ( ! ast.findRule( node.name ) ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
|
|
|
throw new GrammarError(
|
|
|
|
`Rule "${ node.name }" is not defined.`,
|
|
|
|
node.location
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
check( ast );
|
|
|
|
|
2017-10-28 12:57:54 +02:00
|
|
|
options.allowedStartRules.forEach( rule => {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2018-01-26 08:49:34 +01:00
|
|
|
if ( ! ast.findRule( rule ) ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2017-10-28 12:57:54 +02:00
|
|
|
throw new GrammarError( `Start rule "${ rule }" is not defined.` );
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2017-10-28 12:57:54 +02:00
|
|
|
}
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2017-10-28 12:57:54 +02:00
|
|
|
} );
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2014-05-04 14:11:44 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 15:16:56 +02:00
|
|
|
module.exports = reportUndefinedRules;
|