From 73ba6b385fb956107bd50fc985522be342e2ea05 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 27 Feb 2019 01:02:39 +0900 Subject: [PATCH] feat: use key-region to represent table use x.y.z = 42 ~~~ here as the region of the table `x.y` --- toml/parser.hpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 02d1fe8..f850b67 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -988,10 +988,11 @@ std::string format_dotted_keys(InputIterator first, const InputIterator last) return retval; } -template +template result insert_nested_key(table& root, const toml::value& v, InputIterator iter, const InputIterator last, + region key_reg, const bool is_array_of_table = false) { static_assert(std::is_sameinsert(std::make_pair(k, aot)); return ok(true); } @@ -1126,10 +1123,7 @@ insert_nested_key(table& root, const toml::value& v, // [x.y.z] if(tab->count(k) == 0) { - // the region of [x.y] is the same as [x.y.z]. - (*tab)[k] = v; // copy region_info_ - detail::assign_keeping_region((*tab)[k], - ::toml::value(::toml::table{})); + (*tab)[k] = toml::value(toml::table{}, key_reg); } // type checking... @@ -1194,11 +1188,11 @@ parse_inline_table(location& loc) return err(kv_r.unwrap_err()); } const std::vector& keys = kv_r.unwrap().first.first; -// const region& key_reg = kv_r.unwrap().first.second; + const region& key_reg = kv_r.unwrap().first.second; const value& val = kv_r.unwrap().second; const auto inserted = - insert_nested_key(retval, val, keys.begin(), keys.end()); + insert_nested_key(retval, val, keys.begin(), keys.end(), key_reg); if(!inserted) { throw internal_error("[error] toml::parse_inline_table: " @@ -1376,10 +1370,10 @@ result parse_ml_table(location& loc) if(const auto kv = parse_key_value_pair(loc)) { const std::vector& keys = kv.unwrap().first.first; -// const region& key_reg = kv_r.unwrap().first.second; + const region& key_reg = kv.unwrap().first.second; const value& val = kv.unwrap().second; const auto inserted = - insert_nested_key(tab, val, keys.begin(), keys.end()); + insert_nested_key(tab, val, keys.begin(), keys.end(), key_reg); if(!inserted) { return err(inserted.unwrap_err()); @@ -1457,7 +1451,8 @@ result parse_toml_file(location& loc) const auto inserted = insert_nested_key(data, toml::value(tab.unwrap(), reg), - keys.begin(), keys.end(), /*is_array_of_table=*/ true); + keys.begin(), keys.end(), reg, + /*is_array_of_table=*/ true); if(!inserted) {return err(inserted.unwrap_err());} continue; @@ -1471,7 +1466,7 @@ result parse_toml_file(location& loc) const auto& reg = tabkey.unwrap().second; const auto inserted = insert_nested_key(data, - toml::value(tab.unwrap(), reg), keys.begin(), keys.end()); + toml::value(tab.unwrap(), reg), keys.begin(), keys.end(), reg); if(!inserted) {return err(inserted.unwrap_err());} continue;