[][src]Crate railroad

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 its SVG.
println!("<html>{}</html>", dia);

Re-exports

pub use notactuallysvg as svg;

Modules

notactuallysvg

Structs

Choice

A container of elements, drawn vertically, where exactly one element has to be picked

Comment

A label / verbatim text, drawn in-line

Diagram
Empty

A dummy-element which has no size and draws nothing.

End

A symbol indicating the logical end of a syntax-diagram via two vertical bars.

HorizontalGrid

A horizontal group of unconnected elements.

LabeledBox

A box drawn around the given element and a label placed inside the box, above the element.

Link

Wraps another primitive, making it a clickable link to some URI.

NonTerminal

A NonTerminal, drawn as a rectangle.

Optional

Wraps another element to make that element logically optional.

Repeat

Wraps one element by providing a backwards-path through another element.

Sequence

A horizontal group of elements, connected from left to right.

SimpleEnd

A symbol indicating the logical end of a syntax-diagram via a circle

SimpleStart

A symbol indicating the logical start of a syntax-diagram via a circle

Stack

A vertical group of elements, drawn from top to bottom.

Start

A symbol indicating the logical start of a syntax-diagram via two vertical bars.

Terminal

A Terminal-symbol, drawn as a rectangle with rounded corners.

VerticalGrid

A vertical group of unconnected elements.

Enums

LinkTarget

Constants

DEFAULT_CSS

Traits

RailroadNode

A diagram is built from a set of primitives which implement RailroadNode.