Skip to content

Commit 2ec75d6

Browse files
authored
Fix a small bug in the TOML parser and add an example of printing to a file (#40208)
fix the TOML parser to parse 0e-3 and add an example of writing to a file
1 parent 40267bb commit 2ec75d6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

base/toml_parser.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,6 @@ function parse_number_or_date_start(l::Parser)
821821
ate && return parse_int(l, contains_underscore)
822822
elseif accept(l, isdigit)
823823
return parse_local_time(l)
824-
elseif peek(l) !== '.'
825-
return ParserError(ErrLeadingZeroNotAllowedInteger)
826824
end
827825
end
828826

stdlib/TOML/docs/src/index.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ format.
6565
```jldoctest
6666
julia> using TOML
6767
68-
julia> fname = tempname();
69-
7068
julia> data = Dict(
7169
"names" => ["Julia", "Julio"],
7270
"age" => [10, 20],
@@ -75,6 +73,17 @@ julia> data = Dict(
7573
julia> TOML.print(data)
7674
names = ["Julia", "Julio"]
7775
age = [10, 20]
76+
77+
julia> fname = tempname();
78+
79+
julia> open(fname, "w") do io
80+
TOML.print(io, data)
81+
end
82+
83+
julia> TOML.parsefile(fname)
84+
Dict{String, Any} with 2 entries:
85+
"names" => ["Julia", "Julio"]
86+
"age" => [10, 20]
7887
```
7988

8089
Keys can be sorted according to some value

stdlib/TOML/test/values.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ end
3939
@test testval("1.0e0" , 1.0)
4040
@test testval("1.0e+0" , 1.0)
4141
@test testval("1.0e-0" , 1.0)
42+
@test testval("0e-3" , 0.0)
4243
@test testval("1.001e-0" , 1.001)
4344
@test testval("2e10" , 2e10)
4445
@test testval("2e+10" , 2e10)
@@ -53,8 +54,8 @@ end
5354
@test testval("+1_000" , 1000 |> Int64)
5455
@test testval("-1_000" , -1000 |> Int64)
5556

56-
@test failval("0_" , Internals.ErrLeadingZeroNotAllowedInteger)
57-
@test failval("0__0" , Internals.ErrLeadingZeroNotAllowedInteger)
57+
@test failval("0_" , Internals.ErrUnderscoreNotSurroundedByDigits)
58+
@test failval("0__0" , Internals.ErrUnderscoreNotSurroundedByDigits)
5859
@test failval("__0" , Internals.ErrUnexpectedStartOfValue)
5960
@test failval("1_0_" , Internals.ErrTrailingUnderscoreNumber)
6061
@test failval("1_0__0" , Internals.ErrUnderscoreNotSurroundedByDigits)

0 commit comments

Comments
 (0)