From c34886f9541797ff4267ebe966ba4216b1aea6c3 Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 29 Jun 2023 16:43:17 +0200 Subject: [PATCH] sdk-builder: canonicalize and ident-ize package name - fix `,` not being an illegal char in idents --- sdk-builder/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk-builder/src/main.rs b/sdk-builder/src/main.rs index 239a3ca..caa1a30 100644 --- a/sdk-builder/src/main.rs +++ b/sdk-builder/src/main.rs @@ -143,7 +143,7 @@ pub mod rust { use anyhow::Context; use itertools::Itertools; - use proc_macro2::TokenStream; + use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; use unreal_sdk::sdk::repr::{ Class, ClassField, ClassMethod, Enum, ObjectRef, PrimitiveType, ProcessedPackage, Sdk, @@ -175,9 +175,9 @@ pub mod rust { "i64", "i128", "usize", "isize", ]; - const CHARS: [char; 19] = [ + const CHARS: [char; 20] = [ ' ', '?', '+', '-', ':', '/', '^', '(', ')', '[', ']', '<', '>', '&', '.', '#', '\'', '"', - '%', + '%', ',', ]; pub struct Builder { @@ -257,7 +257,7 @@ pub mod rust { .packages .values() .map(|pkg| { - let name = pkg.name.clone(); + let name = canonicalize_name(&pkg.name).to_string(); let tokens = self.generate_package(pkg, args.feature_gate)?; anyhow::Ok((name, tokens)) @@ -280,6 +280,7 @@ pub mod rust { let mut mod_rs = TokenStream::new(); for (name, tokens) in packages { + let name = format_ident!("{name}"); if args.single_file { mod_rs.extend(quote! { pub mod #name {