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) {
transition(init, " \t\n")
fsm_epsilon(read_ini_comment(ps, consumer), init, ';')
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 '['.
state(start_section) {
......@@ -281,7 +281,10 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
// Wait for the closing ']', preceded by any number of whitespaces.
state(close_section) {
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();
}
......
......@@ -188,8 +188,13 @@ void ini_consumer::value_impl(config_value&& x) {
std::string prev_key;
swap(current_key_, prev_key);
for (auto& entry : *dict) {
if (holds_alternative<dict_type>(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_);
}
......
......@@ -46,15 +46,15 @@ impl = 'foo';some atom
const char test_ini2[] = R"(
is_server = true
port = 4242
nodes = ["sun", "venus"]
logger = {
file-name = "foobar.ini"
}
port = 4242
scheduler = {
timing = 2us,
impl = 'foo'
}
nodes = ["sun", "venus"]
)";
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