Skip to content

Commit

Permalink
feat(parser): include a get_name function for variants
Browse files Browse the repository at this point in the history
  • Loading branch information
H1ghBre4k3r committed Jan 11, 2025
1 parent 6116e3b commit 9487b7d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lachs_derive/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ pub fn impl_token_macro(item: syn::Item, attrs: Punctuated<Ident, Comma>) -> Tok
});

let struct_variants = variants_with_fields.clone().map(|(ident, fields, _)| {
let value = ident.to_string();
quote! {
#[derive(Debug, Clone)]
#vis struct #ident {
#fields
}

impl #ident {
pub fn get_name(&self) -> String {
String::from(#value)
}
}
}
});

Expand All @@ -93,6 +100,13 @@ pub fn impl_token_macro(item: syn::Item, attrs: Punctuated<Ident, Comma>) -> Tok
}
});

let get_name_cases = variants_with_fields.clone().map(|(ident, _, _)| {
let value = ident.to_string();
quote! {
Self::#ident(_) => String::from(#value),
}
});

let insertions = variants_with_fields
.clone()
.map(|(_, _, insertion)| insertion);
Expand Down Expand Up @@ -121,6 +135,12 @@ pub fn impl_token_macro(item: syn::Item, attrs: Punctuated<Ident, Comma>) -> Tok
}
}

pub fn get_name(&self) -> String {
match self {
#(#get_name_cases)*
}
}

fn does_equal(&self, other: &Self) -> bool {
self.position() == other.position()
}
Expand Down

0 comments on commit 9487b7d

Please sign in to comment.