Registry / serialization / ebnf-parser

ebnf-parser

JSON →
library0.1.10jsnpmunverified

ebnf-parser is a utility library designed to parse BNF and EBNF grammars, primarily used as a pre-processor for the Jison parser generator. It takes either a string representation of a grammar or a JSON grammar and transforms EBNF constructs into standard BNF, producing a JSON grammar format that Jison can consume. The current stable version is 0.1.10. Due to its specific role as a dependency for Jison and its low version number, its release cadence is slow and driven by Jison's needs. Key differentiators include its tight integration with Jison's grammar format and its focus solely on grammar transformation rather than full parsing engine capabilities, making it a specialized tool in the parser generator ecosystem.

npm install ebnf-parser
INSTALL
IMPORT
SIG · EBNF-PARSER
E
ebnf-parser
serializationjavascriptv0.1.10
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.

ebnfParser
const ebnfParser = require('ebnf-parser');
import ebnfParser from 'ebnf-parser';
This package is CommonJS-only. For modern ESM projects, you'll need to use a CommonJS interop wrapper or bundler configuration.
parse
const ebnfParser = require('ebnf-parser'); ebnfParser.parse("%start ... %");
import { parse } from 'ebnf-parser';
The `parse` method is a property of the default CommonJS export, not a named export. Ensure the `parser.js` file is generated by running `make`.
transform
const ebnfParser = require('ebnf-parser'); ebnfParser.transform({"ebnf": "..."});
import { transform } from 'ebnf-parser';
The `transform` method is a property of the default CommonJS export. It expects a JSON representation of an EBNF grammar as input.

This quickstart demonstrates how to use `ebnf-parser` to parse a string-based EBNF grammar and how to conceptually transform an EBNF JSON grammar into a Jison-compatible BNF JSON format.

const ebnfParser = require('ebnf-parser'); // Example 1: Parsing a simple EBNF string grammar const grammarString = ` %start program program: statement+; statement: 'id' '=' expression ';'; expression: term ('+' term)*; term: 'number' | '(' expression ')'; `; try { const parsedGrammar = ebnfParser.parse(grammarString); console.log('Parsed Grammar (string input):', JSON.stringify(parsedGrammar, null, 2)); } catch (error) { console.error('Error parsing string grammar:', error.message); } // Example 2: Transforming an EBNF JSON grammar (conceptual, actual JSON might vary) const ebnfJson = { "ebnf": { "program": ["statement+"], "statement": ["'id' '=' expression ';'"], "expression": ["term ('+' term)*"], "term": ["'number' | '(' expression ')'"] } }; try { const transformedGrammar = ebnfParser.transform(ebnfJson); console.log('Transformed Grammar (JSON input):', JSON.stringify(transformedGrammar, null, 2)); } catch (error) { console.error('Error transforming JSON grammar:', error.message); }
Debug
Known issues
gotchaThis package is CommonJS-only. Attempting to use `import` statements directly in an ESM module will result in a runtime error unless your build setup handles CommonJS interoperability.
fix
Use `const ebnfParser = require('ebnf-parser');` for CommonJS environments. For ESM, a dynamic import `import('ebnf-parser')` might work, or configure your bundler (e.g., Webpack, Rollup) to handle CommonJS modules.
affects: >=0.1.0
breakingThe parser relies on a generated `parser.js` file. If cloning from Git, you must run `make` in the package's root directory to generate this file, otherwise the package will fail to load or function correctly.
fix
After cloning the repository, navigate to the package directory and run `make`. If installing via npm, this step is typically handled by `prepare` scripts, but manual builds might require it.
affects: >=0.1.0
gotchaThe package version 0.1.10 indicates an early stage of development or maintenance mode. It might not receive frequent updates or extensive community support compared to more mature libraries.
fix
Evaluate whether its features meet your needs and consider the stability implications for long-term projects. Report issues on the GitHub repository if you encounter bugs.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: ebnfParser.parse is not a function
The `parser.js` file, which contains the actual parsing logic and the `parse` method, has not been generated or is not accessible.
fix
If installing from source (e.g., Git clone), ensure you run `make` in the package root to generate `parser.js`. If installed via npm, verify the installation integrity.
SyntaxError: Cannot use import statement outside a module
You are attempting to use `import ebnfParser from 'ebnf-parser';` in a CommonJS context (e.g., a `.js` file without `"type": "module"` in `package.json`, or an older Node.js version).
fix
Change your import statement to `const ebnfParser = require('ebnf-parser');`. Alternatively, configure your project for ESM, but note that `ebnf-parser` itself is CommonJS and will require interop.
Upgrade
Version history
0.1.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
ebnf-parser — npm install ebnf-parser · libregistry