From 3368c504d97ffc9cd831e7af44237ccd8261aee1 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:40:01 -0600 Subject: [PATCH 01/22] Box for recursive types --- xsd-parser/src/generator/struct_field.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index dee270c..0587ca8 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -22,9 +22,11 @@ pub trait StructFieldGenerator { } fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { + let type_name = gen.base().format_type_name(entity.type_name.as_str(), gen); + let type_name = format!("Box<{}>", type_name); gen.base() .modify_type( - gen.base().format_type_name(entity.type_name.as_str(), gen).as_ref(), + &type_name, &entity.type_modifiers, ) .into() From 6cce94903858f63090253fd0597823d185c03033 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:43:55 -0600 Subject: [PATCH 02/22] Box for recursive types --- xsd-parser/src/generator/struct_field.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index 0587ca8..21d0766 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -22,8 +22,13 @@ pub trait StructFieldGenerator { } fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { - let type_name = gen.base().format_type_name(entity.type_name.as_str(), gen); - let type_name = format!("Box<{}>", type_name); + let mut type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); + if entity.type_modifiers.is_empty() { + type_name = match type_name.to_string().as_str() { + "f64" => type_name.to_string(), + _ => format!("Box<{}>", type_name), + }; + } gen.base() .modify_type( &type_name, From 301abb954b64f81053708145ae316414db74656b Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:46:08 -0600 Subject: [PATCH 03/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index 21d0766..82ffc5a 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -23,7 +23,7 @@ pub trait StructFieldGenerator { fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { let mut type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); - if entity.type_modifiers.is_empty() { + if entity.type_modifiers.is_empty() && !type_name.ends_with("Choice") { type_name = match type_name.to_string().as_str() { "f64" => type_name.to_string(), _ => format!("Box<{}>", type_name), From 4283625915232f1afdfe1624654ba95ad6189a08 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:49:24 -0600 Subject: [PATCH 04/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index 82ffc5a..d496b44 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -23,6 +23,7 @@ pub trait StructFieldGenerator { fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { let mut type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); + println!("type_name={type_name} entity.type_modifiers={:?}", entity.type_modifiers); if entity.type_modifiers.is_empty() && !type_name.ends_with("Choice") { type_name = match type_name.to_string().as_str() { "f64" => type_name.to_string(), From 3c312744eea43b94d615ee7916f846a1b48f8a6b Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:52:29 -0600 Subject: [PATCH 05/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index d496b44..e57d915 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -22,20 +22,15 @@ pub trait StructFieldGenerator { } fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { - let mut type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); - println!("type_name={type_name} entity.type_modifiers={:?}", entity.type_modifiers); - if entity.type_modifiers.is_empty() && !type_name.ends_with("Choice") { - type_name = match type_name.to_string().as_str() { - "f64" => type_name.to_string(), - _ => format!("Box<{}>", type_name), - }; - } - gen.base() + let type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); + let type_name: String = gen.base() .modify_type( &type_name, &entity.type_modifiers, ) - .into() + .into(); + let type_name = format!("Box<{type_name}>"); + type_name } fn get_name(&self, entity: &StructField, gen: &Generator) -> String { From 008613f10422a86b4f85418cefe761acfb9d9206 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:54:04 -0600 Subject: [PATCH 06/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index e57d915..0f35fe1 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -23,13 +23,15 @@ pub trait StructFieldGenerator { fn get_type_name(&self, entity: &StructField, gen: &Generator) -> String { let type_name = gen.base().format_type_name(entity.type_name.as_str(), gen).to_string(); - let type_name: String = gen.base() + let mut type_name: String = gen.base() .modify_type( &type_name, &entity.type_modifiers, ) .into(); - let type_name = format!("Box<{type_name}>"); + if type_name != "f64" && !type_name.starts_with("Vec<") { + type_name = format!("Box<{type_name}>"); + } type_name } From 941f3bca42e1aa89212be6315761d75cbb352b5c Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 14:55:01 -0600 Subject: [PATCH 07/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index 0f35fe1..de717aa 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -29,7 +29,7 @@ pub trait StructFieldGenerator { &entity.type_modifiers, ) .into(); - if type_name != "f64" && !type_name.starts_with("Vec<") { + if type_name != "f64" && type_name != "String" && !type_name.starts_with("Vec<") { type_name = format!("Box<{type_name}>"); } type_name From 6e9893906886dfa513fca236749d9c095a00e1ea Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 16:53:22 -0600 Subject: [PATCH 08/22] hacky hack --- xsd-parser/src/generator/struct.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index f6a641a..0523d46 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -7,7 +7,7 @@ use crate::{ pub trait StructGenerator { fn generate(&self, entity: &Struct, gen: &Generator) -> String { - format!( + let str = format!( "{comment}{macros}pub struct {name} {{{fields}}}\n\n{validation}\n{subtypes}\n", comment = self.format_comment(entity, gen), macros = self.macros(entity, gen), @@ -15,7 +15,10 @@ pub trait StructGenerator { fields = self.fields(entity, gen), subtypes = self.subtypes(entity, gen), validation = self.validation(entity, gen), - ) + ); + let name = self.get_type_name(entity, gen); + let str2 = format!("impl YaSerialize for Box<{name}> {{\nfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n"); + str + str2.as_str() } fn fields(&self, entity: &Struct, gen: &Generator) -> String { From 756318aa7784a6c464ad256bf3d45cd0ce8f8b7d Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 16:58:41 -0600 Subject: [PATCH 09/22] hacky hack --- xsd-parser/src/generator/struct.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 0523d46..0a1fb77 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -17,8 +17,9 @@ pub trait StructGenerator { validation = self.validation(entity, gen), ); let name = self.get_type_name(entity, gen); - let str2 = format!("impl YaSerialize for Box<{name}> {{\nfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n"); - str + str2.as_str() + let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); + let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\nOk(Box::new(Window::deserialize(reader)?))}}\n\n}}"); + str + str2.as_str() + str3.as_str() } fn fields(&self, entity: &Struct, gen: &Generator) -> String { From 5c096de595618efdd909985e8b1a8ab03ef76527 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:00:33 -0600 Subject: [PATCH 10/22] hacky hack --- xsd-parser/src/generator/struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 0a1fb77..a537ce7 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -18,7 +18,7 @@ pub trait StructGenerator { ); let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); - let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\nOk(Box::new(Window::deserialize(reader)?))}}\n\n}}"); + let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new(Window::deserialize(reader)?))}}\n}}\n\n"); str + str2.as_str() + str3.as_str() } From 514aeb24a359e1eb6b15390442c470ba2f76deaf Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:03:14 -0600 Subject: [PATCH 11/22] hacky hack --- xsd-parser/src/generator/struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index a537ce7..e63af38 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -18,7 +18,7 @@ pub trait StructGenerator { ); let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); - let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new(Window::deserialize(reader)?))}}\n}}\n\n"); + let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); str + str2.as_str() + str3.as_str() } From de2191b3a903d33224aa83dadd9d3b3de4ebf8dc Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:04:29 -0600 Subject: [PATCH 12/22] hacky hack --- xsd-parser/src/generator/enum.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/enum.rs b/xsd-parser/src/generator/enum.rs index d314e72..6c56ef1 100644 --- a/xsd-parser/src/generator/enum.rs +++ b/xsd-parser/src/generator/enum.rs @@ -18,7 +18,7 @@ pub trait EnumGenerator { indent = gen.base().indent() ); - format!( + let str = format!( "{comment}{macros}\n\ pub enum {name} {{\n\ {cases}\n\ @@ -36,7 +36,12 @@ pub trait EnumGenerator { default = default_case, subtypes = self.subtypes(entity, gen), validation = self.validation(entity, gen), - ) + ); + + let name = self.get_type_name(entity, gen); + let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); + let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); + str + str2.as_str() + str3.as_str() } fn cases(&self, entity: &Enum, gen: &Generator) -> String { From 99fcf6ef5163ffe4444c6253e0055d010ec219c2 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:07:16 -0600 Subject: [PATCH 13/22] hacky hack --- xsd-parser/src/generator/struct.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index e63af38..8e2f26f 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -19,7 +19,11 @@ pub trait StructGenerator { let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); - str + str2.as_str() + str3.as_str() + if name == "String" { + str + } else { + str + str2.as_str() + str3.as_str() + } } fn fields(&self, entity: &Struct, gen: &Generator) -> String { From 6cafef2ee974549b4885f6c2da54ed0bb5b17f3a Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:08:49 -0600 Subject: [PATCH 14/22] hacky hack --- xsd-parser/src/generator/enum.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/enum.rs b/xsd-parser/src/generator/enum.rs index 6c56ef1..ea83f2b 100644 --- a/xsd-parser/src/generator/enum.rs +++ b/xsd-parser/src/generator/enum.rs @@ -41,7 +41,11 @@ pub trait EnumGenerator { let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); - str + str2.as_str() + str3.as_str() + if name == "String" { + str + } else { + str + str2.as_str() + str3.as_str() + } } fn cases(&self, entity: &Enum, gen: &Generator) -> String { From 9bcdaa154cf411f2b044bafc349f722856383e17 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:10:23 -0600 Subject: [PATCH 15/22] hacky hack --- xsd-parser/src/generator/enum.rs | 7 +------ xsd-parser/src/generator/struct.rs | 6 +----- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/xsd-parser/src/generator/enum.rs b/xsd-parser/src/generator/enum.rs index ea83f2b..a7a1c94 100644 --- a/xsd-parser/src/generator/enum.rs +++ b/xsd-parser/src/generator/enum.rs @@ -38,14 +38,9 @@ pub trait EnumGenerator { validation = self.validation(entity, gen), ); - let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); - if name == "String" { - str - } else { - str + str2.as_str() + str3.as_str() - } + str + str2.as_str() + str3.as_str() } fn cases(&self, entity: &Enum, gen: &Generator) -> String { diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 8e2f26f..e63af38 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -19,11 +19,7 @@ pub trait StructGenerator { let name = self.get_type_name(entity, gen); let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); - if name == "String" { - str - } else { - str + str2.as_str() + str3.as_str() - } + str + str2.as_str() + str3.as_str() } fn fields(&self, entity: &Struct, gen: &Generator) -> String { From f8fc5b1f4dd15d14320e0ffaec37433708c7025a Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:16:37 -0600 Subject: [PATCH 16/22] hacky hack --- xsd-parser/src/generator/struct.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index e63af38..6d145b7 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -17,8 +17,11 @@ pub trait StructGenerator { validation = self.validation(entity, gen), ); let name = self.get_type_name(entity, gen); - let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); - let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); + let mut str2 = format!("impl YaSerialize for Box<{name}> {{\n"); + str2 += format!("\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\n\t\tself.as_ref().serialize(writer)\n}}\n").as_str(); + str2 += format!("\tfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\n\t\tself.as_ref().serialize_attributes(attributes, namespace)\n}}\n}}\n\n").as_str(); + let mut str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n"); + str3 += format!("\t\tOk(Box::new({name}::deserialize(reader)?))\n}}\n}}\n\n").as_str(); str + str2.as_str() + str3.as_str() } From 574e6c080af6cd4bf79c494ced79b83628ee87f8 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 17:17:53 -0600 Subject: [PATCH 17/22] hacky hack --- xsd-parser/src/generator/enum.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xsd-parser/src/generator/enum.rs b/xsd-parser/src/generator/enum.rs index a7a1c94..0e26ea8 100644 --- a/xsd-parser/src/generator/enum.rs +++ b/xsd-parser/src/generator/enum.rs @@ -38,8 +38,11 @@ pub trait EnumGenerator { validation = self.validation(entity, gen), ); - let str2 = format!("impl YaSerialize for Box<{name}> {{\n\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\nself.serialize(writer)\n}}\nfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\nself.serialize_attributes(attributes, namespace)\n}}\n}}\n\n"); - let str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n\t\tOk(Box::new({name}::deserialize(reader)?))}}\n}}\n\n"); + let mut str2 = format!("impl YaSerialize for Box<{name}> {{\n"); + str2 += format!("\tfn serialize(&self, writer: &mut Serializer) -> Result<(), String> {{\n\t\tself.as_ref().serialize(writer)\n}}\n").as_str(); + str2 += format!("\tfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\n\t\tself.as_ref().serialize_attributes(attributes, namespace)\n}}\n}}\n\n").as_str(); + let mut str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n"); + str3 += format!("\t\tOk(Box::new({name}::deserialize(reader)?))\n}}\n}}\n\n").as_str(); str + str2.as_str() + str3.as_str() } From c91336b0af85f3d83a08948c2fdac7ba837e7da2 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 19:21:17 -0600 Subject: [PATCH 18/22] hacky hack --- xsd-parser/src/generator/struct.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 6d145b7..1fd0e12 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -22,7 +22,11 @@ pub trait StructGenerator { str2 += format!("\tfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\n\t\tself.as_ref().serialize_attributes(attributes, namespace)\n}}\n}}\n\n").as_str(); let mut str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n"); str3 += format!("\t\tOk(Box::new({name}::deserialize(reader)?))\n}}\n}}\n\n").as_str(); - str + str2.as_str() + str3.as_str() + if name.contains("String") { + str + } else { + str + str2.as_str() + str3.as_str() + } } fn fields(&self, entity: &Struct, gen: &Generator) -> String { From 3049b6634962d51a6e83998ca9b51d0b7fc580a4 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 19:23:01 -0600 Subject: [PATCH 19/22] hacky hack --- xsd-parser/src/generator/struct.rs | 6 +----- xsd-parser/src/generator/struct_field.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 1fd0e12..6d145b7 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -22,11 +22,7 @@ pub trait StructGenerator { str2 += format!("\tfn serialize_attributes(&self, attributes: Vec, namespace: Namespace) -> Result<(Vec, Namespace), String> {{\n\t\tself.as_ref().serialize_attributes(attributes, namespace)\n}}\n}}\n\n").as_str(); let mut str3 = format!("impl YaDeserialize for Box<{name}> {{\n\tfn deserialize(reader: &mut Deserializer) -> Result {{\n"); str3 += format!("\t\tOk(Box::new({name}::deserialize(reader)?))\n}}\n}}\n\n").as_str(); - if name.contains("String") { - str - } else { - str + str2.as_str() + str3.as_str() - } + str + str2.as_str() + str3.as_str() } fn fields(&self, entity: &Struct, gen: &Generator) -> String { diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index de717aa..d5f8516 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -29,7 +29,7 @@ pub trait StructFieldGenerator { &entity.type_modifiers, ) .into(); - if type_name != "f64" && type_name != "String" && !type_name.starts_with("Vec<") { + if type_name != "f64" && !type_name.contains("String") && !type_name.starts_with("Vec<") { type_name = format!("Box<{type_name}>"); } type_name From b70a36b166947201a0073c9528815c39e3c72789 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Tue, 30 Apr 2024 21:12:01 -0600 Subject: [PATCH 20/22] hacky hack --- xsd-parser/src/generator/struct_field.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/xsd-parser/src/generator/struct_field.rs b/xsd-parser/src/generator/struct_field.rs index d5f8516..18864d5 100644 --- a/xsd-parser/src/generator/struct_field.rs +++ b/xsd-parser/src/generator/struct_field.rs @@ -32,6 +32,7 @@ pub trait StructFieldGenerator { if type_name != "f64" && !type_name.contains("String") && !type_name.starts_with("Vec<") { type_name = format!("Box<{type_name}>"); } + type_name = type_name.replace("Box Date: Thu, 2 May 2024 12:28:46 -0600 Subject: [PATCH 21/22] hacky hack --- xsd-parser/src/generator/struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 6d145b7..46269f4 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -86,7 +86,7 @@ pub trait StructGenerator { } fn macros(&self, _entity: &Struct, gen: &Generator) -> Cow<'static, str> { - let derives = "#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]\n"; + let derives = "#[derive(Clone, Default, PartialEq, Debug, YaSerialize, YaDeserialize)]\n"; let tns = gen.target_ns.borrow(); match tns.as_ref() { Some(tn) => match tn.name() { From c5099f9e865cdbb916465a62f16f6eb2013f1c06 Mon Sep 17 00:00:00 2001 From: Brent Gardner Date: Thu, 2 May 2024 12:33:30 -0600 Subject: [PATCH 22/22] hacky hack --- xsd-parser/src/generator/struct.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsd-parser/src/generator/struct.rs b/xsd-parser/src/generator/struct.rs index 46269f4..6d145b7 100644 --- a/xsd-parser/src/generator/struct.rs +++ b/xsd-parser/src/generator/struct.rs @@ -86,7 +86,7 @@ pub trait StructGenerator { } fn macros(&self, _entity: &Struct, gen: &Generator) -> Cow<'static, str> { - let derives = "#[derive(Clone, Default, PartialEq, Debug, YaSerialize, YaDeserialize)]\n"; + let derives = "#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]\n"; let tns = gen.target_ns.borrow(); match tns.as_ref() { Some(tn) => match tn.name() {