Show rust: A syntax-diagram generator for macro_rules!()-syntax


#1

Hi,

allow me to shamelessly crosspost from reddit: As I found the situation about documenting macro_rules()-syntax not very satisfying, I wrote a library to automatically generate syntax (“railroad”) diagrams directly from code. The obvious target for this is docs.rs, where it might do some good. I’m now looking for comments if rust thinks this thing is useful and worth the effort.

A live demo, compiled to WASM, can be found here.

There are more examples of the macros from nom, stdlib, syn and various others.


#2

Wow thanks for the great tool! :sparkling_heart: :confetti_ball: :tada:

Minor nit picks:

  1. The background color of pat (blue) makes the text unreadable.

    macro_rules! a {
    (
    $item:item
    $block:block
    $stmt:stmt
    $pat:pat
    $expr:expr
    $ty:ty
    $ident:ident
    $path:path
    $meta:meta
    $lifetime:lifetime
    ) => {};
    }
    
  2. :literal and :vis are not supported


#4

Macro-internal rules omitted

*claps* I have to admit, I’m rather pleased to see that. Very nice work.

Also, I think the actual obvious target for this is rustdoc itself.


#5

Fixed :literal and :vis, thanks for pointing this out.


#6

Apart from Rustdoc, I feel like some sort of IDE integration could also be useful, and it could speed up the development of macros significantly