{"id":15596,"library":"ebnf-parser","title":"EBNF Grammar Parser for Jison","description":"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.","status":"maintenance","version":"0.1.10","language":"javascript","source_language":"en","source_url":"https://github.com/zaach/ebnf-parser","tags":["javascript","bnf","ebnf","grammar","parser","jison"],"install":[{"cmd":"npm install ebnf-parser","lang":"bash","label":"npm"},{"cmd":"yarn add ebnf-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add ebnf-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. For modern ESM projects, you'll need to use a CommonJS interop wrapper or bundler configuration.","wrong":"import ebnfParser from 'ebnf-parser';","symbol":"ebnfParser","correct":"const ebnfParser = require('ebnf-parser');"},{"note":"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`.","wrong":"import { parse } from 'ebnf-parser';","symbol":"parse","correct":"const ebnfParser = require('ebnf-parser');\nebnfParser.parse(\"%start ... %\");"},{"note":"The `transform` method is a property of the default CommonJS export. It expects a JSON representation of an EBNF grammar as input.","wrong":"import { transform } from 'ebnf-parser';","symbol":"transform","correct":"const ebnfParser = require('ebnf-parser');\nebnfParser.transform({\"ebnf\": \"...\"});"}],"quickstart":{"code":"const ebnfParser = require('ebnf-parser');\n\n// Example 1: Parsing a simple EBNF string grammar\nconst grammarString = `\n%start program\n\nprogram: statement+;\nstatement: 'id' '=' expression ';';\nexpression: term ('+' term)*;\nterm: 'number' | '(' expression ')';\n`;\n\ntry {\n  const parsedGrammar = ebnfParser.parse(grammarString);\n  console.log('Parsed Grammar (string input):', JSON.stringify(parsedGrammar, null, 2));\n} catch (error) {\n  console.error('Error parsing string grammar:', error.message);\n}\n\n// Example 2: Transforming an EBNF JSON grammar (conceptual, actual JSON might vary)\nconst ebnfJson = {\n  \"ebnf\": {\n    \"program\": [\"statement+\"],\n    \"statement\": [\"'id' '=' expression ';'\"],\n    \"expression\": [\"term ('+' term)*\"],\n    \"term\": [\"'number' | '(' expression ')'\"]\n  }\n};\n\ntry {\n  const transformedGrammar = ebnfParser.transform(ebnfJson);\n  console.log('Transformed Grammar (JSON input):', JSON.stringify(transformedGrammar, null, 2));\n} catch (error) {\n  console.error('Error transforming JSON grammar:', error.message);\n}","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"The `parser.js` file, which contains the actual parsing logic and the `parse` method, has not been generated or is not accessible.","error":"TypeError: ebnfParser.parse is not a function"},{"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.","cause":"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).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}