Skip to content

Commit 8687254

Browse files
authored
Update Parsers support (#327)
* Update Parsers support Update the Parsers compat versions to `"1, 2"`. As of v1.0.5, `Parsers.tryparse` ensured the full input buffer was consumed when parsing a value (as mentioned desirable in the now-deleted comment in `float_from_bytes`). So dropping support for older Parsers versions allows us to trust `Parsers.tryparse`, and those pre-1.0 versions are pretty old at this point anyway. I locally ran the JSON.jl tests under both Parsers v2.0.1 and v1.1.1 and ensured both were passing, so it shouldn't matter which version of Parsers ends up getting installed if there are other packages which don't 2.0 yet.
1 parent 1c24980 commit 8687254

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1818

1919
[compat]
2020
julia = "0.7, 1.0"
21-
Parsers = "0.1, 0.2, 0.3, 1"
21+
Parsers = "1, 2"
2222

2323
[targets]
2424
test = ["DataStructures", "Distributed", "FixedPointNumbers", "OffsetArrays", "Sockets", "Test"]

src/Parser.jl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,7 @@ byte before `to`. Bytes enclosed should all be ASCII characters.
319319
float_from_bytes(bytes::MemoryParserState, from::Int, to::Int) = float_from_bytes(bytes.utf8, from, to)
320320

321321
function float_from_bytes(bytes::Union{String, Vector{UInt8}}, from::Int, to::Int)::Union{Float64,Nothing}
322-
# Would like to use tryparse, but we want it to consume the full input,
323-
# and the version in Parsers does not do this.
324-
325-
# return Parsers.tryparse(Float64, @view bytes.utf8[from:to])
326-
327-
len = to - from + 1
328-
x, code, vpos, vlen, tlen = Parsers.xparse(Float64, bytes, from, to, Parsers.OPTIONS)
329-
if !Parsers.ok(code) || vlen < len
330-
return nothing
331-
end
332-
return x::Float64
322+
return Parsers.tryparse(Float64, bytes isa String ? SubString(bytes, from:to) : view(bytes, from:to))
333323
end
334324

335325
"""

test/json-checker.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Run modified JSON checker tests
22

3-
const JSON_DATA_DIR = joinpath(dirname(@__DIR__), "data")
3+
const JSON_DATA_DIR = joinpath(dirname(pathof(JSON)), "../data")
44

55
for i in 1:38
66
file = "fail$(lpad(string(i), 2, "0")).json"

0 commit comments

Comments
 (0)