From eb96dd07f0482f399e95d3081ef71527d76c89d4 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 26 Mar 2021 11:14:19 +0100 Subject: [PATCH 1/3] fix the TOML parser to parse 0e-3 --- base/toml_parser.jl | 2 -- stdlib/TOML/test/values.jl | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/base/toml_parser.jl b/base/toml_parser.jl index c69096504df0b..956c62196d6b8 100644 --- a/base/toml_parser.jl +++ b/base/toml_parser.jl @@ -821,8 +821,6 @@ function parse_number_or_date_start(l::Parser) ate && return parse_int(l, contains_underscore) elseif accept(l, isdigit) return parse_local_time(l) - elseif peek(l) !== '.' - return ParserError(ErrLeadingZeroNotAllowedInteger) end end diff --git a/stdlib/TOML/test/values.jl b/stdlib/TOML/test/values.jl index 9f09e26b01cda..8337bb5a54714 100644 --- a/stdlib/TOML/test/values.jl +++ b/stdlib/TOML/test/values.jl @@ -39,6 +39,7 @@ end @test testval("1.0e0" , 1.0) @test testval("1.0e+0" , 1.0) @test testval("1.0e-0" , 1.0) + @test testval("0e-3" , 0.0) @test testval("1.001e-0" , 1.001) @test testval("2e10" , 2e10) @test testval("2e+10" , 2e10) @@ -53,8 +54,8 @@ end @test testval("+1_000" , 1000 |> Int64) @test testval("-1_000" , -1000 |> Int64) - @test failval("0_" , Internals.ErrLeadingZeroNotAllowedInteger) - @test failval("0__0" , Internals.ErrLeadingZeroNotAllowedInteger) + @test failval("0_" , Internals.ErrUnderscoreNotSurroundedByDigits) + @test failval("0__0" , Internals.ErrUnderscoreNotSurroundedByDigits) @test failval("__0" , Internals.ErrUnexpectedStartOfValue) @test failval("1_0_" , Internals.ErrTrailingUnderscoreNumber) @test failval("1_0__0" , Internals.ErrUnderscoreNotSurroundedByDigits) From 54c4bd08cc0d92acbf415800eb90e310553f146d Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 26 Mar 2021 11:15:57 +0100 Subject: [PATCH 2/3] add an example of writing to a file --- stdlib/TOML/docs/src/index.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stdlib/TOML/docs/src/index.md b/stdlib/TOML/docs/src/index.md index e34bb8d85f2f1..1fa81cc3c19d6 100644 --- a/stdlib/TOML/docs/src/index.md +++ b/stdlib/TOML/docs/src/index.md @@ -65,8 +65,6 @@ format. ```jldoctest julia> using TOML -julia> fname = tempname(); - julia> data = Dict( "names" => ["Julia", "Julio"], "age" => [10, 20], @@ -75,6 +73,17 @@ julia> data = Dict( julia> TOML.print(data) names = ["Julia", "Julio"] age = [10, 20] + +julia> fname = tempname(); + +julia> open(fname, "w") do io + TOML.print(io, data) + end + +julia> TOML.parsefile(fname) +Dict{String, Any} with 2 entries: + "names" => ["Julia", "Julio"] + "age" => [10, 20] ``` Keys can be sorted according to some value From 8899ab2a4025149483c4d7747661be90f3addbd6 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Fri, 26 Mar 2021 15:02:40 +0100 Subject: [PATCH 3/3] fix spacing --- stdlib/TOML/docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/TOML/docs/src/index.md b/stdlib/TOML/docs/src/index.md index 1fa81cc3c19d6..36e8ec6248108 100644 --- a/stdlib/TOML/docs/src/index.md +++ b/stdlib/TOML/docs/src/index.md @@ -78,7 +78,7 @@ julia> fname = tempname(); julia> open(fname, "w") do io TOML.print(io, data) - end + end julia> TOML.parsefile(fname) Dict{String, Any} with 2 entries: