This plugin provides a <$railroad>
widget for generating railroad diagrams as SVG images.
Alternatively, the diagram notation can be stored in a dedicated tiddler with its type
field set to text/vnd.tiddlywiki.railroad
, and that tiddler can simply be transcluded to wherever it is needed.
The plugin is based on a library by Tab Atkins, and has been extended to make it more flexible, including allowing components of a diagram to function as links or be transcluded from other tiddlers.
The railroad widget uses a special notation to construct the components defined below.
x
and y
here stand for any component.
Names (as opposed to quoted strings) are available when a value starts with a letter and contains only letters, digits, underscores, dots and hyphens.
- sequence
- A sequence of components
- The
<-
and->
delimiters allow you to force a single component to be treated as a sequence. This is occasionally useful for spacing a diagram out
- optional
- A component that can be omitted
- The colon makes
x
appear straight ahead
- repeated
- A list of one or more
x
- The
+
suffix addsy
as a separator between eachx
and the next
- optional repeated
- An optional list of
x
, i.e. a list of zero or morex
- choice
- A set of alternatives
- The colon indicates which branch appears straight ahead. By default, it's the first branch
- string / terminal
- A literal or terminal component
- This follows the normal TiddlyWiki rules for quoted strings
- nonterminal
- A nonterminal component, i.e. the name of another diagram
- comment
- A comment
- dummy
- The absence of a component
- link
- A link to the tiddler title or URI given by the string or name
- transclusion
- Treats the content of another tiddler as diagram syntax and transcludes it into the current diagram
- arrow pragma
- Controls whether repeat paths have an arrow on them
- Can be toggled on and off in mid-diagram, if desired
- debug pragma
- Causes the diagram to display its parse tree
- start/end pragma
- Controls the style of the diagram's startpoint or endpoint