2023-07-16 12:01:48 +00:00
|
|
|
mod mark_as_ci_command;
|
|
|
|
mod struct_to_ci_enum;
|
|
|
|
|
|
|
|
use mark_as_ci_command::generate_final_function;
|
2023-07-12 19:48:51 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
2023-07-16 12:01:48 +00:00
|
|
|
use quote::quote;
|
|
|
|
use struct_to_ci_enum::{generate_command_enum, generate_generate_ci_function};
|
|
|
|
use syn::{self, ItemFn, Field, parse::Parser};
|
2023-07-12 19:48:51 +00:00
|
|
|
|
|
|
|
#[proc_macro_attribute]
|
2023-07-16 12:01:48 +00:00
|
|
|
pub fn turn_struct_to_ci_commands(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
2023-07-12 19:48:51 +00:00
|
|
|
// Construct a representation of Rust code as a syntax tree
|
|
|
|
// that we can manipulate
|
|
|
|
let input = syn::parse(input)
|
|
|
|
.expect("This should always be valid rust code, as it's extracted from direct code");
|
|
|
|
|
|
|
|
// Build the trait implementation
|
2023-07-16 12:01:48 +00:00
|
|
|
let generate_ci_function: TokenStream2 = generate_generate_ci_function(&input);
|
|
|
|
|
|
|
|
let command_enum = generate_command_enum(&input);
|
|
|
|
|
|
|
|
quote! {
|
|
|
|
#command_enum
|
|
|
|
#generate_ci_function
|
|
|
|
}
|
|
|
|
.into()
|
2023-07-12 19:48:51 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 12:01:48 +00:00
|
|
|
/// Generate a default lua function implementation.
|
2023-07-17 05:23:36 +00:00
|
|
|
// TODO: Is this needed?
|
2023-07-16 12:01:48 +00:00
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn gen_lua_function(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
|
|
|
// Construct a representation of Rust code as a syntax tree
|
|
|
|
// that we can manipulate
|
|
|
|
let parser = Field::parse_named;
|
|
|
|
let input = parser.parse(input)
|
|
|
|
.expect("This is only defined for named fileds.");
|
|
|
|
|
|
|
|
|
|
|
|
quote! {
|
2023-07-17 05:23:36 +00:00
|
|
|
#input
|
2023-07-16 12:01:48 +00:00
|
|
|
}
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Turn a function into a valid ci command function
|
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn ci_command(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
|
|
|
// Construct a representation of Rust code as a syntax tree
|
|
|
|
// that we can manipulate
|
|
|
|
let mut input: ItemFn = syn::parse(input)
|
|
|
|
.expect("This should always be valid rust code, as it's extracted from direct code");
|
|
|
|
|
|
|
|
// Build the trait implementation
|
|
|
|
let output_function: TokenStream2 = generate_final_function(&mut input);
|
|
|
|
|
|
|
|
//panic!("{:#?}", output_function);
|
|
|
|
quote! {
|
|
|
|
#output_function
|
|
|
|
}
|
|
|
|
.into()
|
2023-07-12 19:48:51 +00:00
|
|
|
}
|