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

Method parse_inline_table

src/toml.hpp:15754–15837  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15752 }
15753
15754 TOML_EXTERNAL_LINKAGE
15755 node_ptr parser::parse_inline_table()
15756 {
15757 return_if_error({});
15758 assert_not_eof();
15759 TOML_ASSERT_ASSUME(*cp == U'{');
15760 push_parse_scope("inline table"sv);
15761
15762 // skip opening '{'
15763 advance_and_return_if_error_or_eof({});
15764
15765 node_ptr tbl_ptr{ new table{} };
15766 table& tbl = tbl_ptr->ref_cast<table>();
15767 tbl.is_inline(true);
15768 table_vector_scope table_scope{ open_inline_tables, tbl };
15769
15770 enum class TOML_CLOSED_ENUM parse_type : int
15771 {
15772 none,
15773 comma,
15774 kvp
15775 };
15776 parse_type prev = parse_type::none;
15777 while (!is_error())
15778 {
15779 if constexpr (TOML_LANG_UNRELEASED) // toml/issues/516 (newlines/trailing commas in inline tables)
15780 {
15781 while (consume_leading_whitespace() || consume_line_break() || consume_comment())
15782 continue;
15783 }
15784 else
15785 {
15786 while (consume_leading_whitespace())
15787 continue;
15788 }
15789 return_if_error({});
15790 set_error_and_return_if_eof({});
15791
15792 // commas - only legal after a key-value pair
15793 if (*cp == U',')
15794 {
15795 if (prev == parse_type::kvp)
15796 {
15797 prev = parse_type::comma;
15798 advance_and_return_if_error_or_eof({});
15799 }
15800 else
15801 set_error_and_return_default("expected key-value pair or closing '}', saw comma"sv);
15802 }
15803
15804 // closing '}'
15805 else if (*cp == U'}')
15806 {
15807 if constexpr (!TOML_LANG_UNRELEASED) // toml/issues/516 (newlines/trailing commas in inline tables)
15808 {
15809 if (prev == parse_type::comma)
15810 {
15811 set_error_and_return_default("expected key-value pair, saw closing '}' (dangling comma)"sv);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected