chimpler / pyhocon

HOCON parser for Python
Apache License 2.0
502 stars 118 forks source link

Assignment of variables with underscore in their name causes pyparsing exception #312

Open gafniguy opened 1 year ago

gafniguy commented 1 year ago

With the following config file,

model{
    d_in = 3
    d_out = 2
}

I ran ConfigFactory.parse_file('./confs/test2.conf') and get an exception:

pyparsing.exceptions.ParseSyntaxException: , found '=' (at char 30), (line:3, col:11)

If I change d_out to e_out, or comment one of them out, or remove the underscore in at least one of their names, I will get no exception.

I get this with Python 3.11.3, Python 3.8.17 and pyparsing 3.1.0 and pyparsing 3.0.8

GuillaumeLeclerc commented 1 year ago

Cam for the exact same problem and from the name of the variables I assume from the same repository :wink: I guess the best is to just rename the parameters at this point

GuillaumeLeclerc commented 1 year ago

Actually pip install pyhocon==0.3.57 works

viktor-dolniik commented 12 months ago

Happens to me with this config

x = 1
y = 1

so the issue is probably not related to underscores or nestedness.

When I reorder the parameters:

y = 1
x = 1

it is parsed correctly. Changing the values to float solves the issue as well.

pierresouchay commented 4 months ago

That's a duplicate of https://github.com/chimpler/pyhocon/issues/324 and has been fixed by https://github.com/chimpler/pyhocon/pull/326 -> fixed in version 0.3.61: https://github.com/chimpler/pyhocon/releases/tag/0.3.61

=> Basically, variables with names starting with possible durations (ex: d_hello (d=day) or y_me (y=year) were incorrectly parsed if using "\n" with values, but fixed now

=> You can close this issue