You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.1 KiB
1.1 KiB
Plugins
You can use plugins by simply passing them to the generate method (e.g. peg.generate(grammar, { plugins: [plugin1, plugin2, etc] })
).
Creating a Plugin
Plugins are expected to be an object that contains at least one method: use( session, options )
session
- See the docs for peg.compiler.Sessionoptions
- see the docs forpeg.generate
andpeg.compiler.compile
Here is a simple example:
import customGrammarParser from "./parser";
export function use( session, options ) {
// Replace the grammar parser
session.parser = customGrammarParser;
// always output the source
options.output = "source";
}
Resources
You can find some plugins to use on
- the PEG.js wiki (or add yours to the list for other's to find)
- NPM: https://www.npmjs.com/browse/keyword/pegjs