sdk-builder: canonicalize and ident-ize package name

- fix `,` not being an illegal char in idents
This commit is contained in:
Janis 2023-06-29 16:43:17 +02:00
parent 8c47749c98
commit c34886f954

View file

@ -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 {