Skip to content

Commit

Permalink
build: parser: Deal with empty descriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed May 22, 2024
1 parent 05defce commit b0858d7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions build/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Payload {
struct MessageDefinition {
name: String,
id: u16,
description: String,
description: Option<String>,
payload: Vec<Payload>,
category: MessageDefinitionCategory,
}
Expand Down Expand Up @@ -174,7 +174,17 @@ impl MessageDefinition {
MessageDefinition {
name: name.clone(),
id: value.get("id").unwrap().as_u64().unwrap() as u16,
description: value.get("description").unwrap().as_str().unwrap().into(),
description: match value.get("description") {
Some(description) => {
let description = description.as_str().unwrap();
if description.is_empty() {
None
} else {
Some(description.into())
}
}
None => None,
},
payload: value
.get("payload")
.unwrap()
Expand All @@ -192,7 +202,10 @@ impl MessageDefinition {
let pascal_message_name = ident!(self.name.to_case(Case::Pascal));

let function_name = quote::format_ident!("{}", self.name.to_case(Case::Snake));
let function_description = &self.description;
let function_description = self
.description
.clone()
.unwrap_or("No documentation provided.".into());
let function_parameters = self.payload.iter().map(|variable| {
let name = ident!(variable.name);
let typ = variable.typ.to_rust();
Expand Down Expand Up @@ -273,7 +286,10 @@ impl MessageDefinition {
}
}
pub fn emit_struct(&self) -> TokenStream {
let comment = &self.description;
let comment = self
.description
.clone()
.unwrap_or("No documentation provided.".into());
let struct_name = quote::format_ident!("{}Struct", self.name.to_case(Case::Pascal));
let variables: Vec<TokenStream> = self
.payload
Expand Down

0 comments on commit b0858d7

Please sign in to comment.