Parsing Inline Tables
jmassara opened this issue · 3 comments
I'm trying to use TOML Inline tables and running into an issue. Given the following program:
package main
import (
"fmt"
"github.com/naoina/toml"
)
const good = `
[heading]
key1 = "value1"
[[heading.array]]
key2 = "value2"
[[heading.array]]
key2 = "value3"
[heading.array.map]
key3 = "value4"
[[heading.array]]
key2 = "value5"
[heading.array.map]
key3 = "value6"
`
const bad = `
[heading]
key1 = "value1"
[[heading.array]]
key2 = "value2"
[[heading.array]]
key2 = "value3"
map = { key3 = "value4" }
[[heading.array]]
key2 = "value5"
map = { key3 = "value6" }
`
func main() {
if _, err := toml.Parse([]byte(good)); err != nil {
fmt.Println(err)
}
if _, err := toml.Parse([]byte(bad)); err != nil {
fmt.Println(err)
}
}
Yields this error:
toml: line 14: table 'map' is in conflict with normal table in line 10
In the bad
config, why does the second definition of map
interfere with the first one? I can change the bad
config to the following and it works fine:
const bad = `
[heading]
key1 = "value1"
[[heading.array]]
key2 = "value2"
[[heading.array]]
key2 = "value3"
map = { key3 = "value4" }
[[heading.array]]
key2 = "value5"
[heading.array.map]
key3 = "value6"
`
Unless I'm mistaken to create a sub value you have to do [heading.array.map]
as you've shown. It fails when doing map = { key3 = "value4" }
because you're trying to create the same variable/key twice. I haven't looked at the spec recently though so I could be wrong.
Yes, it's the same variable/key but inside of a different array element (just like key2
). I would think map = { key3 = "value4" }
is just syntax sugar for specifying it the longer, uglier way.
Ping.