Skip to the content.

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. Grammar-level directives%extras, %conflicts, %inline, %supertypes, %axiom, %include
  4. BNF → tree-sitter cheat sheet — every mapping on one page
  5. End-to-end: from .bnf to a working parserconvert and highlights
  6. Analysing a grammarcheck, --summary, firsts
  7. Formatting and refactoringformat, rename
  8. Visualising a grammarrailroad, graph

Guides

The BNF dialect’s own grammar

The dialect is self-described in grammar/bnf.bnf, and its diagrams are generated by the tool itself:

Project