| 346 | */ |
| 347 | |
| 348 | static int |
| 349 | yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event, |
| 350 | int implicit) |
| 351 | { |
| 352 | yaml_token_t *token; |
| 353 | yaml_version_directive_t *version_directive = NULL; |
| 354 | struct { |
| 355 | yaml_tag_directive_t *start; |
| 356 | yaml_tag_directive_t *end; |
| 357 | } tag_directives = { NULL, NULL }; |
| 358 | |
| 359 | token = PEEK_TOKEN(parser); |
| 360 | if (!token) return 0; |
| 361 | |
| 362 | /* Parse extra document end indicators. */ |
| 363 | |
| 364 | if (!implicit) |
| 365 | { |
| 366 | while (token->type == YAML_DOCUMENT_END_TOKEN) { |
| 367 | SKIP_TOKEN(parser); |
| 368 | token = PEEK_TOKEN(parser); |
| 369 | if (!token) return 0; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /* Parse an implicit document. */ |
| 374 | |
| 375 | if (implicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN && |
| 376 | token->type != YAML_TAG_DIRECTIVE_TOKEN && |
| 377 | token->type != YAML_DOCUMENT_START_TOKEN && |
| 378 | token->type != YAML_STREAM_END_TOKEN) |
| 379 | { |
| 380 | if (!yaml_parser_process_directives(parser, NULL, NULL, NULL)) |
| 381 | return 0; |
| 382 | if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) |
| 383 | return 0; |
| 384 | parser->state = YAML_PARSE_BLOCK_NODE_STATE; |
| 385 | DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1, |
| 386 | token->start_mark, token->start_mark); |
| 387 | return 1; |
| 388 | } |
| 389 | |
| 390 | /* Parse an explicit document. */ |
| 391 | |
| 392 | else if (token->type != YAML_STREAM_END_TOKEN) |
| 393 | { |
| 394 | yaml_mark_t start_mark, end_mark; |
| 395 | start_mark = token->start_mark; |
| 396 | if (!yaml_parser_process_directives(parser, &version_directive, |
| 397 | &tag_directives.start, &tag_directives.end)) |
| 398 | return 0; |
| 399 | token = PEEK_TOKEN(parser); |
| 400 | if (!token) goto error; |
| 401 | if (token->type != YAML_DOCUMENT_START_TOKEN) { |
| 402 | yaml_parser_set_parser_error(parser, |
| 403 | "did not find expected <document start>", token->start_mark); |
| 404 | goto error; |
| 405 | } |
no test coverage detected