0.3.0 • Published 2 years ago

lezer-loader v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

lezer-loader

Lezer loader module for webpack.

Limitations

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.

Basic Usage

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;

External Token Usage

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;