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.
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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);
}
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.