2022-07-10 17:06:19 +02:00
|
|
|
mod group;
|
|
|
|
mod skeleton;
|
|
|
|
mod util;
|
2022-07-10 18:32:55 +02:00
|
|
|
mod parser;
|
|
|
|
mod md_parser;
|
2022-07-10 17:06:19 +02:00
|
|
|
|
|
|
|
use case::CaseExt;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::quote;
|
|
|
|
use skeleton::generate_skeleton;
|
|
|
|
use syn::parse_macro_input;
|
|
|
|
|
|
|
|
use crate::group::generate_groups;
|
|
|
|
|
2022-07-10 18:32:55 +02:00
|
|
|
const API_CONTENT: &str = include_str!("../api-4_1.md");
|
2022-07-10 17:06:19 +02:00
|
|
|
|
|
|
|
#[proc_macro_derive(QBittorrentApiGen, attributes(api_gen))]
|
|
|
|
pub fn derive(input: TokenStream) -> TokenStream {
|
|
|
|
let ast = parse_macro_input!(input as syn::DeriveInput);
|
|
|
|
let ident = &ast.ident;
|
|
|
|
|
|
|
|
let api_groups = parser::parse_api_groups(API_CONTENT);
|
|
|
|
|
|
|
|
let skeleton = generate_skeleton(ident);
|
|
|
|
let groups = generate_groups(api_groups);
|
|
|
|
let impl_ident = syn::Ident::new(&format!("{}_impl", ident).to_snake(), ident.span());
|
|
|
|
|
|
|
|
quote! {
|
|
|
|
mod #impl_ident {
|
|
|
|
#skeleton
|
|
|
|
#groups
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.into()
|
|
|
|
}
|