JuliaLang / TOML.jl

A fast TOML parser for TOML 1.0 written in Julia
MIT License
34 stars 15 forks source link

Exp float 0e-3 not parsing #19

Closed jaakkor2 closed 3 years ago

jaakkor2 commented 3 years ago

This is with Julia v1.6.0

using TOML
TOML.parse("a=0e-3")

gives

ERROR: TOML Parser error:
none:1:3 error: leading zero in integer not allowed
  a=0e-3
    ^
Stacktrace:
 [1] parse
   @ .\toml_parser.jl:441 [inlined]
 [2] parse(str::String)
   @ TOML C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\TOML\src\TOML.jl:71
 [3] top-level scope
   @ REPL[14]:1

This works

TOML.parse("a=1e-3")
Dict{String, Any} with 1 entry:
  "a" => 0.001

https://toml.io/en/v1.0.0#float does not say 0e-3 should not work.

Online https://toml-parser.com/ parser reads a=0e-3 just fine.

Julia parses parse(Float64, "0e-3") fine as well.

KristofferC commented 3 years ago

The spec says that for float, leading zeros are not allowed, for example:

a = 03.14

errors in https://toml-parser.com/ (but parse(Float64, "03.14")) works. So leading zeros are not allowed in 03.14 but allowed in 0e-3?

jaakkor2 commented 3 years ago

https://toml-parser.com/ says for a=00e-3

Error while parsing floating-point: leading zeroes are prohibited (error occurred at line 1, column 4)

KristofferC commented 3 years ago

Okay, the part before the . or the exponential part parses as an integer. So 0 is fine before e-3 because the integer 0 is valid integer. 03 is not fine before .14 because 03 is not a valid integer.