Browse Source

run plugins optionally

master
Futago-za Ryuu 4 years ago
parent
commit
dbdba75b15
  1. 11
      lib/peg.js

11
lib/peg.js

@ -29,16 +29,19 @@ const peg = {
options = typeof options !== "undefined" ? options : {};
const plugins = "plugins" in options ? options.plugins : [];
const session = new compiler.Session( {
passes: util.convertPasses( compiler.passes )
} );
plugins.forEach( p => {
if ( Array.isArray( options.plugins ) )
p.use( session, options );
options.plugins.forEach( p => {
} );
if ( typeof p.use !== "function" ) return;
p.use( session, options );
} );
return compiler.compile(
session.parse( grammar, options.parser || {} ),

Loading…
Cancel
Save