In Rust, both declarative and procedural macros (macro_rules!) can accept arbitrary syntax which isn't necessarily valid Rust, provided that it parses. For instance, in the docs, this is used to create a macro which parses SQL queries from an SQL-like syntax.
However, when using attribute macros, this does not seem to be the case. For example:
#[my_attribute_macro]
fn example() {
impl A {
impl B {
// This is invalid Rust code (nested `impl`s) which is parsable
}
}
}
Yields a compiler error because impls cannot be nested in valid Rust. Is there any way of working around this limitation, to get attribute macros which work more like other macros?