lezer-loader
raw JSON → 0.3.0 verified Sat Apr 25 auth: no javascript
A webpack loader for Lezer grammar files (.grammar). Currently at version 0.3.0 with a stable API. It enables importing .grammar files as parser modules, supporting external token imports. No configuration options are supported yet. @external imports in grammar files are not tracked as webpack dependencies, requiring manual rebuild triggers. Best paired with @lezer/generator and @lezer/lr for TypeScript usage.
Common errors
error Module parse failed: Unexpected token (1:0) in file.grammar ↓
cause Webpack is not configured to handle .grammar files with lezer-loader.
fix
Add rule { test: /\.grammar$/, use: 'lezer-loader' } to webpack config.
error Cannot find module './tokens' from 'syntax.grammar' ↓
cause External token import path is incorrect or tokens.js is not in webpack's resolution scope.
fix
Ensure the @external tokens import path in the grammar file is correct and the module is accessible.
Warnings
gotcha @external imports in grammar files are not tracked as webpack dependencies. Edit the grammar file to trigger a rebuild. ↓
fix Manually edit the .grammar file (e.g., add a comment or change whitespace) to force webpack to recompile.
breaking No options are supported yet. Attempting to pass options to the loader may break silently. ↓
fix Do not pass any options to the loader in webpack config.
Install
npm install lezer-loader yarn add lezer-loader pnpm add lezer-loader Imports
- default (parser) wrong
const parser = require('./syntax.grammar')correctimport parser from './syntax.grammar' - named (external tokens)
import { insertSemi } from './syntax.grammar' - type (TypeScript) wrong
import { LRParser } from '@lezer/lr'correctimport type { LRParser } from '@lezer/lr'
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.grammar$/,
use: 'lezer-loader',
},
],
},
};