From f9b224c222bca468e4a0878373a31ed13d04cbe7 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 12 Feb 2023 02:55:03 +0900 Subject: [PATCH] fix: reopening table implicitly defined by aot --- toml/parser.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/toml/parser.hpp b/toml/parser.hpp index 47b777b..06e0324 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -1305,6 +1305,8 @@ std::string format_dotted_keys(InputIterator first, const InputIterator last) // forward decl for is_valid_forward_table_definition result, region>, std::string> parse_table_key(location& loc); +result, region>, std::string> +parse_array_table_key(location& loc); template result, std::string> parse_inline_table(location& loc); @@ -1420,6 +1422,21 @@ bool is_valid_forward_table_definition(const Value& fwd, const Value& inserting, // the keys are not equivalent. it is allowed. return true; } + // nested array-of-table definition implicitly defines tables. + // those tables can be reopened. + if(const auto atabkeys = parse_array_table_key(def)) + { + // table keys always contains all the nodes from the root. + const auto& tks = atabkeys.unwrap().first; + if(std::size_t(std::distance(key_first, key_last)) == tks.size() && + std::equal(tks.begin(), tks.end(), key_first)) + { + // the keys are equivalent. it is not allowed. + return false; + } + // the keys are not equivalent. it is allowed. + return true; + } if(const auto dotkeys = parse_key(def)) // a.b.c = "foo" { // consider the following case.