pmderodat / ada-toml

TOML parser for Ada
Other
31 stars 5 forks source link

Accepted syntax for tables that is rejected by other parsers #5

Closed mosteo closed 4 years ago

mosteo commented 4 years ago

I've found that master branch accepts these examples with the obvious intended meaning of creating a table:

one.two = false

or the actual case where I found it:

[[one]]
two.three = false

but these are rejected by the Python and JS parsers, and the haskell validator.

See this stackoverflow post I made for a bit more detail.

pmderodat commented 4 years ago

Hello @mosteo,

Thank you for reporting this, and sorry for the late answer. Indeed, the TOML spec seems to completely allow this usage, and I could actually successfully parse the examples you provided on stackoverflow using Python’s toml package (https://pypi.org/project/toml/, version 0.10.0):

$ python
Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import toml
>>> toml.loads('[[somearray]]\none.two = false')
{'somearray': [{'one': {'two': False}}]}
>>> toml.loads('apple.color = "red"')
{'apple': {'color': 'red'}}

Am I missing something?

mosteo commented 4 years ago

Now this is funny. Here's the output I get with stock versions from Ubuntu 18.04:

$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import toml
>>> toml.loads('[[somearray]]\none.two = false')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/toml.py", line 176, in loads
    item + "'. Try quoting the key name.")
toml.TomlDecodeError: Found invalid character in key name: '.'. Try quoting the key name.

The version is older though:

$ apt policy python3-toml
python3-toml:
  Installed: 0.9.3-1
  Candidate: 0.9.3-1

And you're right, with the latest pip version it parses properly.

This is the JS parser I tried that fails: https://runkit.com/embed/kagrz6s6rsrf

However, I have found at least one other that works (not sure what library it's using): https://toml-to-json.matiaskorhonen.fi/

Finally, the haskell validator I used is this one: https://hackage.haskell.org/package/tomlcheck

$ ./tomlcheck -f bad.toml 
bad.toml:2:4:
  |
2 | two.three = false
  |    ^
unexpected '.'
expecting '=' or alphanumeric character

I guess those discrepancies are enough that I open an issue directly in the TOML repo so they clarify.

pmderodat commented 4 years ago

Funny indeed :) Yes, I was going to suggest to ask for an authoritative answer on the TOML standard repository: thank you very much for doing this!

mosteo commented 4 years ago

I must be blind because the examples in the "dotted keys" of the README are explicit about this (ada-toml is right).

pmderodat commented 4 years ago

The issue on the TOML repository was fixed, confirming that ada-toml behaves correctly, so closing this. :-)