Commit 115b4fd0 authored by Dominik Charousset's avatar Dominik Charousset

Add a map reader to INI parser

parent 7362662d
......@@ -101,7 +101,52 @@ void read_ini_list(state<Iterator, Sentinel>& ps, Consumer& consumer) {
template <class Iterator, class Sentinel, class Consumer>
void read_ini_map(state<Iterator, Sentinel>& ps, Consumer& consumer) {
// TODO: implement me
std::string key;
auto is_alnum_or_dash = [](char x) {
return isalnum(x) || x == '-' || x == '_';
};
start();
state(init) {
action(is_char<'{'>, await_key_name, consumer.begin_map())
}
state(await_key_name) {
input(is_char<' '>, await_key_name)
input(is_char<'\t'>, await_key_name)
input(is_char<'\n'>, await_key_name)
invoke_fsm_if(is_char<';'>, read_ini_comment(ps, consumer), await_key_name)
action(isalnum, read_key_name, key = ch)
action(is_char<'}'>, done, consumer.end_map())
}
// Reads a key of a "key=value" line.
state(read_key_name) {
action(is_alnum_or_dash, read_key_name, key += ch)
epsilon(await_assignment)
}
// Reads the assignment operator in a "key=value" line.
state(await_assignment) {
input(is_char<' '>, await_assignment)
input(is_char<'\t'>, await_assignment)
action(is_char<'='>, await_value, consumer.key(std::move(key)))
}
// Reads the value in a "key=value" line.
state(await_value) {
input(is_char<' '>, await_value)
input(is_char<'\t'>, await_value)
invoke_fsm(read_ini_value(ps, consumer), after_value)
}
// Waits for end-of-line after reading a value
state(after_value) {
input(is_char<' '>, after_value)
input(is_char<'\t'>, after_value)
input(is_char<'\n'>, after_value)
input(is_char<','>, await_key_name)
action(is_char<'}'>, done, consumer.end_map())
invoke_fsm_if(is_char<';'>, read_ini_comment(ps, consumer), after_value)
}
term_state(done) {
//nop
}
fin();
}
template <class Iterator, class Sentinel, class Consumer>
......
......@@ -103,6 +103,14 @@ some-list=[
"abc",
'def', ; some comment and a trailing comma
]
some-map={
; here we have some list entries
entry1=123,
entry2=23 ; twenty-three!
,
entry3= "abc",
entry4 = 'def', ; some comment and a trailing comma
}
)";
const auto ini0_log = make_log(
......@@ -111,7 +119,9 @@ const auto ini0_log = make_log(
"value: 2000ns", "key: impl", "value: 'foo'", "key: x_",
"value: " + deep_to_string(.123), "key: some-bool", "value: true",
"key: some-other-bool", "value: false", "key: some-list", "[", "value: 123",
"value: 23", "value: \"abc\"", "value: 'def'", "]", "}");
"value: 23", "value: \"abc\"", "value: 'def'", "]", "key: some-map", "{",
"key: entry1", "value: 123", "key: entry2", "value: 23", "key: entry3",
"value: \"abc\"", "key: entry4", "value: 'def'", "}", "}");
} // namespace <anonymous>
......
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