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

  1. Getting started — the problem, the solution, installing, and a complete first example
  2. Syntax walkthrough — every construct of the BNF dialect, and what is not supported
  3. Tree-sitter concepts — LR parsing, conflicts, precedence, keyword extraction, external scanners, supertypes, extras
  4. Grammar-level directives%extras, %conflicts, %inline, %supertypes, %axiom, %include
  5. BNF → tree-sitter cheat sheet — every mapping on one page
  6. End-to-end: from .bnf to a working parserconvert and highlights
  7. Worked example: a boolean/arithmetic expression language — operator precedence, %prec, and keyword extraction in a realistic grammar
  8. Analysing a grammarcheck, --summary, firsts
  9. Formatting and refactoringformat, rename
  10. Visualising a grammarrailroad, graph
  11. Generating a processing scaffoldscaffold, step by step
  12. Scaffold reference — generated files, flags, the Visitor trait, --ast-types, --merge-config

Guides

  • Editor setup — syntax highlighting for .bnf files 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:

Project


This site uses Just the Docs, a documentation theme for Jekyll.