MCPcopy Create free account
hub / github.com/aspizu/goboscript / list_declaration

Method list_declaration

src/codegen/sb3.rs:771–839  ·  view source on GitHub ↗
(
        &mut self,
        input: &Path,
        s: S,
        list: &List,
        comma: &mut bool,
        d: D,
    )

Source from the content-addressed store, hash-verified

769 }
770
771 pub fn list_declaration(
772 &mut self,
773 input: &Path,
774 s: S,
775 list: &List,
776 comma: &mut bool,
777 d: D,
778 ) -> io::Result<()> {
779 let data = list
780 .cmd()
781 .and_then(|cmd| {
782 cmd_to_list(cmd, input)
783 .map_err(|err| d.diagnostics.push(err))
784 .ok()
785 })
786 .or_else(|| {
787 list.array().map(|array| {
788 array
789 .iter()
790 .map(|(value, _)| String::from(value.to_string().as_str()))
791 .collect::<Vec<_>>()
792 })
793 });
794 match &list.type_ {
795 Type::Value => {
796 write_comma_io(&mut self.zip, comma)?;
797 if let Some(cmd) = data {
798 write!(self, r#""{}":["{}",{}]"#, list.name, list.name, json!(cmd))?;
799 } else {
800 write!(self, r#""{}":["{}",[]]"#, list.name, list.name)?;
801 }
802 }
803 Type::Struct {
804 name: type_name,
805 span: type_span,
806 } => {
807 let Some(struct_) = s.get_struct(type_name) else {
808 d.report(
809 DiagnosticKind::UnrecognizedStruct(type_name.clone()),
810 type_span,
811 );
812 return Ok(());
813 };
814 for (i, field) in struct_.fields.iter().enumerate() {
815 let qualified_list_name = qualify_struct_var_name(&field.name, &list.name);
816 write_comma_io(&mut self.zip, comma)?;
817 if let Some(cmd) = &data {
818 let column = (0..(cmd.len() / struct_.fields.len()))
819 .map(|j| &cmd[j * struct_.fields.len() + i])
820 .collect::<Vec<_>>();
821 write!(
822 self,
823 r#""{}":["{}",{}]"#,
824 qualified_list_name,
825 qualified_list_name,
826 json!(column)
827 )?;
828 } else {

Callers 1

spriteMethod · 0.80

Calls 8

cmd_to_listFunction · 0.85
write_comma_ioFunction · 0.85
qualify_struct_var_nameFunction · 0.85
cmdMethod · 0.80
arrayMethod · 0.80
reportMethod · 0.80
to_stringMethod · 0.45
get_structMethod · 0.45

Tested by

no test coverage detected