| | 338 | /* |
|---|
| | 339 | * Parse the production: |
|---|
| | 340 | * stream ::= STREAM-START implicit_document? explicit_document* STREAM-END |
|---|
| | 341 | * ************ |
|---|
| | 342 | */ |
|---|
| | 343 | |
|---|
| | 344 | static yaml_event_t * |
|---|
| | 345 | yaml_parser_parse_stream_start(yaml_parser_t *parser) |
|---|
| | 346 | { |
|---|
| | 347 | yaml_token_t *token; |
|---|
| | 348 | yaml_event_t *event; |
|---|
| | 349 | |
|---|
| | 350 | token = yaml_parser_get_token(parser); |
|---|
| | 351 | if (!token) return NULL; |
|---|
| | 352 | |
|---|
| | 353 | assert(token->type == YAML_STREAM_START_TOKEN); |
|---|
| | 354 | |
|---|
| | 355 | event = yaml_stream_start_event_new(token->data.stream_start.encoding, |
|---|
| | 356 | token->start_mark, token->start_mark); |
|---|
| | 357 | yaml_token_delete(token); |
|---|
| | 358 | if (!event) { |
|---|
| | 359 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 360 | return NULL; |
|---|
| | 361 | } |
|---|
| | 362 | |
|---|
| | 363 | parser->state = YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE; |
|---|
| | 364 | |
|---|
| | 365 | return event; |
|---|
| | 366 | } |
|---|
| | 367 | |
|---|
| | 368 | /* |
|---|
| | 369 | * Parse the productions: |
|---|
| | 370 | * implicit_document ::= block_node DOCUMENT-END* |
|---|
| | 371 | * * |
|---|
| | 372 | * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* |
|---|
| | 373 | * ************************* |
|---|
| | 374 | */ |
|---|
| | 375 | |
|---|
| | 376 | static yaml_event_t * |
|---|
| | 377 | yaml_parser_parse_document_start(yaml_parser_t *parser, int implicit) |
|---|
| | 378 | { |
|---|
| | 379 | yaml_token_t *token; |
|---|
| | 380 | yaml_event_t *event; |
|---|
| | 381 | |
|---|
| | 382 | token = yaml_parser_peek_token(parser); |
|---|
| | 383 | if (!token) return NULL; |
|---|
| | 384 | |
|---|
| | 385 | /* Parse an implicit document. */ |
|---|
| | 386 | |
|---|
| | 387 | if (implicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN && |
|---|
| | 388 | token->type != YAML_TAG_DIRECTIVE_TOKEN && |
|---|
| | 389 | token->type != YAML_DOCUMENT_START_TOKEN && |
|---|
| | 390 | token->type != YAML_STREAM_END_TOKEN) |
|---|
| | 391 | { |
|---|
| | 392 | if (!yaml_parser_process_directives(parser)) return NULL; |
|---|
| | 393 | if (!yaml_parser_append_state(parser, YAML_PARSE_DOCUMENT_END_STATE)) |
|---|
| | 394 | return NULL; |
|---|
| | 395 | parser->state = YAML_PARSE_BLOCK_NODE_STATE; |
|---|
| | 396 | event = yaml_document_start_event_new( |
|---|
| | 397 | parser->version_directive, parser->tag_directives, 1, |
|---|
| | 398 | token->start_mark, token->start_mark); |
|---|
| | 399 | if (!event) return NULL; |
|---|
| | 400 | return event; |
|---|
| | 401 | } |
|---|
| | 402 | |
|---|
| | 403 | /* Parse an explicit document. */ |
|---|
| | 404 | |
|---|
| | 405 | else if (token->type != YAML_STREAM_END_TOKEN) |
|---|
| | 406 | { |
|---|
| | 407 | yaml_mark_t start_mark, end_mark; |
|---|
| | 408 | start_mark = token->start_mark; |
|---|
| | 409 | if (!yaml_parser_process_directives(parser)) return NULL; |
|---|
| | 410 | token = yaml_parser_peek_token(parser); |
|---|
| | 411 | if (!token) return NULL; |
|---|
| | 412 | if (token->type != YAML_DOCUMENT_START_TOKEN) { |
|---|
| | 413 | yaml_parser_set_parser_error(parser, |
|---|
| | 414 | "did not found expected <document start>", token->start_mark); |
|---|
| | 415 | return NULL; |
|---|
| | 416 | } |
|---|
| | 417 | token = yaml_parser_get_token(parser); |
|---|
| | 418 | end_mark = token->end_mark; |
|---|
| | 419 | yaml_token_delete(token); |
|---|
| | 420 | if (!yaml_parser_append_state(parser, YAML_PARSE_DOCUMENT_END_STATE)) |
|---|
| | 421 | return NULL; |
|---|
| | 422 | parser->state = YAML_PARSE_DOCUMENT_CONTENT_STATE; |
|---|
| | 423 | event = yaml_document_start_event_new( |
|---|
| | 424 | parser->version_directive, parser->tag_directives, 0, |
|---|
| | 425 | start_mark, end_mark); |
|---|
| | 426 | if (!event) return NULL; |
|---|
| | 427 | return event; |
|---|
| | 428 | } |
|---|
| | 429 | |
|---|
| | 430 | /* Parse the stream end. */ |
|---|
| | 431 | |
|---|
| | 432 | else |
|---|
| | 433 | { |
|---|
| | 434 | token = yaml_parser_get_token(parser); |
|---|
| | 435 | parser->state = YAML_PARSE_END_STATE; |
|---|
| | 436 | event = yaml_stream_end_event_new(token->start_mark, token->end_mark); |
|---|
| | 437 | yaml_token_delete(token); |
|---|
| | 438 | return event; |
|---|
| | 439 | } |
|---|
| | 440 | } |
|---|
| | 441 | |
|---|
| | 442 | /* |
|---|
| | 443 | * Parse the productions: |
|---|
| | 444 | * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* |
|---|
| | 445 | * *********** |
|---|
| | 446 | */ |
|---|
| | 447 | |
|---|
| | 448 | static yaml_event_t * |
|---|
| | 449 | yaml_parser_parse_document_content(yaml_parser_t *parser) |
|---|
| | 450 | { |
|---|
| | 451 | yaml_token_t *token; |
|---|
| | 452 | |
|---|
| | 453 | token = yaml_parser_peek_token(parser); |
|---|
| | 454 | if (!token) return NULL; |
|---|
| | 455 | |
|---|
| | 456 | if (token->type == YAML_VERSION_DIRECTIVE_TOKEN || |
|---|
| | 457 | token->type == YAML_TAG_DIRECTIVE_TOKEN || |
|---|
| | 458 | token->type == YAML_DOCUMENT_START_TOKEN || |
|---|
| | 459 | token->type == YAML_DOCUMENT_END_TOKEN || |
|---|
| | 460 | token->type == YAML_STREAM_END_TOKEN) { |
|---|
| | 461 | parser->state = parser->states[--parser->states_length]; |
|---|
| | 462 | return yaml_parser_process_empty_scalar(parser, token->start_mark); |
|---|
| | 463 | } |
|---|
| | 464 | else { |
|---|
| | 465 | return yaml_parser_parse_node(parser, 1, 0); |
|---|
| | 466 | } |
|---|
| | 467 | } |
|---|
| | 468 | |
|---|
| | 469 | /* |
|---|
| | 470 | * Parse the productions: |
|---|
| | 471 | * implicit_document ::= block_node DOCUMENT-END* |
|---|
| | 472 | * ************* |
|---|
| | 473 | * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* |
|---|
| | 474 | * ************* |
|---|
| | 475 | */ |
|---|
| | 476 | |
|---|
| | 477 | static yaml_event_t * |
|---|
| | 478 | yaml_parser_parse_document_end(yaml_parser_t *parser) |
|---|
| | 479 | { |
|---|
| | 480 | yaml_token_t *token; |
|---|
| | 481 | yaml_event_t *event; |
|---|
| | 482 | yaml_mark_t start_mark, end_mark; |
|---|
| | 483 | int implicit = 1; |
|---|
| | 484 | |
|---|
| | 485 | token = yaml_parser_peek_token(parser); |
|---|
| | 486 | if (!token) return NULL; |
|---|
| | 487 | |
|---|
| | 488 | start_mark = end_mark = token->start_mark; |
|---|
| | 489 | |
|---|
| | 490 | while (token->type == YAML_DOCUMENT_END_TOKEN) { |
|---|
| | 491 | end_mark = token->end_mark; |
|---|
| | 492 | yaml_token_delete(yaml_parser_get_token(parser)); |
|---|
| | 493 | token = yaml_parser_peek_token(parser); |
|---|
| | 494 | if (!token) return NULL; |
|---|
| | 495 | implicit = 0; |
|---|
| | 496 | } |
|---|
| | 497 | |
|---|
| | 498 | event = yaml_document_end_event_new(implicit, start_mark, end_mark); |
|---|
| | 499 | if (!event) { |
|---|
| | 500 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 501 | return NULL; |
|---|
| | 502 | } |
|---|
| | 503 | return event; |
|---|
| | 504 | } |
|---|
| | 505 | |
|---|
| | 506 | /* |
|---|
| | 507 | * Parse the productions: |
|---|
| | 508 | * block_node_or_indentless_sequence ::= |
|---|
| | 509 | * ALIAS |
|---|
| | 510 | * ***** |
|---|
| | 511 | * | properties (block_content | indentless_block_sequence)? |
|---|
| | 512 | * ********** * |
|---|
| | 513 | * | block_content | indentless_block_sequence |
|---|
| | 514 | * * |
|---|
| | 515 | * block_node ::= ALIAS |
|---|
| | 516 | * ***** |
|---|
| | 517 | * | properties block_content? |
|---|
| | 518 | * ********** * |
|---|
| | 519 | * | block_content |
|---|
| | 520 | * * |
|---|
| | 521 | * flow_node ::= ALIAS |
|---|
| | 522 | * ***** |
|---|
| | 523 | * | properties flow_content? |
|---|
| | 524 | * ********** * |
|---|
| | 525 | * | flow_content |
|---|
| | 526 | * * |
|---|
| | 527 | * properties ::= TAG ANCHOR? | ANCHOR TAG? |
|---|
| | 528 | * ************************* |
|---|
| | 529 | * block_content ::= block_collection | flow_collection | SCALAR |
|---|
| | 530 | * ****** |
|---|
| | 531 | * flow_content ::= flow_collection | SCALAR |
|---|
| | 532 | * ****** |
|---|
| | 533 | */ |
|---|
| | 534 | |
|---|
| | 535 | static yaml_event_t * |
|---|
| | 536 | yaml_parser_parse_node(yaml_parser_t *parser, |
|---|
| | 537 | int block, int indentless_sequence) |
|---|
| | 538 | { |
|---|
| | 539 | yaml_token_t *token; |
|---|
| | 540 | yaml_event_t *event; |
|---|
| | 541 | yaml_char_t *anchor = NULL; |
|---|
| | 542 | yaml_char_t *tag_handle = NULL; |
|---|
| | 543 | yaml_char_t *tag_suffix = NULL; |
|---|
| | 544 | yaml_char_t *tag = NULL; |
|---|
| | 545 | yaml_mark_t start_mark, end_mark, tag_mark; |
|---|
| | 546 | int implicit; |
|---|
| | 547 | |
|---|
| | 548 | token = yaml_parser_peek_token(parser); |
|---|
| | 549 | if (!token) return NULL; |
|---|
| | 550 | |
|---|
| | 551 | if (token->type == YAML_ALIAS_TOKEN) |
|---|
| | 552 | { |
|---|
| | 553 | token = yaml_parser_get_token(parser); |
|---|
| | 554 | event = yaml_alias_event_new(token->data.alias.value, |
|---|
| | 555 | token->start_mark, token->end_mark); |
|---|
| | 556 | if (!event) { |
|---|
| | 557 | yaml_token_delete(token); |
|---|
| | 558 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 559 | return NULL; |
|---|
| | 560 | } |
|---|
| | 561 | yaml_free(token); |
|---|
| | 562 | return event; |
|---|
| | 563 | } |
|---|
| | 564 | |
|---|
| | 565 | else |
|---|
| | 566 | { |
|---|
| | 567 | start_mark = end_mark = token->start_mark; |
|---|
| | 568 | |
|---|
| | 569 | if (token->type == YAML_ANCHOR_TOKEN) |
|---|
| | 570 | { |
|---|
| | 571 | token = yaml_parser_get_token(parser); |
|---|
| | 572 | anchor = token->data.anchor.value; |
|---|
| | 573 | start_mark = token->start_mark; |
|---|
| | 574 | end_mark = token->end_mark; |
|---|
| | 575 | yaml_free(token); |
|---|
| | 576 | token = yaml_parser_peek_token(parser); |
|---|
| | 577 | if (!token) goto error; |
|---|
| | 578 | if (token->type == YAML_TAG_TOKEN) |
|---|
| | 579 | { |
|---|
| | 580 | token = yaml_parser_get_token(parser); |
|---|
| | 581 | tag_handle = token->data.tag.handle; |
|---|
| | 582 | tag_suffix = token->data.tag.suffix; |
|---|
| | 583 | tag_mark = token->start_mark; |
|---|
| | 584 | end_mark = token->end_mark; |
|---|
| | 585 | yaml_free(token); |
|---|
| | 586 | token = yaml_parser_peek_token(parser); |
|---|
| | 587 | if (!token) goto error; |
|---|
| | 588 | } |
|---|
| | 589 | } |
|---|
| | 590 | else if (token->type == YAML_TAG_TOKEN) |
|---|
| | 591 | { |
|---|
| | 592 | token = yaml_parser_get_token(parser); |
|---|
| | 593 | tag_handle = token->data.tag.handle; |
|---|
| | 594 | tag_suffix = token->data.tag.suffix; |
|---|
| | 595 | start_mark = tag_mark = token->start_mark; |
|---|
| | 596 | end_mark = token->end_mark; |
|---|
| | 597 | yaml_free(token); |
|---|
| | 598 | token = yaml_parser_peek_token(parser); |
|---|
| | 599 | if (!token) goto error; |
|---|
| | 600 | if (token->type == YAML_ANCHOR_TOKEN) |
|---|
| | 601 | { |
|---|
| | 602 | token = yaml_parser_get_token(parser); |
|---|
| | 603 | anchor = token->data.anchor.value; |
|---|
| | 604 | end_mark = token->end_mark; |
|---|
| | 605 | yaml_free(token); |
|---|
| | 606 | token = yaml_parser_peek_token(parser); |
|---|
| | 607 | if (!token) goto error; |
|---|
| | 608 | } |
|---|
| | 609 | } |
|---|
| | 610 | |
|---|
| | 611 | if (tag_handle) { |
|---|
| | 612 | if (!*tag_handle) { |
|---|
| | 613 | tag = tag_suffix; |
|---|
| | 614 | yaml_free(tag_handle); |
|---|
| | 615 | tag_handle = tag_suffix = NULL; |
|---|
| | 616 | } |
|---|
| | 617 | else { |
|---|
| | 618 | yaml_tag_directive_t **tag_directive = parser->tag_directives; |
|---|
| | 619 | for (tag_directive = parser->tag_directives; |
|---|
| | 620 | *tag_directive; tag_directive++) { |
|---|
| | 621 | if (strcmp((char *)(*tag_directive)->handle, (char *)tag_handle) == 0) { |
|---|
| | 622 | size_t prefix_len = strlen((char *)(*tag_directive)->prefix); |
|---|
| | 623 | size_t suffix_len = strlen((char *)tag_suffix); |
|---|
| | 624 | tag = yaml_malloc(prefix_len+suffix_len+1); |
|---|
| | 625 | if (!tag) { |
|---|
| | 626 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 627 | goto error; |
|---|
| | 628 | } |
|---|
| | 629 | memcpy(tag, (*tag_directive)->handle, prefix_len); |
|---|
| | 630 | memcpy(tag+prefix_len, tag_suffix, suffix_len); |
|---|
| | 631 | tag[prefix_len+suffix_len] = '\0'; |
|---|
| | 632 | yaml_free(tag_handle); |
|---|
| | 633 | yaml_free(tag_suffix); |
|---|
| | 634 | tag_handle = tag_suffix = NULL; |
|---|
| | 635 | break; |
|---|
| | 636 | } |
|---|
| | 637 | } |
|---|
| | 638 | if (*tag_directive) { |
|---|
| | 639 | yaml_parser_set_parser_error_context(parser, |
|---|
| | 640 | "while parsing a node", start_mark, |
|---|
| | 641 | "found undefined tag handle", tag_mark); |
|---|
| | 642 | goto error; |
|---|
| | 643 | } |
|---|
| | 644 | } |
|---|
| | 645 | } |
|---|
| | 646 | |
|---|
| | 647 | implicit = (!tag || !*tag); |
|---|
| | 648 | if (indentless_sequence && token->type == YAML_BLOCK_ENTRY_TOKEN) { |
|---|
| | 649 | end_mark = token->end_mark; |
|---|
| | 650 | parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; |
|---|
| | 651 | event = yaml_sequence_start_event_new(anchor, tag, implicit, |
|---|
| | 652 | YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark); |
|---|
| | 653 | if (!event) goto error; |
|---|
| | 654 | } |
|---|
| | 655 | else { |
|---|
| | 656 | if (token->type == YAML_SCALAR_TOKEN) { |
|---|
| | 657 | int plain_implicit = 0; |
|---|
| | 658 | int quoted_implicit = 0; |
|---|
| | 659 | token = yaml_parser_get_token(parser); |
|---|
| | 660 | end_mark = token->end_mark; |
|---|
| | 661 | if ((token->data.scalar.style == YAML_PLAIN_SCALAR_STYLE && !tag) |
|---|
| | 662 | || strcmp((char *)tag, "!") == 0) { |
|---|
| | 663 | plain_implicit = 1; |
|---|
| | 664 | } |
|---|
| | 665 | else if (!tag) { |
|---|
| | 666 | quoted_implicit = 1; |
|---|
| | 667 | } |
|---|
| | 668 | parser->state = parser->states[--parser->states_length]; |
|---|
| | 669 | event = yaml_scalar_event_new(anchor, tag, |
|---|
| | 670 | token->data.scalar.value, token->data.scalar.length, |
|---|
| | 671 | plain_implicit, quoted_implicit, |
|---|
| | 672 | token->data.scalar.style, start_mark, end_mark); |
|---|
| | 673 | if (!event) { |
|---|
| | 674 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 675 | yaml_token_delete(token); |
|---|
| | 676 | goto error; |
|---|
| | 677 | } |
|---|
| | 678 | yaml_free(token); |
|---|
| | 679 | } |
|---|
| | 680 | else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) { |
|---|
| | 681 | end_mark = token->end_mark; |
|---|
| | 682 | parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE; |
|---|
| | 683 | event = yaml_sequence_start_event_new(anchor, tag, implicit, |
|---|
| | 684 | YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark); |
|---|
| | 685 | if (!event) { |
|---|
| | 686 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 687 | goto error; |
|---|
| | 688 | } |
|---|
| | 689 | } |
|---|
| | 690 | else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) { |
|---|
| | 691 | end_mark = token->end_mark; |
|---|
| | 692 | parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE; |
|---|
| | 693 | event = yaml_mapping_start_event_new(anchor, tag, implicit, |
|---|
| | 694 | YAML_FLOW_MAPPING_STYLE, start_mark, end_mark); |
|---|
| | 695 | if (!event) { |
|---|
| | 696 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 697 | goto error; |
|---|
| | 698 | } |
|---|
| | 699 | } |
|---|
| | 700 | else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) { |
|---|
| | 701 | end_mark = token->end_mark; |
|---|
| | 702 | parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE; |
|---|
| | 703 | event = yaml_sequence_start_event_new(anchor, tag, implicit, |
|---|
| | 704 | YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark); |
|---|
| | 705 | if (!event) { |
|---|
| | 706 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 707 | goto error; |
|---|
| | 708 | } |
|---|
| | 709 | } |
|---|
| | 710 | else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) { |
|---|
| | 711 | end_mark = token->end_mark; |
|---|
| | 712 | parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE; |
|---|
| | 713 | event = yaml_mapping_start_event_new(anchor, tag, implicit, |
|---|
| | 714 | YAML_BLOCK_MAPPING_STYLE, start_mark, end_mark); |
|---|
| | 715 | if (!event) { |
|---|
| | 716 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 717 | goto error; |
|---|
| | 718 | } |
|---|
| | 719 | } |
|---|
| | 720 | else if (anchor || tag) { |
|---|
| | 721 | yaml_char_t *value = yaml_malloc(1); |
|---|
| | 722 | if (!value) { |
|---|
| | 723 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 724 | goto error; |
|---|
| | 725 | } |
|---|
| | 726 | value[0] = '\0'; |
|---|
| | 727 | event = yaml_scalar_event_new(anchor, tag, value, 0, |
|---|
| | 728 | implicit, 0, YAML_PLAIN_SCALAR_STYLE, |
|---|
| | 729 | start_mark, end_mark); |
|---|
| | 730 | if (!event) { |
|---|
| | 731 | yaml_free(value); |
|---|
| | 732 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 733 | goto error; |
|---|
| | 734 | } |
|---|
| | 735 | } |
|---|
| | 736 | else { |
|---|
| | 737 | yaml_parser_set_parser_error_context(parser, |
|---|
| | 738 | (block ? "while parsing a block node" |
|---|
| | 739 | : "while parsing a flow node"), start_mark, |
|---|
| | 740 | "did not found expected node content", token->start_mark); |
|---|
| | 741 | goto error; |
|---|
| | 742 | } |
|---|
| | 743 | return event; |
|---|
| | 744 | } |
|---|
| | 745 | } |
|---|
| | 746 | |
|---|
| | 747 | error: |
|---|
| | 748 | yaml_free(anchor); |
|---|
| | 749 | yaml_free(tag_handle); |
|---|
| | 750 | yaml_free(tag_suffix); |
|---|
| | 751 | yaml_free(tag); |
|---|
| | 752 | |
|---|
| | 753 | return NULL; |
|---|
| | 754 | } |
|---|
| | 755 | |
|---|
| | 756 | /* |
|---|
| | 757 | * Parse the productions: |
|---|
| | 758 | * block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END |
|---|
| | 759 | * ******************** *********** * ********* |
|---|
| | 760 | */ |
|---|
| | 761 | |
|---|
| | 762 | static yaml_event_t * |
|---|
| | 763 | yaml_parser_parse_block_sequence_entry(yaml_parser_t *parser, int first) |
|---|
| | 764 | { |
|---|
| | 765 | yaml_token_t *token; |
|---|
| | 766 | yaml_event_t *event; |
|---|
| | 767 | |
|---|
| | 768 | if (first) { |
|---|
| | 769 | token = yaml_parser_get_token(parser); |
|---|
| | 770 | if (!yaml_parser_append_mark(parser, token->start_mark)) { |
|---|
| | 771 | yaml_token_delete(token); |
|---|
| | 772 | return NULL; |
|---|
| | 773 | } |
|---|
| | 774 | yaml_token_delete(token); |
|---|
| | 775 | } |
|---|
| | 776 | |
|---|
| | 777 | token = yaml_parser_get_token(parser); |
|---|
| | 778 | if (!token) return NULL; |
|---|
| | 779 | |
|---|
| | 780 | if (token->type == YAML_BLOCK_ENTRY_TOKEN) |
|---|
| | 781 | { |
|---|
| | 782 | yaml_mark_t mark = token->end_mark; |
|---|
| | 783 | yaml_token_delete(token); |
|---|
| | 784 | token = yaml_parser_peek_token(parser); |
|---|
| | 785 | if (!token) return NULL; |
|---|
| | 786 | if (token->type != YAML_BLOCK_ENTRY_TOKEN && |
|---|
| | 787 | token->type != YAML_BLOCK_END_TOKEN) { |
|---|
| | 788 | if (!yaml_parser_append_state(parser, |
|---|
| | 789 | YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE)) |
|---|
| | 790 | return NULL; |
|---|
| | 791 | return yaml_parser_parse_node(parser, 1, 0); |
|---|
| | 792 | } |
|---|
| | 793 | else { |
|---|
| | 794 | parser->state = YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE; |
|---|
| | 795 | return yaml_parser_process_empty_scalar(parser, mark); |
|---|
| | 796 | } |
|---|
| | 797 | } |
|---|
| | 798 | |
|---|
| | 799 | else if (token->type == YAML_BLOCK_END_TOKEN) |
|---|
| | 800 | { |
|---|
| | 801 | parser->state = parser->states[--parser->states_length]; |
|---|
| | 802 | event = yaml_sequence_end_event_new(token->start_mark, token->end_mark); |
|---|
| | 803 | yaml_token_delete(token); |
|---|
| | 804 | if (!event) { |
|---|
| | 805 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 806 | return NULL; |
|---|
| | 807 | } |
|---|
| | 808 | return event; |
|---|
| | 809 | } |
|---|
| | 810 | |
|---|
| | 811 | else |
|---|
| | 812 | { |
|---|
| | 813 | yaml_parser_set_parser_error_context(parser, |
|---|
| | 814 | "while parsing a block collection", parser->marks[parser->marks_length-1], |
|---|
| | 815 | "did not found expected '-' indicator", token->start_mark); |
|---|
| | 816 | yaml_token_delete(token); |
|---|
| | 817 | return NULL; |
|---|
| | 818 | } |
|---|
| | 819 | } |
|---|
| | 820 | |
|---|
| | 821 | /* |
|---|
| | 822 | * Parse the productions: |
|---|
| | 823 | * indentless_sequence ::= (BLOCK-ENTRY block_node?)+ |
|---|
| | 824 | * *********** * |
|---|
| | 825 | */ |
|---|
| | 826 | |
|---|
| | 827 | static yaml_event_t * |
|---|
| | 828 | yaml_parser_parse_indentless_sequence_entry(yaml_parser_t *parser) |
|---|
| | 829 | { |
|---|
| | 830 | yaml_token_t *token; |
|---|
| | 831 | yaml_event_t *event; |
|---|
| | 832 | |
|---|
| | 833 | token = yaml_parser_peek_token(parser); |
|---|
| | 834 | if (!token) return NULL; |
|---|
| | 835 | |
|---|
| | 836 | if (token->type == YAML_BLOCK_ENTRY_TOKEN) |
|---|
| | 837 | { |
|---|
| | 838 | yaml_mark_t mark = token->end_mark; |
|---|
| | 839 | yaml_token_delete(yaml_parser_get_token(parser)); |
|---|
| | 840 | token = yaml_parser_peek_token(parser); |
|---|
| | 841 | if (token->type != YAML_BLOCK_ENTRY_TOKEN && |
|---|
| | 842 | token->type != YAML_BLOCK_END_TOKEN) { |
|---|
| | 843 | if (!yaml_parser_append_state(parser, |
|---|
| | 844 | YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE)) |
|---|
| | 845 | return NULL; |
|---|
| | 846 | return yaml_parser_parse_node(parser, 1, 0); |
|---|
| | 847 | } |
|---|
| | 848 | else { |
|---|
| | 849 | parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; |
|---|
| | 850 | return yaml_parser_process_empty_scalar(parser, mark); |
|---|
| | 851 | } |
|---|
| | 852 | } |
|---|
| | 853 | |
|---|
| | 854 | else |
|---|
| | 855 | { |
|---|
| | 856 | parser->state = parser->states[--parser->states_length]; |
|---|
| | 857 | event = yaml_sequence_end_event_new(token->start_mark, token->start_mark); |
|---|
| | 858 | if (!event) { |
|---|
| | 859 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 860 | return NULL; |
|---|
| | 861 | } |
|---|
| | 862 | return event; |
|---|
| | 863 | } |
|---|
| | 864 | } |
|---|
| | 865 | |
|---|
| | 866 | /* |
|---|
| | 867 | * Parse the productions: |
|---|
| | 868 | * block_mapping ::= BLOCK-MAPPING_START |
|---|
| | 869 | * ******************* |
|---|
| | 870 | * ((KEY block_node_or_indentless_sequence?)? |
|---|
| | 871 | * *** * |
|---|
| | 872 | * (VALUE block_node_or_indentless_sequence?)?)* |
|---|
| | 873 | * |
|---|
| | 874 | * BLOCK-END |
|---|
| | 875 | * ********* |
|---|
| | 876 | */ |
|---|
| | 877 | |
|---|
| | 878 | static yaml_event_t * |
|---|
| | 879 | yaml_parser_parse_block_mapping_key(yaml_parser_t *parser, int first) |
|---|
| | 880 | { |
|---|
| | 881 | yaml_token_t *token; |
|---|
| | 882 | yaml_event_t *event; |
|---|
| | 883 | |
|---|
| | 884 | if (first) { |
|---|
| | 885 | token = yaml_parser_get_token(parser); |
|---|
| | 886 | if (!yaml_parser_append_mark(parser, token->start_mark)) { |
|---|
| | 887 | yaml_token_delete(token); |
|---|
| | 888 | return NULL; |
|---|
| | 889 | } |
|---|
| | 890 | yaml_token_delete(token); |
|---|
| | 891 | } |
|---|
| | 892 | |
|---|
| | 893 | token = yaml_parser_get_token(parser); |
|---|
| | 894 | if (!token) return NULL; |
|---|
| | 895 | |
|---|
| | 896 | if (token->type == YAML_KEY_TOKEN) |
|---|
| | 897 | { |
|---|
| | 898 | yaml_mark_t mark = token->end_mark; |
|---|
| | 899 | yaml_token_delete(token); |
|---|
| | 900 | token = yaml_parser_peek_token(parser); |
|---|
| | 901 | if (!token) return NULL; |
|---|
| | 902 | if (token->type != YAML_KEY_TOKEN && |
|---|
| | 903 | token->type != YAML_VALUE_TOKEN && |
|---|
| | 904 | token->type != YAML_BLOCK_END_TOKEN) { |
|---|
| | 905 | if (!yaml_parser_append_state(parser, |
|---|
| | 906 | YAML_PARSE_BLOCK_MAPPING_VALUE_STATE)) |
|---|
| | 907 | return NULL; |
|---|
| | 908 | return yaml_parser_parse_node(parser, 1, 1); |
|---|
| | 909 | } |
|---|
| | 910 | else { |
|---|
| | 911 | parser->state = YAML_PARSE_BLOCK_MAPPING_VALUE_STATE; |
|---|
| | 912 | return yaml_parser_process_empty_scalar(parser, mark); |
|---|
| | 913 | } |
|---|
| | 914 | } |
|---|
| | 915 | |
|---|
| | 916 | else if (token->type == YAML_BLOCK_END_TOKEN) |
|---|
| | 917 | { |
|---|
| | 918 | parser->state = parser->states[--parser->states_length]; |
|---|
| | 919 | event = yaml_sequence_end_event_new(token->start_mark, token->end_mark); |
|---|
| | 920 | yaml_token_delete(token); |
|---|
| | 921 | if (!event) { |
|---|
| | 922 | parser->error = YAML_MEMORY_ERROR; |
|---|
| | 923 | return NULL; |
|---|
| | 924 | } |
|---|
| | 925 | return event; |
|---|
| | 926 | } |
|---|
| | 927 | |
|---|
| | 928 | else |
|---|
| | 929 | { |
|---|
| | 930 | yaml_parser_set_parser_error_context(parser, |
|---|
| | 931 | "while parsing a block mapping", parser->marks[parser->marks_length-1], |
|---|
| | 932 | "did not found expected key", token->start_mark); |
|---|
| | 933 | yaml_token_delete(token); |
|---|
| | 934 | return NULL; |
|---|
| | 935 | } |
|---|
| | 936 | } |
|---|
| | 937 | |
|---|
| | 938 | /* |
|---|
| | 939 | * Parse the productions: |
|---|
| | 940 | * block_mapping ::= BLOCK-MAPPING_START |
|---|
| | 941 | * |
|---|
| | 942 | * ((KEY block_node_or_indentless_sequence?)? |
|---|
| | 943 | * |
|---|
| | 944 | * (VALUE block_node_or_indentless_sequence?)?)* |
|---|
| | 945 | * ***** * |
|---|
| | 946 | * BLOCK-END |
|---|
| | 947 | * |
|---|
| | 948 | */ |
|---|
| | 949 | |
|---|
| | 950 | static yaml_event_t * |
|---|
| | 951 | yaml_parser_parse_block_mapping_value(yaml_parser_t *parser) |
|---|
| | 952 | { |
|---|
| | 953 | yaml_token_t *token; |
|---|
| | 954 | yaml_event_t *event; |
|---|
| | 955 | |
|---|
| | 956 | token = yaml_parser_peek_token(parser); |
|---|
| | 957 | if (!token) return NULL; |
|---|
| | 958 | |
|---|
| | 959 | if (token->type == YAML_VALUE_TOKEN) |
|---|
| | 960 | { |
|---|
| | 961 | yaml_mark_t mark = token->end_mark; |
|---|
| | 962 | yaml_token_delete(yaml_parser_get_token(parser)); |
|---|
| | 963 | token = yaml_parser_peek_token(parser); |
|---|
| | 964 | if (!token) return NULL; |
|---|
| | 965 | if (token->type != YAML_KEY_TOKEN && |
|---|
| | 966 | token->type != YAML_VALUE_TOKEN && |
|---|
| | 967 | token->type != YAML_BLOCK_END_TOKEN) { |
|---|
| | 968 | if (!yaml_parser_append_state(parser, |
|---|
| | 969 | YAML_PARSE_BLOCK_MAPPING_KEY_STATE)) |
|---|
| | 970 | return NULL; |
|---|
| | 971 | return yaml_parser_parse_node(parser, 1, 1); |
|---|
| | 972 | } |
|---|
| | 973 | else { |
|---|
| | 974 | parser->state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE; |
|---|
| | 975 | return yaml_parser_process_empty_scalar(parser, mark); |
|---|
| | 976 | } |
|---|
| | 977 | } |
|---|
| | 978 | |
|---|
| | 979 | else |
|---|
| | 980 | { |
|---|
| | 981 | parser->state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE; |
|---|
| | 982 | return yaml_parser_process_empty_scalar(parser, token->start_mark); |
|---|
| | 983 | } |
|---|
| | 984 | } |
|---|
| | 985 | |
|---|
| | 986 | static yaml_event_t * |
|---|
| | 987 | yaml_parser_parse_flow_sequence_entry(yaml_parser_t *parser, int first); |
|---|
| | 988 | |
|---|
| | 989 | static yaml_event_t * |
|---|
| | 990 | yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser); |
|---|
| | 991 | |
|---|
| | 992 | static yaml_event_t * |
|---|
| | 993 | yaml_parser_parse_flow_sequence_entry_mapping_value(yaml_parser_t *parser); |
|---|
| | 994 | |
|---|
| | 995 | static yaml_event_t * |
|---|
| | 996 | yaml_parser_parse_flow_sequence_entry_mapping_end(yaml_parser_t *parser); |
|---|
| | 997 | |
|---|
| | 998 | static yaml_event_t * |
|---|
| | 999 | yaml_parser_parse_flow_mapping_key(yaml_parser_t *parser, int first); |
|---|
| | 1000 | |
|---|
| | 1001 | static yaml_event_t * |
|---|
| | 1002 | yaml_parser_parse_flow_mapping_value(yaml_parser_t *parser, int empty); |
|---|
| | 1003 | |
|---|