Commit 3c5d82f2 authored by Dominik Charousset's avatar Dominik Charousset

Relax ini syntax for maps

Make '=' for defining maps and ',' for separating key-value pairs
optional. For example, this change allows to rewrite an entry like this:

```
logger = {
  console-verbosity='trace',
  console='colored'
}
```

to a slightly less noisy version such as this:

```
logger {
  console-verbosity='trace'
  console='colored'
}
```
parent 5d3605f3
...@@ -131,10 +131,19 @@ void read_ini_map(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -131,10 +131,19 @@ void read_ini_map(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
} }
// Waits for end-of-line after reading a value // Waits for end-of-line after reading a value
state(after_value) { state(after_value) {
transition(after_value, " \t\n") transition(after_value, " \t")
transition(had_newline, "\n")
transition(await_key_name, ',') transition(await_key_name, ',')
transition(done, '}', consumer.end_map()) transition(done, '}', consumer.end_map())
fsm_epsilon(read_ini_comment(ps, consumer), after_value, ';') fsm_epsilon(read_ini_comment(ps, consumer), had_newline, ';')
}
// Allows users to skip the ',' for separating key/value pairs
state(had_newline) {
transition(had_newline, " \t\n")
transition(await_key_name, ',')
transition(done, '}', consumer.end_map())
fsm_epsilon(read_ini_comment(ps, consumer), had_newline, ';')
epsilon(read_key_name, alnum_or_dash)
} }
term_state(done) { term_state(done) {
//nop //nop
...@@ -220,6 +229,8 @@ void read_ini_section(state<Iterator, Sentinel>& ps, Consumer&& consumer) { ...@@ -220,6 +229,8 @@ void read_ini_section(state<Iterator, Sentinel>& ps, Consumer&& consumer) {
state(await_assignment) { state(await_assignment) {
transition(await_assignment, " \t") transition(await_assignment, " \t")
transition(await_value, '=', emit_key()) transition(await_value, '=', emit_key())
// The '=' is optional for maps, i.e., `key = {}` == `key {}`.
epsilon(await_value, '{', emit_key())
} }
// Reads the value in a "key=value" line. // Reads the value in a "key=value" line.
state(await_value) { state(await_value) {
......
...@@ -124,11 +124,10 @@ some-list=[ ...@@ -124,11 +124,10 @@ some-list=[
"abc", "abc",
'def', ; some comment and a trailing comma 'def', ; some comment and a trailing comma
] ]
some-map={ some-map{
; here we have some list entries ; here we have some list entries
entry1=123, entry1=123,
entry2=23 ; twenty-three! entry2=23 ; twenty-three! btw, comma is not mandatory
,
entry3= "abc", entry3= "abc",
entry4 = 'def', ; some comment and a trailing comma entry4 = 'def', ; some comment and a trailing comma
} }
......
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