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. 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

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