MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / parse_array

Method parse_array

src/toml.hpp:15685–15752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15683 };
15684
15685 TOML_EXTERNAL_LINKAGE
15686 node_ptr parser::parse_array()
15687 {
15688 return_if_error({});
15689 assert_not_eof();
15690 TOML_ASSERT_ASSUME(*cp == U'[');
15691 push_parse_scope("array"sv);
15692
15693 // skip opening '['
15694 advance_and_return_if_error_or_eof({});
15695
15696 node_ptr arr_ptr{ new array{} };
15697 array& arr = arr_ptr->ref_cast<array>();
15698 enum class TOML_CLOSED_ENUM parse_type : int
15699 {
15700 none,
15701 comma,
15702 val
15703 };
15704 parse_type prev = parse_type::none;
15705
15706 while (!is_error())
15707 {
15708 while (consume_leading_whitespace() || consume_line_break() || consume_comment())
15709 continue;
15710 set_error_and_return_if_eof({});
15711
15712 // commas - only legal after a value
15713 if (*cp == U',')
15714 {
15715 if (prev == parse_type::val)
15716 {
15717 prev = parse_type::comma;
15718 advance_and_return_if_error_or_eof({});
15719 continue;
15720 }
15721 set_error_and_return_default("expected value or closing ']', saw comma"sv);
15722 }
15723
15724 // closing ']'
15725 else if (*cp == U']')
15726 {
15727 advance_and_return_if_error({});
15728 break;
15729 }
15730
15731 // must be a value
15732 else
15733 {
15734 if (prev == parse_type::val)
15735 {
15736 set_error_and_return_default("expected comma or closing ']', saw '"sv, to_sv(*cp), "'"sv);
15737 continue;
15738 }
15739 prev = parse_type::val;
15740
15741 auto val = parse_value();
15742 return_if_error({});

Callers

nothing calls this directly

Calls 1

moveFunction · 0.85

Tested by

no test coverage detected