{"id":18497,"library":"lex-parser","title":"lex-parser","description":"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.","status":"maintenance","version":"0.1.4","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","lexical","grammar","parser","jison"],"install":[{"cmd":"npm install lex-parser","lang":"bash","label":"npm"},{"cmd":"yarn add lex-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add lex-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exposes a single parse function as default export. In CommonJS environments, require is acceptable; for ESM, use import.","wrong":"const lexParser = require('lex-parser'); // Works for CJS but not ESM","symbol":"default (parse function)","correct":"import lexParser from 'lex-parser'; const result = lexParser.parse('%%...');"},{"note":"The named export 'parse' is available. Avoid confusing with the package name.","wrong":"import { lexParser } from 'lex-parser'; // Wrong symbol; named export is 'parse', not 'lexParser'.","symbol":"parse function (named)","correct":"import { parse } from 'lex-parser'; const result = parse('%%...');"}],"quickstart":{"code":"import lexParser from 'lex-parser';\n\nconst grammar = `\nNAME [a-zA-Z_][a-zA-Z0-9_-]*\n%%\n{NAME} return 'NAME';\n`;\n\nconst parsed = lexParser.parse(grammar);\nconsole.log(JSON.stringify(parsed, null, 2));","lang":"javascript","description":"Shows how to install, import, and use lexParser.parse() to parse a simple lexical grammar and output JSON."},"warnings":[{"fix":"Use dynamic import or configure bundler for CommonJS compatibility.","message":"Package uses CommonJS module format by default; ESM may require additional configuration.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Instead of using lex-parser directly, rely on jison or jison-lex which include it as a dependency.","message":"Package is rarely updated; consider using jison-lex directly for grammar parsing inside jison workflows.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Ensure grammar string includes '%%' to separate the rules section from optional trailing code.","message":"The parse function expects a complete grammar string with '%%' separator between rules and code; missing it results in invalid output.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use either: const result = lexParser.parse('%%...'); if lexParser is the default import (CommonJS), or const { parse } = require('lex-parser'); result = parse('%%...');","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.","error":"lexParser.parse is not a function"},{"fix":"Install via npm: npm install lex-parser","cause":"Package not installed.","error":"Cannot find module 'lex-parser'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}