Registry / serialization / lezer-loader

lezer-loader

JSON →
library0.3.0jsnpmunverified

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.

npm install lezer-loader
INSTALL
IMPORT
SIG · LEZER-LOADER
L
lezer-loader
serializationjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (parser)
import parser from './syntax.grammar'
const parser = require('./syntax.grammar')
Default export is the LRParser instance. Use ESM syntax for webpack.
named (external tokens)
import { insertSemi } from './syntax.grammar'
Named exports only exist for external tokens defined in the grammar with @external tokens.
type (TypeScript)
import type { LRParser } from '@lezer/lr'
import { LRParser } from '@lezer/lr'
Use type-only imports for TypeScript declarations to avoid runtime overhead.

Configures webpack to handle .grammar files with lezer-loader, enabling import of Lezer parsers.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.grammar$/, use: 'lezer-loader', }, ], }, };
Debug
Known issues
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.
affects: >=0.0.0
breakingNo 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.
affects: ==0.3.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) in file.grammar
Webpack is not configured to handle .grammar files with lezer-loader.
fix
Add rule { test: /\.grammar$/, use: 'lezer-loader' } to webpack config.
Cannot find module './tokens' from 'syntax.grammar'
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.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
@lezer/generatoroptionalPeer dependency required for grammar generation
Agent activity
4 hits · last 30 days
node
4
Resources
lezer-loader — npm install lezer-loader · libregistry