mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
more cleanup
This commit is contained in:
parent
439696cf3f
commit
14ad4e1011
11 changed files with 1199 additions and 1048 deletions
|
|
@ -211,11 +211,31 @@ impl Codegen {
|
|||
|
||||
for class in &amqp.classes {
|
||||
let enum_name = class.name.to_upper_camel_case();
|
||||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
write!(
|
||||
self.output,
|
||||
" {enum_name}{method_name}({enum_name}{method_name}),"
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.output, "}}\n").ok();
|
||||
|
||||
// now codegen the individual structs
|
||||
for class in &amqp.classes {
|
||||
let class_name = class.name.to_upper_camel_case();
|
||||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
self.doc_comment(&class.doc, 4);
|
||||
self.doc_comment(&method.doc, 4);
|
||||
write!(self.output, " {enum_name}{method_name}").ok();
|
||||
writeln!(
|
||||
self.output,
|
||||
"#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct {class_name}{method_name}"
|
||||
)
|
||||
.ok();
|
||||
if !method.fields.is_empty() {
|
||||
writeln!(self.output, " {{").ok();
|
||||
for field in &method.fields {
|
||||
|
|
@ -225,24 +245,22 @@ impl Codegen {
|
|||
field.asserts.as_ref(),
|
||||
);
|
||||
if !field_docs.is_empty() {
|
||||
writeln!(self.output, " /// {field_docs}").ok();
|
||||
writeln!(self.output, " /// {field_docs}").ok();
|
||||
if !field.doc.is_empty() {
|
||||
writeln!(self.output, " ///").ok();
|
||||
self.doc_comment(&field.doc, 8);
|
||||
writeln!(self.output, " ///").ok();
|
||||
self.doc_comment(&field.doc, 4);
|
||||
}
|
||||
} else {
|
||||
self.doc_comment(&field.doc, 8);
|
||||
self.doc_comment(&field.doc, 4);
|
||||
}
|
||||
writeln!(self.output, " {field_name}: {field_type},").ok();
|
||||
writeln!(self.output, " pub {field_name}: {field_type},").ok();
|
||||
}
|
||||
writeln!(self.output, " }},").ok();
|
||||
writeln!(self.output, " }}\n").ok();
|
||||
} else {
|
||||
writeln!(self.output, ",").ok();
|
||||
writeln!(self.output, ";\n").ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.output, "}}\n").ok();
|
||||
}
|
||||
|
||||
fn amqp_type_to_rust_type(&self, amqp_type: &str) -> &'static str {
|
||||
|
|
|
|||
|
|
@ -154,14 +154,14 @@ pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
|
|||
let method_name = method.name.to_upper_camel_case();
|
||||
writeln!(
|
||||
self.output,
|
||||
" Ok((input, Method::{class_name}{method_name} {{"
|
||||
" Ok((input, Method::{class_name}{method_name}({class_name}{method_name} {{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
let field_name = self.snake_case(&field.name);
|
||||
writeln!(self.output, " {field_name},").ok();
|
||||
}
|
||||
writeln!(self.output, " }}))").ok();
|
||||
writeln!(self.output, " }})))").ok();
|
||||
|
||||
writeln!(self.output, "}}").ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use crate::methods::RandomMethod;
|
|||
let method_name = method.name.to_upper_camel_case();
|
||||
writeln!(
|
||||
self.output,
|
||||
" {i} => Method::{class_name}{method_name} {{"
|
||||
" {i} => Method::{class_name}{method_name}( {class_name}{method_name}{{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
|
|
@ -54,7 +54,7 @@ use crate::methods::RandomMethod;
|
|||
)
|
||||
.ok();
|
||||
}
|
||||
writeln!(self.output, " }},").ok();
|
||||
writeln!(self.output, " }}),").ok();
|
||||
}
|
||||
writeln!(
|
||||
self.output,
|
||||
|
|
|
|||
|
|
@ -22,12 +22,16 @@ pub fn write_method<W: Write>(method: Method, mut writer: W) -> Result<(), Trans
|
|||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
let method_index = method.index;
|
||||
writeln!(self.output, " Method::{class_name}{method_name} {{").ok();
|
||||
writeln!(
|
||||
self.output,
|
||||
" Method::{class_name}{method_name}({class_name}{method_name} {{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
let field_name = self.snake_case(&field.name);
|
||||
writeln!(self.output, " {field_name},").ok();
|
||||
}
|
||||
writeln!(self.output, " }} => {{").ok();
|
||||
writeln!(self.output, " }}) => {{").ok();
|
||||
let [ci0, ci1] = class_index.to_be_bytes();
|
||||
let [mi0, mi1] = method_index.to_be_bytes();
|
||||
writeln!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue