Skip to content

Commit

Permalink
Fix @name not working on single elem group choices
Browse files Browse the repository at this point in the history
Fixes #211
Fixes #153
  • Loading branch information
rooooooooob committed Nov 15, 2023
1 parent 3385715 commit 83a0ede
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,8 @@ pub fn parse_group(
.iter()
.enumerate()
.map(|(i, group_choice)| {
let rule_metadata =
RuleMetadata::from(group_choice.comments_before_grpchoice.as_ref());
// If we're a 1-element we should just wrap that type in the variant rather than
// define a new struct just for each variant.
// TODO: handle map-based enums? It would require being able to extract the key logic
Expand All @@ -1500,15 +1502,17 @@ pub fn parse_group(
} else {
false
};
let variant_ident =
convert_to_camel_case(&match group_entry_to_raw_field_name(group_entry) {
let ident_name = rule_metadata.name.unwrap_or_else(|| {
match group_entry_to_raw_field_name(group_entry) {
Some(name) => name,
None => append_number_if_duplicate(
&mut variants_names_used,
ty.for_variant().to_string(),
),
});
let variant_ident = VariantIdent::new_custom(variant_ident);
}
});
let variant_ident =
VariantIdent::new_custom(convert_to_camel_case(&ident_name));
EnumVariant::new(variant_ident, ty, serialize_as_embedded)
// None => {
// // TODO: Weird case, group choice with only one fixed-value field.
Expand All @@ -1521,8 +1525,6 @@ pub fn parse_group(
// EnumVariant::new(variant_name.clone(), RustType::Rust(variant_name), true)
// },
} else {
let rule_metadata =
RuleMetadata::from(group_choice.comments_before_grpchoice.as_ref());
let ident_name = rule_metadata.name.unwrap_or_else(|| format!("{name}{i}"));
// General case, GroupN type identifiers and generate group choice since it's inlined here
let variant_name = RustIdent::new(CDDLIdent::new(ident_name));
Expand Down

0 comments on commit 83a0ede

Please sign in to comment.