37 lines
1.1 KiB
Markdown
37 lines
1.1 KiB
Markdown
---
|
|
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/
|