Webpack loader for Lezer grammar files.
To begin, you'll need to install lezer-webpack-loader
:
npm install --save-dev lezer-webpack-loader
Then add the plugin to your webpack config. For example:
file.js
import { parser } from "example.grammar";
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.grammar$/i,
use: "lezer-webpack-plugin",
},
],
},
};
And run webpack
via your preferred method.
This way you can import the parser and the tokens directly from the grammar file.
warn
includeNames
moduleStyle
exportName
externalTokenizer
externalPropSource
externalSpecializer
externalProp
contextTracker
Type:
type warn = (message: string) => void;
Default: console.warn
A function that should be called with warnings.
Type:
type includeNames = boolean;
Default: false
Whether to include term names in the output file.
Type:
type moduleStyle = string;
Default: "es"
Determines the module system used by the output file. Can be either "cjs" (CommonJS) or "es" (ES2015 module).
Type:
type exportName = string;
Default: "parser"
The name of the export that holds the parser in the output file.
Type:
import { ExternalTokenizer } from "@lezer/lr";
type externalTokenizer = (
name: string,
terms: Object<number>
) => ExternalTokenizer;
Default: undefined
When calling buildParser
, this can be used to provide placeholders for external tokenizers.
Type:
import { NodePropSource } from "@lezer/common";
type externalPropSource = (name: string) => NodePropSource;
Default: undefined
Used by buildParser
to resolve external prop sources.
Type:
import { Stack } from "@lezer/lr";
type externalPropSource = (
name: string,
terms: Object<number>
) => (value: string, stack: Stack) => number;
Default: undefined
Provide placeholders for external specializers when using buildParser
.
Type:
import { NodeProp } from "@lezer/common";
type externalProp = (name: string) => NodeProp<any>;
Default: undefined
If given, will be used to initialize external props in the parser returned by buildParser
.
Type:
import { ContextTracker } from "@lezer/lr";
type contextTracker = ContextTracker<any>;
Default: undefined
If given, will be used as context tracker in a parser built with buildParser
.
This project is licensed under the GPLv3 License - see the LICENSE file for details.