MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_parser_load_sequence

Function yaml_parser_load_sequence

xs/tools/yaml/loader.c:343–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341 */
342
343static int
344yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
345{
346 yaml_event_t event;
347 yaml_node_t node;
348 struct {
349 yaml_node_item_t *start;
350 yaml_node_item_t *end;
351 yaml_node_item_t *top;
352 } items = { NULL, NULL, NULL };
353 int index, item_index;
354 yaml_char_t *tag = first_event->data.sequence_start.tag;
355
356 if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
357
358 if (!tag || strcmp((char *)tag, "!") == 0) {
359 yaml_free(tag);
360 tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG);
361 if (!tag) goto error;
362 }
363
364 if (!STACK_INIT(parser, items, INITIAL_STACK_SIZE)) goto error;
365
366 SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
367 first_event->data.sequence_start.style,
368 first_event->start_mark, first_event->end_mark);
369
370 if (!PUSH(parser, parser->document->nodes, node)) goto error;
371
372 index = (int)(parser->document->nodes.top - parser->document->nodes.start);
373
374 if (!yaml_parser_register_anchor(parser, index,
375 first_event->data.sequence_start.anchor)) return 0;
376
377 if (!yaml_parser_parse(parser, &event)) return 0;
378
379 while (event.type != YAML_SEQUENCE_END_EVENT) {
380 if (!STACK_LIMIT(parser,
381 parser->document->nodes.start[index-1].data.sequence.items,
382 INT_MAX-1)) return 0;
383 item_index = yaml_parser_load_node(parser, &event);
384 if (!item_index) return 0;
385 if (!PUSH(parser,
386 parser->document->nodes.start[index-1].data.sequence.items,
387 item_index)) return 0;
388 if (!yaml_parser_parse(parser, &event)) return 0;
389 }
390
391 parser->document->nodes.start[index-1].end_mark = event.end_mark;
392
393 return index;
394
395error:
396 yaml_free(tag);
397 yaml_free(first_event->data.sequence_start.anchor);
398 return 0;
399}
400

Callers 1

yaml_parser_load_nodeFunction · 0.85

Calls 5

yaml_freeFunction · 0.85
yaml_strdupFunction · 0.85
yaml_parser_parseFunction · 0.85
yaml_parser_load_nodeFunction · 0.85

Tested by

no test coverage detected