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

Method block

src/codegen/stmt.rs:317–389  ·  view source on GitHub ↗
(
        &mut self,
        s: S,
        d: D,
        this_id: NodeID,
        block: &Block,
        span: &Span,
        args: &[Expr],
    )

Source from the content-addressed store, hash-verified

315 }
316
317 pub fn block(
318 &mut self,
319 s: S,
320 d: D,
321 this_id: NodeID,
322 block: &Block,
323 span: &Span,
324 args: &[Expr],
325 ) -> io::Result<()> {
326 if block.args().len() != args.len() {
327 d.report(
328 DiagnosticKind::BlockArgsCountMismatch {
329 block: *block,
330 given: args.len(),
331 },
332 span,
333 )
334 }
335 self.begin_inputs()?;
336 let arg_ids: Vec<NodeID> = (&mut self.id).take(args.len()).collect();
337 let menu_id = block.menu().map(|_| self.id.new_id());
338 let mut menu_value = None;
339 let mut menu_is_default = menu_id.is_some();
340 for ((&arg_name, arg_value), &arg_id) in block.args().iter().zip(args).zip(&arg_ids) {
341 if block.menu().is_some_and(|menu| menu.input == arg_name) {
342 if let Expr::Value { value, span: _ } = &arg_value {
343 menu_value = Some(value.clone());
344 continue;
345 } else {
346 menu_is_default = false;
347 self.input_with_shadow(s, d, arg_name, arg_value, arg_id, menu_id.unwrap())?;
348 }
349 } else {
350 self.input(s, d, arg_name, arg_value, arg_id)?;
351 }
352 }
353 if menu_is_default {
354 write_comma_io(&mut self.zip, &mut self.inputs_comma)?;
355 write!(
356 self,
357 r#""{}":[1,{}]"#,
358 block.menu().unwrap().input,
359 menu_id.unwrap()
360 )?;
361 }
362 self.end_obj()?; // inputs
363 if let Some(fields) = block.fields() {
364 write!(self, r#","fields":{fields}"#)?;
365 }
366 if let Block::StopOtherScripts = block {
367 self.write_all(
368 b",\"mutation\":{\"tagName\":\"mutation\",\"children\": [],\"hasnext\": \"true\"}",
369 )?;
370 }
371 self.end_obj()?; // node
372 for (arg, arg_id) in args.iter().zip(arg_ids) {
373 self.expr(s, d, arg, arg_id, this_id)?;
374 }

Callers 1

stmtMethod · 0.80

Calls 15

write_comma_ioFunction · 0.85
newFunction · 0.85
argsMethod · 0.80
reportMethod · 0.80
begin_inputsMethod · 0.80
menuMethod · 0.80
new_idMethod · 0.80
input_with_shadowMethod · 0.80
end_objMethod · 0.80
fieldsMethod · 0.80
exprMethod · 0.80
begin_nodeMethod · 0.80

Tested by

no test coverage detected