Let's say I want to build a #[proc_macro_attribute] that takes the following code:
#[say_hello_if_blue]
fn foobar() {
do_something(1, 2, 3);
do_something_blue(1, 2, 3);
if some_condition() {
if other_condition() {
let a = get_value();
let b = get_value_blue(a);
}
}
}
and transforms it into:
fn foobar() {
do_something(1, 2, 3);
do_something_blue(1, 2, 3, "Hello");
if some_condition() {
if other_condition() {
let a = get_value();
let b = get_value_blue(a, "Hello");
}
}
}
In other words, I'd like to be able to take an arbitrary syntax tree (in that case a function body), select parts of the tree that match simple conditions (eg "is a function calls whose name ends with _blue"), and perform some transformations on them while ignoring the rest.
Is this implemented in syn somewhere? Is there a crate that implements that feature? Or is it something I need to code from the ground up?