pegjs/docs/guides/plugins.md
2018-03-21 02:13:47 +00:00

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 )

Here is a simple example:

import customGrammarParser from "./parser";

export function use( session, options ) {

    // Replace the grammar parser
    config.parser = customGrammarParser;

    // always output the source
    options.output = "source";

}

Resources

You can find some plugins to use on