Skip to content

Commit

Permalink
- fix: more naming issues when outputting rust
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenX8 committed Nov 28, 2024
1 parent 65ee270 commit c26e650
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions generator/src/codegen/rust/codegen_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
cg!(self, "/* Generated with IDL v{} */\n", version);
cg!(self, r#"use bincode::{{Encode, Decode}};"#);
cg!(self, r#"use crate::packet::PacketPayload;"#);

for content in packet.contents() {
use self::PacketContent::*;
match content {
Include(ref inc, system) => {
cg!(self, r#"use {};"#, inc);
},
_ => {}
};
}
cg!(self);

let iserialize = packet.contents().iter().filter_map(|elem| {
Expand Down Expand Up @@ -82,7 +92,10 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
}
Some(rust_type)
}
// TODO Map complex type
PacketContent::Complex(ref e) => {
let rust_type = (e.name().clone(), e.name().clone());
Some(rust_type)
}
_ => None,
}
}).collect::<HashMap<String, String>>(); // Collect into a HashMap
Expand All @@ -106,7 +119,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
cg!(self);

cg!(self, r#"#[derive(Debug, Encode, Decode)]"#);
cg!(self, "pub struct {} {{", packet.class_name());
cg!(self, "pub struct {} {{", packet.class_name().to_upper_camel_case());
self.indent();
for content in packet.contents() {
use self::PacketContent::*;
Expand All @@ -119,7 +132,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> {
cg!(self, "}}");

cg!(self);
cg!(self, "impl PacketPayload for {} {{}}", packet.class_name());
cg!(self, "impl PacketPayload for {} {{}}", packet.class_name().to_upper_camel_case());


Ok(())
Expand Down Expand Up @@ -270,9 +283,9 @@ fn rename_if_reserved(name: &str) -> String {
];

if reserved_keywords.contains(&name) {
format!("{}_", name) // Append a suffix to avoid conflicts
format!("{}_", name.to_snake_case()) // Append a suffix to avoid conflicts
} else {
name.to_string()
name.to_string().to_snake_case()
}
}

2 changes: 1 addition & 1 deletion generator/src/flat_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Packet {
(name.clone(),
name.clone().to_snake_case())
} else {
let name = "srv".to_string() + &name[5..];
let name = "Srv".to_string() + &name[5..];
(name.clone(),
name.clone().to_snake_case())
}
Expand Down

0 comments on commit c26e650

Please sign in to comment.