百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

railroad

> 编程语言
开源

一个用于生成语法图的可扩展向量图形库

181 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

一个用于生成语法图的可扩展向量图形库

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

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 Node. Primitives are combined into more complex structures by wrapping simple elements into more complex ones. The public API stays flat at the crate root, so built-in nodes such as Sequence, Choice, Terminal, Optional, and Diagram are all available directly from railroad::*.

rust
use railroad::*;

let mut seq: Sequence> = 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 dia = Diagram::new_with_stylesheet(seq, &Stylesheet::Light);
println!("{}", dia);

Implementing Node

For simple custom nodes, implementing entry_height(), height(), width(), and draw() is often enough. A custom node must only draw within the geometry it advertises, and its connecting path must stay at y + entry_height(). Composite or performance-sensitive nodes should usually override compute_geometry() and the geometry-aware draw/render hooks so child geometry is computed once and reused.

The lower-level SVG helpers are available as railroad::svg. Downstream crates can use them to build custom Node implementations while still exposing their nodes through the regular railroad API.

When adding new Node primitives to this library, examples/visuals.rs is a useful manual harness for generating edge cases and checking layout. Use the visual-debug feature to add guide lines to the rendered diagram and extra metadata to the SVG output.

See https://docs.rs for more information.


Themes

This library comes with a set of pre-defined themes. Existing themes can be modified and custom themes can be created using CSS.

Default light

Default dark

Rust

Coal

Navy

Ayu

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言