Commit 26a7221c authored by Dominik Charousset's avatar Dominik Charousset

Fix handling of top-level config values

parent 20b62978
...@@ -266,7 +266,7 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -266,7 +266,7 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
transition(init, " \t\n") transition(init, " \t\n")
fsm_epsilon(read_ini_comment(ps, consumer), init, ';') fsm_epsilon(read_ini_comment(ps, consumer), init, ';')
transition(start_section, '[') transition(start_section, '[')
fsm_epsilon_if(tmp == "global", read_ini_section(ps, begin_section()), init) fsm_epsilon_if(tmp == "global", read_ini_section(ps, begin_section()), return_to_global)
} }
// Read the section key after reading an '['. // Read the section key after reading an '['.
state(start_section) { state(start_section) {
...@@ -281,7 +281,10 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -281,7 +281,10 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
// Wait for the closing ']', preceded by any number of whitespaces. // Wait for the closing ']', preceded by any number of whitespaces.
state(close_section) { state(close_section) {
transition(close_section, " \t") transition(close_section, " \t")
fsm_transition(read_ini_section(ps, begin_section()), init, ']') fsm_transition(read_ini_section(ps, begin_section()), return_to_global, ']')
}
unstable_state(return_to_global) {
epsilon(init, any_char, tmp = "global")
} }
fin(); fin();
} }
......
...@@ -188,8 +188,13 @@ void ini_consumer::value_impl(config_value&& x) { ...@@ -188,8 +188,13 @@ void ini_consumer::value_impl(config_value&& x) {
std::string prev_key; std::string prev_key;
swap(current_key_, prev_key); swap(current_key_, prev_key);
for (auto& entry : *dict) { for (auto& entry : *dict) {
current_key_ = std::move(entry.first); if (holds_alternative<dict_type>(entry.second)) {
value_impl(std::move(entry.second)); // Recurse into top-level maps.
current_key_ = std::move(entry.first);
value_impl(std::move(entry.second));
} else {
cfg_.insert_or_assign(entry.first, std::move(entry.second));
}
} }
swap(prev_key, current_key_); swap(prev_key, current_key_);
} }
......
...@@ -46,15 +46,15 @@ impl = 'foo';some atom ...@@ -46,15 +46,15 @@ impl = 'foo';some atom
const char test_ini2[] = R"( const char test_ini2[] = R"(
is_server = true is_server = true
port = 4242
nodes = ["sun", "venus"]
logger = { logger = {
file-name = "foobar.ini" file-name = "foobar.ini"
} }
port = 4242
scheduler = { scheduler = {
timing = 2us, timing = 2us,
impl = 'foo' impl = 'foo'
} }
nodes = ["sun", "venus"]
)"; )";
struct fixture { struct fixture {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment