A library to produce syntax diagrams as Scalable Vector Graphics
Clone or download
Latest commit 9c4fe09 Dec 30, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Rustfmt Dec 30, 2018
src Rustfmt Dec 30, 2018
tests Use Rust2018 idioms Dec 30, 2018
.gitignore Init Aug 12, 2018
.travis.yml Rustfmt Dec 24, 2018
Cargo.toml Rust 2018 Dec 24, 2018
LICENSE Add license-file Aug 15, 2018
README.md Update README.md Nov 1, 2018

README.md

A library to create syntax ("railroad") diagrams as Scalable Vector Graphics (SVG).

Build Status Crates.io Version Docs

Live demo (code) Some examples using a small DSL of it's own.

Railroad diagrams are a way to represent context-free grammar. Every diagram has exactly one starting- and 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 using primitives which implement RailroadNode. Primitives are combined into more complex structures by wrapping simple elements into more complex ones.

use railroad::*;

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);

dia.add_element(svg::Element::new("style")
                .set("type", "text/css")
                .text(DEFAULT_CSS));

println!("{}", dia);

diagram for constraint syntax

When adding new RailroadNode-primitives to this library, you may find examples/visual.rs come in handy to quickly generate special-cases and check if they render properly. Use the visual-debug feature to add guide-lines to the rendered diagram and extra information to the SVG's code.