naoina / toml

TOML parser and encoder library for Golang
MIT License
294 stars 50 forks source link

This does not parse, while being toml v0.4.0 compliant. #7

Closed evertheylen closed 7 years ago

evertheylen commented 9 years ago

This does not parse, and it should, according to the spec.


[irc_servers]
    freenode = "chat.freenode.net:8001"
    quakenet = "irc.quakenet.org:6667"

[users]
    [users.alice]
        nick = "tester_Alice"
        name = "Alice"
        channels = {freenode = ["#test123456", "#test1234567"], quakenet = ["#xonotic"]}

    [users.bob]
        nick = "tester_Bob"
        name = "Bob"
        channels = {freenode = ["#test123456"], quakenet = ["#xonotic", "#quake"]}

I have also tested this with https://github.com/avakar/pytoml, which can parse this without problems.

I use these structs:

type TomlUser struct {
    Nick string
    Name string
    Channels map[string][]string
}

type TomlConfig struct {
    IrcServers map[string]string
    Users map[string]TomlUser
}

Full example program: http://play.golang.org/p/-qWU5Y0RW-

Gives me this error:

panic: toml:http://play.golang.org/p/aeGl88Vog5

goroutine 1 [running]:
main.main()
        /tmp/test/marshltest.go:40 +0xdf

goroutine 5 [chan send]:
github.com/naoina/toml.(*tokens16).Tokens.func1(0xc82001a300, 0xc8200d8000)
        /Bestanden/Arch/Go/src/github.com/naoina/toml/parse.peg.go:466 +0x134
created by github.com/naoina/toml.(*tokens16).Tokens
        /Bestanden/Arch/Go/src/github.com/naoina/toml/parse.peg.go:469 +0x5d
exit status 2

If I replace map[string]string with []string it does work: http://play.golang.org/p/mtLIcqURv5.