How to parse enum macro?

You "just" have to manually parse what represents the syntax of an enum definition: a comma-separated sequence of variant names, where each may be followed by a parenthesized comma-saparated sequence of types (technically braces with named fields are a possibility too, but handling both within the same macro would require making it much more complex), and both sequences accept trailing commas:

macro_rules! bridge_events {(
    $(
        $VariantName:ident $(
            ( $($T:ty),+ $(,)? )
        )?
    ),+ $(,)?
) => (
    #[cfg_attr(feature = "ts_test",
        derive(EnumIter, AsRefStr),
    )]
    #[derive(FromPrimitive, Copy, Clone, Debug)]
    #[repr(u32)]
    pub
    enum BridgeEvent {
        $(
            $VariantName ,
        )+
    }

    pub
    enum Event {
        $(
            $VariantName $(
                ( $($T ,)+ )
            )? ,
        )+
    }
)}

See The Little Book of Rust macros for a guide regarding them.

6 Likes