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.
npm install bnfNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a compiler, adds a calculator grammar, sets rule events, and parses expressions.
Avoid writing custom rules until v2 stabilizes, or pin to a specific minor version.
Migrate to inline compiling with AddLanguage and ParseScript.
Use exactly the documented casing: AddLanguage, SetRuleEvents, ParseScript.
Always include a rule named SYNTAX as the entry point.
Use `import { Compiler } from 'bnf';` and instantiate with `new Compiler()`.Ensure AddLanguage is called with a valid grammar before parsing.
Validate grammar using BNF syntax: `<rule> ::= <expression> | "literal"` or ABNF: `rule = expression / "literal"`.
No dependency data recorded yet.