From e1c81878cfb31f48aa2353ba070ffe473e88c877 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 19 Jun 2023 14:49:06 +0300 Subject: [PATCH 1/4] make Parsers a weakdep --- Project.toml | 4 ++- ext/ParsersExt.jl | 67 ++++++++++++++++++++++++++++++++++++++++++ src/InlineStrings.jl | 69 +++----------------------------------------- 3 files changed, 74 insertions(+), 66 deletions(-) create mode 100644 ext/ParsersExt.jl diff --git a/Project.toml b/Project.toml index 5d83c58..272d542 100644 --- a/Project.toml +++ b/Project.toml @@ -18,9 +18,11 @@ julia = "1.6" [weakdeps] ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" +Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" [extensions] ArrowTypesExt = "ArrowTypes" +ParsersExt = "Parsers" [targets] -test = ["Arrow", "Test", "Random", "Serialization"] +test = ["Arrow", "Test", "Parsers", "Random", "Serialization"] diff --git a/ext/ParsersExt.jl b/ext/ParsersExt.jl new file mode 100644 index 0000000..99be500 --- /dev/null +++ b/ext/ParsersExt.jl @@ -0,0 +1,67 @@ +module ParsersExt +using Parsers +using InlineStrings: InlineString, InlineString1, addcodeunit + +Parsers.xparse(::Type{T}, buf::AbstractString, pos, len, options, ::Type{S}=T) where {T <: InlineString, S} = + Parsers.xparse(T, codeunits(buf), pos, len, options, S) + +function Parsers.xparse(::Type{T}, source::Union{AbstractVector{UInt8}, IO}, pos, len, options::Parsers.Options, ::Type{S}=T) where {T <: InlineString, S} + res = Parsers.xparse(String, source, pos, len, options, PosLen) + code = res.code + overflowed = false + poslen = res.val + if !Parsers.valueok(code) || Parsers.sentinel(code) + x = T() + else + poslen = res.val + if T === InlineString1 + if poslen.len != 1 + overflowed = true + x = T() + else + Parsers.fastseek!(source, poslen.pos) + x = InlineString1(Parsers.peekbyte(source, poslen.pos)) + Parsers.fastseek!(source, pos + res.tlen - 1) + end + elseif Parsers.escapedstring(code) || !(source isa AbstractVector{UInt8}) + if poslen.len > (sizeof(T) - 1) + overflowed = true + x = T() + else + # manually build up InlineString + i = poslen.pos + maxi = i + poslen.len + x = T() + Parsers.fastseek!(source, i - 1) + while i < maxi + b = Parsers.peekbyte(source, i) + if b == options.e + i += 1 + Parsers.incr!(source) + b = Parsers.peekbyte(source, i) + end + x, overflowed = addcodeunit(x, b) + i += 1 + Parsers.incr!(source) + end + Parsers.fastseek!(source, maxi) + end + else + vlen = poslen.len + if vlen > (sizeof(T) - 1) + # @show T, vlen, sizeof(T) + overflowed = true + x = T() + else + # @show poslen.pos, vlen + x = T(source, poslen.pos, vlen) + end + end + end + if overflowed + code |= Parsers.OVERFLOW + end + return Parsers.Result{S}(code, res.tlen, x) +end + +end diff --git a/src/InlineStrings.jl b/src/InlineStrings.jl index 6a107f1..fe67b2f 100644 --- a/src/InlineStrings.jl +++ b/src/InlineStrings.jl @@ -2,8 +2,6 @@ module InlineStrings import Base: == -using Parsers - export InlineString, InlineStringType, inlinestrings export @inline_str @@ -878,69 +876,6 @@ end end end -# Parsers.xparse -Parsers.xparse(::Type{T}, buf::AbstractString, pos, len, options, ::Type{S}=T) where {T <: InlineString, S} = - Parsers.xparse(T, codeunits(buf), pos, len, options, S) - -function Parsers.xparse(::Type{T}, source::Union{AbstractVector{UInt8}, IO}, pos, len, options::Parsers.Options, ::Type{S}=T) where {T <: InlineString, S} - res = Parsers.xparse(String, source, pos, len, options, PosLen) - code = res.code - overflowed = false - poslen = res.val - if !Parsers.valueok(code) || Parsers.sentinel(code) - x = T() - else - poslen = res.val - if T === InlineString1 - if poslen.len != 1 - overflowed = true - x = T() - else - Parsers.fastseek!(source, poslen.pos) - x = InlineString1(Parsers.peekbyte(source, poslen.pos)) - Parsers.fastseek!(source, pos + res.tlen - 1) - end - elseif Parsers.escapedstring(code) || !(source isa AbstractVector{UInt8}) - if poslen.len > (sizeof(T) - 1) - overflowed = true - x = T() - else - # manually build up InlineString - i = poslen.pos - maxi = i + poslen.len - x = T() - Parsers.fastseek!(source, i - 1) - while i < maxi - b = Parsers.peekbyte(source, i) - if b == options.e - i += 1 - Parsers.incr!(source) - b = Parsers.peekbyte(source, i) - end - x, overflowed = addcodeunit(x, b) - i += 1 - Parsers.incr!(source) - end - Parsers.fastseek!(source, maxi) - end - else - vlen = poslen.len - if vlen > (sizeof(T) - 1) - # @show T, vlen, sizeof(T) - overflowed = true - x = T() - else - # @show poslen.pos, vlen - x = T(source, poslen.pos, vlen) - end - end - end - if overflowed - code |= Parsers.OVERFLOW - end - return Parsers.Result{S}(code, res.tlen, x) -end - ## InlineString sorting using Base.Sort, Base.Order @@ -1138,4 +1073,8 @@ Base.Broadcast.broadcasted(::Type{InlineString}, A::AbstractArray) = inlinestrin Base.map(::Type{InlineString}, A::AbstractArray) = inlinestrings(A) Base.collect(::Type{InlineString}, A::AbstractArray) = inlinestrings(A) +if !isdefined(Base, :get_extension) + include("../ext/ParsersExt.jl") +end + end # module From 9ad22939b1c4785708e4311a1acf9bbc5aaebd43 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 19 Jun 2023 14:49:06 +0300 Subject: [PATCH 2/4] make Parsers a weakdep --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 272d542..0d841f1 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" [extras] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From c79ff0bcbdef846e9ee53d80fee70ec64e24fb20 Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Fri, 12 Jul 2024 14:49:37 +0200 Subject: [PATCH 3/4] reorder the project entries a bit --- Project.toml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 0d841f1..d3417b0 100644 --- a/Project.toml +++ b/Project.toml @@ -6,24 +6,26 @@ version = "1.4.1" [deps] Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -[extras] -Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +[weakdeps] +ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Parsers = "2" julia = "1.6" -[weakdeps] -ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" -Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" - [extensions] ArrowTypesExt = "ArrowTypes" ParsersExt = "Parsers" +[extras] +Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + + + [targets] test = ["Arrow", "Test", "Parsers", "Random", "Serialization"] From 96442fccba9f744bb9b0d70767dbfa59b178487b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 12 Jul 2024 11:03:35 -0700 Subject: [PATCH 4/4] Trim some extra empty lines --- Project.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Project.toml b/Project.toml index d3417b0..53feee6 100644 --- a/Project.toml +++ b/Project.toml @@ -25,7 +25,5 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - - [targets] test = ["Arrow", "Test", "Parsers", "Random", "Serialization"]