Lezer loader module for webpack.
No options are supported yet.
@external
imports in the grammar file do not get marked as webpack dependencies. If you need to re-build your grammar file based on the imports, just edit your grammar file to trigger the webpack re-build.
Usage, in webpack.config.js
:
{
// ...
module: {
rules: [
{
test: /\.grammar$/,
use: "lezer-loader",
},
];
}
// ...
}
Usage, in your JavaScript files (supposing the file is named syntax.grammar
):
// editor.js
import parser from "./syntax.grammar";
For TypeScript declarations:
// syntax.grammar.d.ts
import { LRParser } from "@lezer/lr";
declare const parser: LRParser;
export default parser;
To reference external tokens, they have to first be defined in your grammar file:
// syntax.grammar
@external tokens insertSemicolon from "./tokens" { insertSemi }
Then to import them:
// tokens.js
import { insertSemi } from "./syntax.grammar";
For TypeScript declarations:
export const insertSemi: number;