Skip to content

jared-hughes/lezer-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published