Partially done railroad.js post

This commit is contained in:
Eryn Wells 2022-10-19 07:38:53 -07:00
parent a7ef5d696b
commit e1bf32f8e2

View file

@ -0,0 +1,37 @@
---
title: railroad.js
slug: railroad-js
date: 2022-08-20T10:45:53-07:00
draft: true
---
{{< figures/railroad id="sExpressionDiagram" >}}
return rr.Diagram(
rr.Start("simple", "s_expression"),
rr.ZeroOrMore(
rr.Choice(0,
rr.Group(rr.Sequence(
"a ... z",
rr.ZeroOrMore(rr.Choice(0, "a ... z", "1 ... 9"))
), "atom"),
rr.Sequence(
"(", rr.OneOrMore(rr.NonTerminal("s_expression")), ")"
),
rr.Sequence(
"(",
rr.NonTerminal("s_expression"),
".",
rr.NonTerminal("s_expression"),
")"
)
)
)
);
{{< /figures/railroad >}}
I just recently integrated support for Tab Atkins' excellent [`railroad.js`][rrjs].
It allows you to make diagrams like the one above. These are great for
describing modular architectures, control flow through programs or other complex
systems, and—as above—grammars.
[rrjs]: http://tabatkins.github.io/railroad-diagrams/