{"id":25005,"library":"bnf","title":"nodebnf","description":"BNF is a JavaScript library for compiling, parsing, and interpreting BNF and ABNF grammars. Version 1.0.1 uses ECMAScript 6+ and supports inline compilation of grammars, predefined rules (e.g., DIGIT, CRLF, LITERAL), rule events, and multi-language scripts (planned). It runs on Node.js. Unlike other parser generators (e.g., PEG.js, ANTLR), BNF focuses on simplicity and direct embedding of BNF/ABNF syntax without a separate generation step. The library is in early development, with custom rule APIs subject to change.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/navstev0/nodebnf","tags":["javascript","parser","interpreter","compiler","bnf","lexical"],"install":[{"cmd":"npm install bnf","lang":"bash","label":"npm"},{"cmd":"yarn add bnf","lang":"bash","label":"yarn"},{"cmd":"pnpm add bnf","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import path is 'bnf'. The package may also support CommonJS require, but ESM is preferred for v1.","wrong":"const Compiler = require('bnf').Compiler","symbol":"Compiler","correct":"import { Compiler } from 'bnf'"},{"note":"BNF is a named export. Do not default-import.","wrong":"const bnf = require('bnf')","symbol":"BNF","correct":"import { BNF } from 'bnf'"},{"note":"ABNF is a named export, not default.","wrong":"import ABNF from 'bnf'","symbol":"ABNF","correct":"import { ABNF } from 'bnf'"}],"quickstart":{"code":"import { Compiler } from 'bnf';\n\nconst compiler = new Compiler();\ncompiler.AddLanguage(`\n  <SYNTAX> ::= <evaluation> | <evaluation> <CRLF> <SYNTAX>\n  <evaluation> ::= <number> <OWSP> <type> <OWSP> <number>\n  <number> ::= <DIGITS>\n  <type> ::= \"+\" | \"-\" | \"/\" | \"*\"\n`, \"testLang\");\ncompiler.SetRuleEvents({\n  evaluation(token) {\n    console.log(\"evaluation token found answer:\", eval(token.value));\n  }\n});\ncompiler.ParseScript(`\n5456 / 13\n11 + 3\n10 * 8\n`.trim());","lang":"javascript","description":"Creates a compiler, adds a calculator grammar, sets rule events, and parses expressions."},"warnings":[{"fix":"Avoid writing custom rules until v2 stabilizes, or pin to a specific minor version.","message":"Custom BNF rules API is unstable and will change during minor version updates.","severity":"breaking","affected_versions":"~1.0.0"},{"fix":"Migrate to inline compiling with AddLanguage and ParseScript.","message":"The prior version used a custom JavaScript markup for script files; this feature is removed in v1.","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Use exactly the documented casing: AddLanguage, SetRuleEvents, ParseScript.","message":"Method names are PascalCase (e.g., AddLanguage, ParseScript) unlike typical JavaScript camelCase.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always include a rule named SYNTAX as the entry point.","message":"The predefined rule SYNTAX must be declared in every grammar; missing it causes parse failure.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import { Compiler } from 'bnf';` and instantiate with `new Compiler()`.","cause":"Importing the library incorrectly (e.g., default import or wrong path).","error":"TypeError: compiler.AddLanguage is not a function"},{"fix":"Ensure AddLanguage is called with a valid grammar before parsing.","cause":"Calling ParseScript before AddLanguage.","error":"Error: No language registered"},{"fix":"Validate grammar using BNF syntax: `<rule> ::= <expression> | \"literal\"` or ABNF: `rule = expression / \"literal\"`.","cause":"Invalid BNF/ABNF syntax (e.g., missing angle brackets or incorrect repeat notation).","error":"SyntaxError: Unexpected token"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}