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.

serialization
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.

This package is CommonJS-only. For modern ESM projects, you'll need to use a CommonJS interop wrapper or bundler configuration.

const ebnfParser = require('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`.

const ebnfParser = require('ebnf-parser'); ebnfParser.parse("%start ... %");

The `transform` method is a property of the default CommonJS export. It expects a JSON representation of an EBNF grammar as input.

const ebnfParser = require('ebnf-parser'); ebnfParser.transform({"ebnf": "..."});

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 footguns
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.
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.
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
17 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
claudebot
3
script
1
bingbot
1
Resources