Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @name not working on single elem group choices #213

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading