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 Node
.
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<Box<dyn Node>> = 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));
// The library only computes the diagram's geometry; we use CSS for layout.
let mut dia = Diagram::new_with_stylesheet(seq, &Stylesheet::Light);
// A `Node`'s `fmt::Display` is its SVG.
println!("<html>{}</html>", dia);
Re-exports§
pub use crate::notactuallysvg as svg;
pub use resvg;
Modules§
- A shorthand for rendering diagrams to images, using
resvg
’s default options.
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.
Enums§
- Possible targets for
Link
. - Pre-defined stylesheets
Constants§
- Default Cascading Style Sheets for the resuling SVG.
Traits§
- A diagram is built from a set of primitives which implement
Node
. - Helper trait for collections of nodes.