1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mod attribute_list;
mod quote;
mod utility;

use self::attribute_list::AttributeList;
use proc_macro::TokenStream;
use std::error::Error;
use syn::{parse_macro_input, Item};

#[proc_macro_attribute]
pub fn quote(attributes: TokenStream, item: TokenStream) -> TokenStream {
    let attributes = parse_macro_input!(attributes as AttributeList);
    let item = parse_macro_input!(item as Item);

    convert_result(quote::generate(&attributes, &item))
}

fn convert_result(result: Result<TokenStream, Box<dyn Error>>) -> TokenStream {
    result.unwrap_or_else(|error| {
        let message = error.to_string();

        ::quote::quote! { compile_error!(#message) }.into()
    })
}