gurkankaymak / hocon

go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config
MIT License
79 stars 17 forks source link

Missing comma error with hyphen-separated key #2

Closed sd65 closed 4 years ago

sd65 commented 4 years ago

Hi,

Thanks for library. I've encountered a strange behaviour. This code :

package main

import (
    "fmt"
    "github.com/gurkankaymak/hocon"
)

func main() {
    hoconString := `
    object1 {
         key-1 = "value1"
    }
    object2.key_2 = "value2"
    object3.key-3 = "value3"
    `
    conf, err := hocon.ParseString(hoconString)
    if err != nil {
      fmt.Println("Error while configuration: ", err)
    }
    fmt.Println(conf)
}

returns this error : missing comma! at: 6:16, values should have comma or ASCII newline ('\n') between them.

The hyphen in key-3 is the culprit here. I believe this is not an expected behaviour cause lightbend/config can parse this configuration without problems.

Can you confirm this is a bug ? Thanks !

sd65 commented 4 years ago

It's actually worse than I thought :

package main

import (
    "fmt"
    "github.com/gurkankaymak/hocon"
)

func main() {
    hoconString := `
    object1 {
         key_0 = "value0"
         key-1 = "value1"
    }
    `
    conf, err := hocon.ParseString(hoconString)
    if err != nil {
      fmt.Println("Error while configuration: ", err)
    }
    fmt.Println(conf)
}

returns {object1:{key_0:value0, 1:value1}}