-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathlib.rs
58 lines (49 loc) · 1.63 KB
/
lib.rs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};
mod document_definition;
mod gen;
mod merge_right;
mod resolver;
use crate::document_definition::{expand_directive_definition, expand_input_definition};
use crate::merge_right::expand_merge_right_derive;
use crate::resolver::expand_resolver_derive;
#[proc_macro_derive(MergeRight, attributes(merge_right))]
pub fn merge_right_derive(input: TokenStream) -> TokenStream {
expand_merge_right_derive(input)
}
#[proc_macro_derive(DirectiveDefinition, attributes(directive_definition))]
pub fn directive_definitions_derive(input: TokenStream) -> TokenStream {
expand_directive_definition(input)
}
#[proc_macro_derive(Doc, attributes(gen_doc))]
pub fn scalar_definition_derive(input: TokenStream) -> TokenStream {
gen::doc(input)
}
#[proc_macro]
pub fn gen_doc(item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::DeriveInput);
let name = &input.ident;
let gen = quote::quote! {
impl #name {
pub fn doc() -> &'static str {
stringify!(#name)
}
}
};
TokenStream::from(quote::quote! {
#input
#gen
})
}
#[proc_macro_derive(InputDefinition)]
pub fn input_definition_derive(input: TokenStream) -> TokenStream {
expand_input_definition(input)
}
#[proc_macro_derive(CustomResolver, attributes(resolver))]
pub fn resolver_derive(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
expand_resolver_derive(input)
.unwrap_or_else(syn::Error::into_compile_error)
.into()
}