Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading zeroes in floating-point indexes raise a TomlError #9

Closed
ziotom78 opened this issue Oct 6, 2015 · 4 comments
Closed

Leading zeroes in floating-point indexes raise a TomlError #9

ziotom78 opened this issue Oct 6, 2015 · 4 comments

Comments

@ziotom78
Copy link

ziotom78 commented Oct 6, 2015

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}
@avakar
Copy link
Owner

avakar commented Oct 6, 2015

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!

@avakar
Copy link
Owner

avakar commented Oct 6, 2015

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.

@avakar avakar closed this as completed Oct 6, 2015
@avakar
Copy link
Owner

avakar commented Oct 6, 2015

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.

@avakar avakar reopened this Oct 6, 2015
@avakar avakar closed this as completed in cd2a796 Oct 8, 2015
@avakar
Copy link
Owner

avakar commented Oct 8, 2015

Since there is no answer on toml-lang, I decided to allow leading zeroes in exponents for now. Released as pytoml-0.1.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants