Syntax Diagrams

Python library for rendering syntax diagrams (a.k.a. railroad diagrams).

Features

  • Automatic line wrapping, keeping width of the diagram below limits.

  • Clever rendering of optionals, avoiding clutter where possible.

  • Automatic right-to-left rendering in one-or-more loops.

  • Producing SVGs or ASCII art.

  • Try it in your browser.

  • See also: sphinx-syntax, a Sphinx plugin for documenting grammars.

Example output

This is a part of SQLite’s grammar rendered with this library:

WITHRECURSIVEcommon-table-expression,select-coreSELECTDISTINCTALLresult-column,FROMtable-or-subquery,join-clauseWHEREexprGROUPBYexpr,HAVINGexprWINDOWwindow-nameASwindow-defn,VALUES(expr,),compound-operatorORDERBYordering-term,LIMITexprOFFSETexpr,expr

Table of contents