Skip to content

Commit

Permalink
fixed macro allowing keywords as module/func names
Browse files Browse the repository at this point in the history
  • Loading branch information
animafps committed Sep 1, 2023
1 parent 4eb4311 commit e4deaac
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rustsynth-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn init_plugins(_input: TokenStream) -> TokenStream {
let func_vec: Vec<proc_macro2::TokenStream> = x
.functions()
.map(|y| {
let name = Ident::new(y.name.unwrap(), Span::call_site());
let name = syn::parse_str::<Ident>(y.name.unwrap()).unwrap_or_else(|_| syn::parse_str::<Ident>(&(y.name.unwrap().to_owned() + "_")).expect("error"));

let args = y
.arguments
Expand All @@ -72,7 +72,9 @@ pub fn init_plugins(_input: TokenStream) -> TokenStream {
.collect();
let args_vec = parse_arguments(&args_split);
let arg_names: Vec<Ident> = args_split.iter().filter(|x| x.len() == 2).map(|x| {
Ident::new(x[0], Span::call_site())
syn::parse_str::<Ident>(x[0]).unwrap_or_else(|_| {
syn::parse_str::<Ident>(&(x[0].to_owned() + "_")).expect("error")
})
}).collect();
quote! {
pub fn #name<'core>(core: &'core rustsynth::core::CoreRef<'core>, #(#args_vec),*) -> rustsynth::map::OwnedMap<'core> {
Expand All @@ -96,6 +98,7 @@ pub fn init_plugins(_input: TokenStream) -> TokenStream {
})
.collect();
let gen = quote! {
#[allow(non_snake_case)]
pub mod Plugins {
#(
#token_vec
Expand All @@ -111,7 +114,9 @@ fn parse_arguments(input: &Vec<Vec<&str>>) -> Vec<proc_macro2::TokenStream> {
.iter()
.filter(|x| x.len() == 2)
.map(|x| {
let x0 = Ident::new(x[0], Span::call_site());
let x0 = syn::parse_str::<Ident>(x[0]).unwrap_or_else(|_| {
syn::parse_str::<Ident>(&(x[0].to_owned() + "_")).expect("error")
});
match x[1] {
"vnode" => {
quote! {
Expand Down

0 comments on commit e4deaac

Please sign in to comment.