Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukaslueg/railroad
A library to produce syntax diagrams as Scalable Vector Graphics
https://github.com/lukaslueg/railroad
Last synced: 5 days ago
JSON representation
A library to produce syntax diagrams as Scalable Vector Graphics
- Host: GitHub
- URL: https://github.com/lukaslueg/railroad
- Owner: lukaslueg
- License: mit
- Created: 2018-08-12T14:35:51.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-26T18:21:24.000Z (4 months ago)
- Last Synced: 2024-10-31T11:54:20.779Z (8 days ago)
- Language: Rust
- Size: 642 KB
- Stars: 140
- Watchers: 6
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - lukaslueg/railroad - A library to produce syntax diagrams as Scalable Vector Graphics (others)
README
### A library to create syntax ("railroad") diagrams as Scalable Vector Graphics (SVG).
[![Build status](https://github.com/lukaslueg/railroad/actions/workflows/check.yml/badge.svg)](https://github.com/lukaslueg/railroad/actions/workflows/check.yml)
[![Crates.io Version](https://img.shields.io/crates/v/railroad.svg)](https://crates.io/crates/railroad)
[![Docs](https://docs.rs/railroad/badge.svg)](https://docs.rs/railroad)**[Live demo](https://lukaslueg.github.io/macro_railroad_wasm_demo/)** ([code](https://github.com/lukaslueg/macro_railroad_wasm))
**[Some examples](https://htmlpreview.github.io/?https://github.com/lukaslueg/railroad_dsl/blob/master/examples/example_diagrams.html)** using a small [DSL of it's own](https://github.com/lukaslueg/railroad_dsl).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 `Node`. Primitives are combined into more complex structures by wrapping simple elements into more complex ones.
```rust
use railroad::*;let mut seq = Sequence::default();
seq.push(Box::new(Start) as Box)
.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 create table sql syntax](https://raw.githubusercontent.com/lukaslueg/railroad/master/examples/create_table_stmt.jpeg)
When adding new `Node`-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.