| 15554 | } |
| 15555 | |
| 15556 | void parse_document() |
| 15557 | { |
| 15558 | assert_not_error(); |
| 15559 | assert_not_eof(); |
| 15560 | push_parse_scope("root table"sv); |
| 15561 | |
| 15562 | table* current_table = &root; |
| 15563 | |
| 15564 | do |
| 15565 | { |
| 15566 | return_if_error(); |
| 15567 | |
| 15568 | // leading whitespace, line endings, comments |
| 15569 | if (consume_leading_whitespace() || consume_line_break() || consume_comment()) |
| 15570 | continue; |
| 15571 | return_if_error(); |
| 15572 | |
| 15573 | // [tables] |
| 15574 | // [[table array]] |
| 15575 | if (*cp == U'[') |
| 15576 | current_table = parse_table_header(); |
| 15577 | |
| 15578 | // bare_keys |
| 15579 | // dotted.keys |
| 15580 | // "quoted keys" |
| 15581 | else if (is_bare_key_character(*cp) || is_string_delimiter(*cp)) |
| 15582 | { |
| 15583 | push_parse_scope("key-value pair"sv); |
| 15584 | |
| 15585 | parse_key_value_pair_and_insert(current_table); |
| 15586 | |
| 15587 | // handle the rest of the line after the kvp |
| 15588 | // (this is not done in parse_key_value_pair() because that is also used for inline tables) |
| 15589 | consume_leading_whitespace(); |
| 15590 | return_if_error(); |
| 15591 | if (!is_eof() && !consume_comment() && !consume_line_break()) |
| 15592 | set_error("expected a comment or whitespace, saw '"sv, to_sv(cp), "'"sv); |
| 15593 | } |
| 15594 | |
| 15595 | else // ?? |
| 15596 | set_error("expected keys, tables, whitespace or comments, saw '"sv, to_sv(cp), "'"sv); |
| 15597 | } |
| 15598 | while (!is_eof()); |
| 15599 | |
| 15600 | auto eof_pos = current_position(1); |
| 15601 | root.source_.end = eof_pos; |
| 15602 | if (current_table && current_table != &root && current_table->source_.end <= current_table->source_.begin) |
| 15603 | current_table->source_.end = eof_pos; |
| 15604 | } |
| 15605 | |
| 15606 | static void update_region_ends(node& nde) noexcept |
| 15607 | { |