Leading zeroes in floating-point indexes raise a TomlError
ziotom78 opened this issue · 4 comments
The following code raises a TomlError exception both under Python2 and Python3:
import pytoml
pytoml.loads("""
# This is a full-line comment
maximum_error = 4.85e-06 # 1 arcsec
""")
The error message is the following:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/local/lib/python2.7/dist-packages/pytoml/parser.py", line 23, in loads
ast = _p_toml(src)
File "/usr/local/lib/python2.7/dist-packages/pytoml/parser.py", line 344, in _p_toml
s.expect_eof()
File "/usr/local/lib/python2.7/dist-packages/pytoml/parser.py", line 124, in expect_eof
return self._expect(self.consume_eof())
File "/usr/local/lib/python2.7/dist-packages/pytoml/parser.py", line 164, in _expect
raise TomlError('msg', self._pos[0], self._pos[1], self._filename)
pytoml.core.TomlError: <string>(3, 24): msg
Removing the leading zero solves the problem:
import pytoml
pytoml.loads("""
# This is a full-line comment
maximum_error = 4.85e-6 # 1 arcsec
""")
# Result: {'maximum_error': 4.85e-06}
Ah, thanks. I'm not sure if leading zeros are allowed in the exponent part or not, so I've opened toml-lang/toml#356. In any case, I don't see a reason why the parser shouldn't be lenient here and I'll make the changes right away.
Thank you for the report!
I take it back, the leading zeroes are explicitly in the invalid test suite, see: https://github.com/avakar/toml-test/blob/master/tests/invalid/exponent-leading-zero-pos.toml. You can argue about the validity of this rule in the issue I opened for toml-lang, but I'll be closing this without a fix.
Ok, I might need to slow down :) The negative test case was only added into my fork of a test suite, the "official" tests do not have it. As such, it might not be the official stance of toml-lang and I'll keep this issue open for now. I'll wait for toml-lang's comment before making any changes to pytoml. Sorry for the chaos.
Since there is no answer on toml-lang, I decided to allow leading zeroes in exponents for now. Released as pytoml-0.1.6.