Commit fde9e45b authored by Dominik Charousset's avatar Dominik Charousset

Allow users to omit [global] in config file

parent a4d0e2ef
...@@ -239,7 +239,7 @@ void read_ini_section(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -239,7 +239,7 @@ void read_ini_section(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
template <class Iterator, class Sentinel, class Consumer> template <class Iterator, class Sentinel, class Consumer>
void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) { void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
using std::swap; using std::swap;
std::string tmp; std::string tmp{"global"};
auto alnum_or_dash = [](char x) { auto alnum_or_dash = [](char x) {
return isalnum(x) || x == '-' || x == '_'; return isalnum(x) || x == '-' || x == '_';
}; };
...@@ -255,6 +255,7 @@ void read_ini(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -255,6 +255,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)
} }
// Read the section key after reading an '['. // Read the section key after reading an '['.
state(start_section) { state(start_section) {
......
...@@ -155,7 +155,8 @@ ini_consumer* ini_category_consumer::dparent() { ...@@ -155,7 +155,8 @@ ini_consumer* ini_category_consumer::dparent() {
ini_consumer::ini_consumer(config_option_set& options, settings& cfg) ini_consumer::ini_consumer(config_option_set& options, settings& cfg)
: options_(options), : options_(options),
cfg_(cfg) { cfg_(cfg),
current_key("global") {
// nop // nop
} }
......
...@@ -34,7 +34,6 @@ using ls = std::vector<std::string>; ...@@ -34,7 +34,6 @@ using ls = std::vector<std::string>;
namespace { namespace {
const char test_ini[] = R"( const char test_ini[] = R"(
[global]
is_server=true is_server=true
port=4242 port=4242
nodes=["sun", "venus", ] nodes=["sun", "venus", ]
...@@ -45,6 +44,19 @@ file-name = "foobar.ini" ; our file name ...@@ -45,6 +44,19 @@ file-name = "foobar.ini" ; our file name
impl = 'foo';some atom impl = 'foo';some atom
)"; )";
const char test_ini2[] = R"(
is_server = true
port = 4242
nodes = ["sun", "venus"]
logger = {
file-name = "foobar.ini"
}
scheduler = {
timing = 2us,
impl = 'foo'
}
)";
struct fixture { struct fixture {
detail::parser::state<std::string::const_iterator> res; detail::parser::state<std::string::const_iterator> res;
config_option_set options; config_option_set options;
...@@ -90,4 +102,27 @@ CAF_TEST(ini_consumer) { ...@@ -90,4 +102,27 @@ CAF_TEST(ini_consumer) {
CAF_CHECK_EQUAL(get<atom_value>(config, "scheduler.impl"), atom("foo")); CAF_CHECK_EQUAL(get<atom_value>(config, "scheduler.impl"), atom("foo"));
} }
CAF_TEST(simplified syntax) {
std::string str = test_ini;
CAF_MESSAGE("read test_ini");
{
detail::ini_consumer consumer{options, config};
res.i = str.begin();
res.e = str.end();
detail::parser::read_ini(res, consumer);
CAF_CHECK_EQUAL(res.code, pec::success);
}
str = test_ini2;
settings config2;
CAF_MESSAGE("read test_ini2");
{
detail::ini_consumer consumer{options, config2};
res.i = str.begin();
res.e = str.end();
detail::parser::read_ini(res, consumer);
CAF_CHECK_EQUAL(res.code, pec::success);
}
CAF_CHECK_EQUAL(config, config2);
}
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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