diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3371c5b..45f896d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,3 +38,29 @@ jobs: with: files: lcov.info token: ${{ secrets.CODECOV_TOKEN }} + + parsers-compat: + name: Parsers ${{ matrix.parsers-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + parsers-version: + - '2' + - '3' + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1.10' + - uses: julia-actions/cache@v2 + - name: Test selected Parsers major + shell: julia --color=yes --startup-file=no {0} + env: + PARSERS_VERSION: ${{ matrix.parsers-version }} + run: | + using Pkg + Pkg.activate(mktempdir()) + Pkg.develop(PackageSpec(path=pwd())) + Pkg.add(PackageSpec(name="Parsers", version=ENV["PARSERS_VERSION"])) + Pkg.test("InlineStrings") diff --git a/Project.toml b/Project.toml index 39a6705..942fb1e 100644 --- a/Project.toml +++ b/Project.toml @@ -11,7 +11,7 @@ ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" [compat] -Parsers = "2" +Parsers = "2, 3" julia = "1.6" [extensions] diff --git a/ext/ParsersExt.jl b/ext/ParsersExt.jl index 99885f0..29185f8 100644 --- a/ext/ParsersExt.jl +++ b/ext/ParsersExt.jl @@ -2,6 +2,8 @@ module ParsersExt using Parsers using InlineStrings: InlineString, addcodeunit +if isdefined(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) @@ -55,4 +57,6 @@ function Parsers.xparse(::Type{T}, source::Union{AbstractVector{UInt8}, IO}, pos return Parsers.Result{S}(code, res.tlen, x) end +end # Parsers 2 xparse API + end diff --git a/test/runtests.jl b/test/runtests.jl index cd09c33..f5af026 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,19 @@ using Test, InlineStrings, Parsers, Serialization, Random -import Parsers: SENTINEL, OK, EOF, OVERFLOW, QUOTED, DELIMITED, INVALID_DELIMITER, INVALID_QUOTED_FIELD, ESCAPED_STRING, NEWLINE, SUCCESS + +const _PARSERS_HAS_XPARSE = isdefined(Parsers, :xparse) +if _PARSERS_HAS_XPARSE + import Parsers: SENTINEL, OK, EOF, OVERFLOW, QUOTED, DELIMITED, + INVALID_DELIMITER, INVALID_QUOTED_FIELD, ESCAPED_STRING, + NEWLINE, SUCCESS +end + +@testset "Parsers extension loading" begin + if isdefined(Base, :get_extension) + @test Base.get_extension(InlineStrings, :ParsersExt) isa Module + else + @test isdefined(InlineStrings, :ParsersExt) + end +end const SUBTYPES = ( InlineString1, @@ -381,7 +395,8 @@ end @test String3(a) * String3(b) * String7(b) isa InlineString15 end -@testset "InlineString parsing" begin +if _PARSERS_HAS_XPARSE +@testset "InlineString parsing with Parsers 2" begin testcases = [ ("", InlineString7(""), NamedTuple(), OK | EOF), (" ", InlineString7(" "), NamedTuple(), OK | EOF), @@ -460,6 +475,7 @@ res = Parsers.xparse(InlineString7, buf, pos, len, opts, Any) @test res.val == "abc" end # @testset +end # Parsers 2 xparse API @testset "InlineString Serialization symmetry" begin for str in ("", "🍕", "a", "a"^3, "a"^7, "a"^15, "a"^31, "a"^63, "a"^127, "a"^255)