Railroad Diagrams
-r compiles a grammar into a self-contained HTML page of railroad (syntax) diagrams,
one per rule, using tabatkins/railroad-diagrams:
px -r px.px > px-grammar.html
Whitespace-only helper rules (like Px’s own s) clutter a diagram set without adding
anything worth reading — each -x rulename excludes one rule:
px -r -x s -x space -x blankline px.px > px-grammar.html
The output is a <dl> of <dt> rule names next to a <dd> containing a <script>
that draws that rule’s diagram — it needs railroad-diagrams.js and its
stylesheet loaded on the page (this site vendors a copy under assets/, from
strpp/scripts — CC0,
by Tab Atkins Jr.; the generated HTML itself expects them at a relative ../scripts/
path, which you can adjust to wherever you keep a local copy).
Live, generated straight from px.px
This is the actual output of px -r px.px for four rules — a top-level rule,
the scope_annotation it can carry, the six kinds of atom, and literal (notice the
![\'] terminal: that’s the stop-condition lookahead from
pitfalls.md, drawn
as a rail you can literally see the parser refusing to take).
rulescope_annotationatomliteral
Each diagram reads left to right along the main rail; a side loop is a repetition, a
fork is a choice, and a labelled box that links elsewhere is a call to another rule
— atom’s six side-by-side branches are the same six-way ordered choice from
The Px Language, just drawn instead of tabulated.