1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
extern crate proc_macro;
mod renderers;
use regex::Regex;
use syn::parse_macro_input;

#[proc_macro_attribute]
pub fn account_schemas_ix_injector(
    args: proc_macro::TokenStream,
    input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
    let args_str = args.to_string();
    let accounts = Regex::new(r"\s|\n|\t|,")
        .unwrap()
        .split(args_str.as_str())
        .collect::<Vec<&str>>()
        .iter()
        .filter_map(|s| {
            if s.is_empty() {
                None
            } else {
                Some(s.to_string())
            }
        })
        .collect::<Vec<String>>();
    let program = parse_macro_input!(input as syn::ItemMod);
    renderers::AccountSchemaInstructionInjectors::new(program, accounts).render()
}