Skip to content

Commit

Permalink
For enum values starting with a digit, prefix the generated symbol wi…
Browse files Browse the repository at this point in the history
…th an underscore.
  • Loading branch information
deven committed Jan 3, 2025
1 parent 845bb91 commit e16a2af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RustReservedWordSymbolProvider(
return base.toSymbol(shape)
}
val previousName = base.toMemberName(shape)
val escapedName = this.toMemberName(shape)
val escapedName = this.toMemberName(shape).replace(Regex("^(_*\\d)"), "_$1")
// if the names don't match and it isn't a simple escaping with `r#`, record a rename
renamedSymbol.toBuilder().name(escapedName)
.letIf(escapedName != previousName && !escapedName.contains("r#")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class EnumMemberModel(
parentShape: Shape,
definition: EnumDefinition,
): MaybeRenamed? {
val name = definition.name.orNull()?.toPascalCase() ?: return null
val name = definition.name.orNull()?.toPascalCase()?.replace(Regex("^(_*\\d)"), "_$1") ?: return null
// Create a fake member shape for symbol look up until we refactor to use EnumShape
val fakeMemberShape =
MemberShape.builder().id(parentShape.id.withMember(name)).target("smithy.api#String").build()
Expand Down

0 comments on commit e16a2af

Please sign in to comment.