tree-sitter-bnf-tools documentation
A tree-sitter grammar for BNF, plus ts-bnf-tool, a CLI that converts BNF grammars into tree-sitter grammar.js notation.
Tutorial
- Getting started — the problem, the solution, installing, and a complete first example
- Syntax walkthrough — every construct of the BNF dialect, and what is not supported
- Tree-sitter concepts — LR parsing, conflicts, precedence, keyword extraction, external scanners, supertypes, extras
- Grammar-level directives —
%extras,%conflicts,%inline,%supertypes,%axiom,%include - BNF → tree-sitter cheat sheet — every mapping on one page
- End-to-end: from
.bnfto a working parser —convertandhighlights - Worked example: a boolean/arithmetic expression language — operator precedence,
%prec, and keyword extraction in a realistic grammar - Analysing a grammar —
check,--summary,firsts - Formatting and refactoring —
format,rename - Visualising a grammar —
railroad,graph - Generating a processing scaffold —
scaffold, step by step - Scaffold reference — generated files, flags, the
Visitortrait,--ast-types,--merge-config
Guides
- Editor setup — syntax highlighting for
.bnffiles in Neovim, Helix, Emacs, and VS Code
The BNF dialect’s own grammar
The dialect is self-described in grammar/bnf.bnf, and its diagrams are generated by the tool itself. make bnf-self-check verifies that converting this file reproduces the same grammar as the hand-maintained tree-sitter-bnf/grammar.js, so the two can’t silently drift:
- Railroad diagram (SVG)
- Rule-dependency graph (PDF)
Project
- README — overview and quick reference
- Repository
- Issues
- Changelog