diff options
author | bptato <nincsnevem662@gmail.com> | 2023-08-26 10:41:09 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-08-26 10:41:09 +0200 |
commit | a11e9468001f19ac3874bec540a5a9cbd94739bc (patch) | |
tree | 60007d530040ef3433fd0086b19118e50b0d4c18 | |
parent | 229f199e4bd3ee17ff368006e6a12448a4e04120 (diff) | |
download | chawan-a11e9468001f19ac3874bec540a5a9cbd94739bc.tar.gz |
toml: various fixes
* Increase line counter on newline in array & inline table parsing * Fix broken inline table parsing
-rw-r--r-- | src/config/toml.nim | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/config/toml.nim b/src/config/toml.nim index a4e13dea..28a022c2 100644 --- a/src/config/toml.nim +++ b/src/config/toml.nim @@ -402,7 +402,8 @@ proc consumeArray(state: var TomlParser): TomlResult = while state.has(): let c = state.consume() case c - of ' ', '\t', '\n': discard + of ' ', '\t': discard + of '\n': inc state.line of ']': if val != nil: res.a.add(val) @@ -427,12 +428,9 @@ proc consumeInlineTable(state: var TomlParser): TomlResult = while state.has(): let c = state.consume() case c - of ' ', '\t', '\n': discard - of '}': - if val != nil: - res.a.add(val) - break - of ',': + of ' ', '\t': discard + of '\n': inc state.line + of ',', '}': if key.len == 0: return state.err("missing key") if val == nil: @@ -450,16 +448,21 @@ proc consumeInlineTable(state: var TomlParser): TomlResult = if k in table.map: return state.err("invalid re-definition of key " & k) table.map[k] = val + val = nil + haskey = false + if c == '}': + return ok(res) else: if val != nil: return state.err("missing comma") if not haskey: + state.reconsume() key = ?state.consumeKey() haskey = true else: state.reconsume() val = ?state.consumeValue() - return ok(res) + return state.err("unexpected end of file") proc consumeValue(state: var TomlParser): TomlResult = while state.has(): |