lex-parser
raw JSON → 0.1.4 verified Sat Apr 25 auth: no javascript maintenance
A parser for lexical grammars used by jison and jison-lex. Currently at version 0.1.4, it parses lexical grammar definitions (similar to those used by Lex/Yacc) and returns a JSON representation. It is a low-level dependency for jison tools and not commonly used directly. The package appears to be stable but rarely updated, with the last release likely years ago. Unlike higher-level alternatives like jison itself, lex-parser focuses solely on parsing the grammar syntax.
Common errors
error lexParser.parse is not a function ↓
cause Incorrect import: using import or require improperly. For example, importing as default but using .parse as if it were a method on an object.
fix
Use either: const result = lexParser.parse('%%...'); if lexParser is the default import (CommonJS), or const { parse } = require('lex-parser'); result = parse('%%...');
error Cannot find module 'lex-parser' ↓
cause Package not installed.
fix
Install via npm: npm install lex-parser
Warnings
gotcha Package uses CommonJS module format by default; ESM may require additional configuration. ↓
fix Use dynamic import or configure bundler for CommonJS compatibility.
deprecated Package is rarely updated; consider using jison-lex directly for grammar parsing inside jison workflows. ↓
fix Instead of using lex-parser directly, rely on jison or jison-lex which include it as a dependency.
gotcha The parse function expects a complete grammar string with '%%' separator between rules and code; missing it results in invalid output. ↓
fix Ensure grammar string includes '%%' to separate the rules section from optional trailing code.
Install
npm install lex-parser yarn add lex-parser pnpm add lex-parser Imports
- default (parse function) wrong
const lexParser = require('lex-parser'); // Works for CJS but not ESMcorrectimport lexParser from 'lex-parser'; const result = lexParser.parse('%%...'); - parse function (named) wrong
import { lexParser } from 'lex-parser'; // Wrong symbol; named export is 'parse', not 'lexParser'.correctimport { parse } from 'lex-parser'; const result = parse('%%...');
Quickstart
import lexParser from 'lex-parser';
const grammar = `
NAME [a-zA-Z_][a-zA-Z0-9_-]*
%%
{NAME} return 'NAME';
`;
const parsed = lexParser.parse(grammar);
console.log(JSON.stringify(parsed, null, 2));