From e16a2af67dcb6f06c5806056a70e366c67e6b9f8 Mon Sep 17 00:00:00 2001 From: "Deven T. Corzine" Date: Fri, 3 Jan 2025 09:26:50 -0500 Subject: [PATCH] For enum values starting with a digit, prefix the generated symbol with an underscore. --- .../smithy/rust/codegen/core/rustlang/RustReservedWords.kt | 2 +- .../smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt index 2c143d8009..e6eb87f654 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt @@ -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#")) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 02b0ba14d7..ff5dbbab09 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -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()