Is this macro syntax possible: macro![a,b]{ /* ... */ }


#1

I have a macro that’s used like this:

external_function(a.as_mut_ptr(), b.as_mut_ptr());
validate![a, b];

Would it be possible to rearrange it to something more like:

validate![a,b] {
    external_function(a.as_mut_ptr(), b.as_mut_ptr());
}

#2

No. You get one group ((..), [..], {..}) as argument to a macro. Best you can do is nest everything in another, outer group.


#3

Thanks. Wrapping it may be the best option then. I just want to make the relationship more obvious in some way.


#4

At some point in the future it may be possible to write

#[validate(a, b)] {
    external_function(a.as_mut_ptr(), b.as_mut_ptr()); 
}

(I tried to test whether attribute proc macros are accepted in this position, but I can’t even figure out which unstable features I need to activate anymore…)


Edit: Okay, I tested it. Yes, support for proc macros in this position is implemented, but there are currently two features you have to toggle just for that:

#![feature(use_extern_macros)]
#![feature(stmt_expr_attributes)]
#![feature(proc_macro_expr)]
extern crate procm;
use procm::attr;

fn main() {
    #[attr(a, b)] {
        let a = 3;
    }
}

In any case, it’s not in the subset of proc macro features that are going to be stabilized soon.