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
//! This crate provides jockey's derive macro.
//!
//! ```rust
//! # extern crate jockey;
//! # #[macro_use] extern crate jockey_derive;
//! # fn main() {
//! #[derive(Arguments)]
//! # #[derive(Default)]
//! # struct Struct {
//! #   pub field: String,
//! # }
//! # }
//! ```

#![recursion_limit="128"] 

extern crate proc_macro;
extern crate proc_macro2;
#[macro_use]
extern crate syn;
#[macro_use]
extern crate quote;

mod derive_parse_args;
mod util;

/// Implementation of `#[derive(Arguments)]` (don't use this directly).
#[proc_macro_derive(Arguments, attributes(jockey))]
pub fn derive_arguments(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input = parse_macro_input!(tokens as syn::DeriveInput);

    let parse_args = derive_parse_args::derive_parse_args(&input);

    let struct_ident: &syn::Ident = &input.ident;
    let result = quote!{
        impl jockey::Arguments for #struct_ident {
            #parse_args
        }
    };
    result.into()
}