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

Function yaml_parser_parse_document_start

xs/tools/yaml/parser.c:363–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361 */
362
363static int
364yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event,
365 int implicit)
366{
367 yaml_token_t *token;
368 yaml_version_directive_t *version_directive = NULL;
369 struct {
370 yaml_tag_directive_t *start;
371 yaml_tag_directive_t *end;
372 } tag_directives = { NULL, NULL };
373
374 token = PEEK_TOKEN(parser);
375 if (!token) return 0;
376
377 /* Parse extra document end indicators. */
378
379 if (!implicit)
380 {
381 while (token->type == YAML_DOCUMENT_END_TOKEN) {
382 SKIP_TOKEN(parser);
383 token = PEEK_TOKEN(parser);
384 if (!token) return 0;
385 }
386 }
387
388 /* Parse an implicit document. */
389
390 if (implicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN &&
391 token->type != YAML_TAG_DIRECTIVE_TOKEN &&
392 token->type != YAML_DOCUMENT_START_TOKEN &&
393 token->type != YAML_STREAM_END_TOKEN)
394 {
395 if (!yaml_parser_process_directives(parser, NULL, NULL, NULL))
396 return 0;
397 if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE))
398 return 0;
399 parser->state = YAML_PARSE_BLOCK_NODE_STATE;
400 DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1,
401 token->start_mark, token->start_mark);
402 return 1;
403 }
404
405 /* Parse an explicit document. */
406
407 else if (token->type != YAML_STREAM_END_TOKEN)
408 {
409 yaml_mark_t start_mark, end_mark;
410 start_mark = token->start_mark;
411 if (!yaml_parser_process_directives(parser, &version_directive,
412 &tag_directives.start, &tag_directives.end))
413 return 0;
414 token = PEEK_TOKEN(parser);
415 if (!token) goto error;
416 if (token->type != YAML_DOCUMENT_START_TOKEN) {
417 yaml_parser_set_parser_error(parser,
418 "did not find expected <document start>", token->start_mark);
419 goto error;
420 }

Callers 1

Calls 3

yaml_freeFunction · 0.85

Tested by

no test coverage detected