Skip to content

Commit

Permalink
Parse variant attributes from ast_enum_of_structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 24, 2021
1 parent 72c006c commit f30253a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions codegen/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,12 @@ mod parsing {

// A single variant of an ast_enum_of_structs!
struct EosVariant {
attrs: Vec<Attribute>,
name: Ident,
member: Option<Path>,
}
fn eos_variant(input: ParseStream) -> Result<EosVariant> {
input.call(Attribute::parse_outer)?;
let attrs = input.call(Attribute::parse_outer)?;
let variant: Ident = input.parse()?;
let member = if input.peek(token::Paren) {
let content;
Expand All @@ -347,6 +348,7 @@ mod parsing {
};
input.parse::<Token![,]>()?;
Ok(EosVariant {
attrs,
name: variant,
member,
})
Expand All @@ -371,10 +373,11 @@ mod parsing {

let enum_item = {
let variants = variants.iter().map(|v| {
let name = v.name.clone();
let attrs = &v.attrs;
let name = &v.name;
match v.member {
Some(ref member) => quote!(#name(#member)),
None => quote!(#name),
Some(ref member) => quote!(#(#attrs)* #name(#member)),
None => quote!(#(#attrs)* #name),
}
});
parse_quote! {
Expand Down

0 comments on commit f30253a

Please sign in to comment.