Expand description
A library to create syntax (“railroad”) diagrams as Scalable Vector Graphics (SVG).
Railroad diagrams are a graphical way to represent context-free grammar. Every diagram has exactly one starting- and one end-point; everything that belongs to the described language is represented by one of the possible paths between those points.
Using this library, diagrams are created by primitives which implemented RailroadNode
.
Primitives are combined into more complex strctures by wrapping simple elements into more
complex ones.
use railroad::*;
// This diagram will be a (horizontal) sequence of simple elements
let mut seq = Sequence::default();
seq.push(Box::new(Start))
.push(Box::new(Terminal::new("BEGIN".to_owned())))
.push(Box::new(NonTerminal::new("syntax".to_owned())))
.push(Box::new(End));
let mut dia = Diagram::new(seq);
// The library only computes the diagram's geometry; we use CSS for layout.
dia.add_element(svg::Element::new("style")
.set("type", "text/css")
.raw_text(DEFAULT_CSS));
// A `RailroadNode`'s `fmt::Display` is it's SVG.
println!("<html>{}</html>", dia);
Re-exports
pub use notactuallysvg as svg;
Modules
Structs
A container of elements, drawn vertically, where exactly one element has to be picked
A label / verbatim text, drawn in-line
A dummy-element which has no size and draws nothing.
A symbol indicating the logical end of a syntax-diagram via two vertical bars.
A horizontal group of unconnected elements.
A box drawn around the given element and a label placed inside the box, above the element.
Wraps another primitive, making it a clickable link to some URI.
A
NonTerminal
, drawn as a rectangle.Wraps another element to make that element logically optional.
Wraps one element by providing a backwards-path through another element.
A horizontal group of elements, connected from left to right.
A symbol indicating the logical end of a syntax-diagram via a circle
A symbol indicating the logical start of a syntax-diagram via a circle
A vertical group of elements, drawn from top to bottom.
A symbol indicating the logical start of a syntax-diagram via two vertical bars.
A
Terminal
-symbol, drawn as a rectangle with rounded corners.A vertical group of unconnected elements.
Constants
Traits
A diagram is built from a set of primitives which implement
RailroadNode
.