lezer-webpack-loader v1.0.0
lezer-webpack-loader
Webpack loader for Lezer grammar files.
Getting started
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.
Options
warn
includeNames
moduleStyle
exportName
externalTokenizer
externalPropSource
externalSpecializer
externalProp
contextTracker
warn
Type:
type warn = (message: string) => void;
Default: console.warn
A function that should be called with warnings.
includeNames
Type:
type includeNames = boolean;
Default: false
Whether to include term names in the output file.
moduleStyle
Type:
type moduleStyle = string;
Default: "es"
Determines the module system used by the output file. Can be either "cjs" (CommonJS) or "es" (ES2015 module).
exportName
Type:
type exportName = string;
Default: "parser"
The name of the export that holds the parser in the output file.
externalTokenizer
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.
externalPropSource
Type:
import { NodePropSource } from "@lezer/common";
type externalPropSource = (name: string) => NodePropSource;
Default: undefined
Used by buildParser
to resolve external prop sources.
externalSpecializer
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
.
externalProp
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
.
contextTracker
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
.
License
This project is licensed under the GPLv3 License - see the LICENSE file for details.
10 months ago