7 releases

0.1.6 Jul 14, 2024
0.1.5 Apr 29, 2023
0.1.4 Mar 19, 2023
0.1.3 Sep 5, 2020
0.1.0 Feb 23, 2019

#47 in Procedural macros

Download history 23/week @ 2024-04-01 47/week @ 2024-04-08 157/week @ 2024-04-15 41/week @ 2024-04-22 2/week @ 2024-04-29 294/week @ 2024-05-06 192/week @ 2024-05-13 64/week @ 2024-05-20 97/week @ 2024-05-27 30/week @ 2024-06-03 5/week @ 2024-06-10 44/week @ 2024-06-17 49/week @ 2024-06-24 95/week @ 2024-07-01 149/week @ 2024-07-08 96/week @ 2024-07-15

406 downloads per month
Used in 3 crates (2 directly)

MIT license

62KB
1.5K SLoC

Build status Crates.io Version

Live demo (code)

A browser add-on for Firefox, Chrome and Edge

A library to generate syntax ("railroad") diagrams for Rust's macro_rules!().

Diagrams are generated as Scalable Vector Graphics, with layout-details controlled by customizable CSS.

As an example, given the definition of nom's method

macro_rules! method {
    ($name:ident<$a:ty>( $i:ty ) -> $o:ty, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$i:ty,$o:ty,$e:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$i:ty,$o:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$o:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty>( $i:ty ) -> $o:ty, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$i:ty,$o:ty,$e:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$i:ty,$o:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$o:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty>, $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty>( $i:ty ) -> $o:ty, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$i:ty,$o:ty,$e:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$i:ty,$o:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty,$o:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    ($name:ident<$a:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty>( $i:ty ) -> $o:ty, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$i:ty,$o:ty,$e:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$i:ty,$o:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty,$o:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
    (pub $name:ident<$a:ty>, mut $self_:ident, $submac:ident!( $($args:tt)* )) => { ... };
}

... the library generates an SVG which renders (using default CSS) as

Syntax diagram for nom::method


To generate the examples shown here, run

cargo run --example various

which will output some html-files to /examples; Feel free to hack on the demos in /examples/various.rs.

Examples

Dependencies

~0.7–1.2MB
~21K SLoC