From 6b275773e620afe289f18c6ac411593ed30fd4f5 Mon Sep 17 00:00:00 2001 From: c42f Date: Tue, 4 Oct 2022 22:14:52 +1000 Subject: [PATCH 1/3] Tweak to allow vendoring into Base.jl For some reason the previous form used here doesn't work during Base bootstrap. --- src/parser_api.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parser_api.jl b/src/parser_api.jl index 9904e84a..50a7d8ed 100644 --- a/src/parser_api.jl +++ b/src/parser_api.jl @@ -96,7 +96,7 @@ function _parse(rule::Symbol, need_eof::Bool, ::Type{T}, text, index=1; version= tree, last_byte(stream) + 1 end -""" +_parse_docs = """ parse(TreeType, text, [index]; version=VERSION, ignore_trivia=true, @@ -130,12 +130,14 @@ source file name. A `ParseError` will be thrown if any errors or warnings occurred during parsing. To avoid exceptions due to warnings, use `ignore_warnings=true`. """ + parse(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:statement, true, T, text; kws...)[1] parseall(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:toplevel, true, T, text; kws...)[1] parseatom(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:atom, true, T, text; kws...)[1] -@eval @doc $(@doc parse) parseall -@eval @doc $(@doc parse) parseatom +@eval @doc $_parse_docs parse +@eval @doc $_parse_docs parseall +@eval @doc $_parse_docs parseatom parse(::Type{T}, text::AbstractString, index::Integer; kws...) where {T} = _parse(:statement, false, T, text, index; kws...) parseall(::Type{T}, text::AbstractString, index::Integer; kws...) where {T} = _parse(:toplevel, false, T, text, index; kws...) From 557a3dbd6a182834dd643cb30f98ddd6e7e93c49 Mon Sep 17 00:00:00 2001 From: c42f Date: Wed, 5 Oct 2022 11:37:52 +1000 Subject: [PATCH 2/3] Separate sysimage precompile into part which can be used in Base When vendoring into base, pkgdir doesn't exist - we need to pass a path to where it's vendored instead. --- sysimage/precompile.jl | 6 ++++++ sysimage/precompile_exec.jl | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 sysimage/precompile.jl diff --git a/sysimage/precompile.jl b/sysimage/precompile.jl new file mode 100644 index 00000000..a1ae9555 --- /dev/null +++ b/sysimage/precompile.jl @@ -0,0 +1,6 @@ +function precompile_JuliaSyntax(mod, juliasyntax_path) + Base.include(mod, joinpath(juliasyntax_path, "test", "test_utils.jl")) + Base.include(mod, joinpath(juliasyntax_path, "test", "parser.jl")) + JuliaSyntax.enable_in_core!() + Meta.parse("x+y+z-w .+ [a b c]") +end diff --git a/sysimage/precompile_exec.jl b/sysimage/precompile_exec.jl index 567d3d02..99c80693 100644 --- a/sysimage/precompile_exec.jl +++ b/sysimage/precompile_exec.jl @@ -1,5 +1,3 @@ import JuliaSyntax -Base.include(@__MODULE__(), joinpath(pkgdir(JuliaSyntax), "test", "test_utils.jl")) -Base.include(@__MODULE__(), joinpath(pkgdir(JuliaSyntax), "test", "parser.jl")) -JuliaSyntax.enable_in_core!() -Meta.parse("x+y+z-w .+ [a b c]") +include("precompile.jl") +precompile_JuliaSyntax(@__MODULE__(), pkgdir(JuliaSyntax)) From 3f0a061d49b01534e4bcaec44a57a923d77735e0 Mon Sep 17 00:00:00 2001 From: c42f Date: Thu, 6 Oct 2022 12:30:21 +1000 Subject: [PATCH 3/3] Relative include for JuliaSyntax tests This allows these files to be run during precompilation even when JuliaSyntax isn't a standalone module. --- test/parser.jl | 6 +++--- test/test_utils.jl | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/parser.jl b/test/parser.jl index 87b39368..543cad0b 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -1,10 +1,10 @@ function test_parse(production, code; v=v"1.6") stream = ParseStream(code, version=v) - production(JuliaSyntax.ParseState(stream)) - t = JuliaSyntax.build_tree(GreenNode, stream, wrap_toplevel_as_kind=K"None") + production(ParseState(stream)) + t = build_tree(GreenNode, stream, wrap_toplevel_as_kind=K"None") source = SourceFile(code) s = SyntaxNode(source, t) - if JuliaSyntax.kind(s) == K"None" + if kind(s) == K"None" join([sprint(show, MIME("text/x.sexpression"), c) for c in children(s)], ' ') else sprint(show, MIME("text/x.sexpression"), s) diff --git a/test/test_utils.jl b/test/test_utils.jl index d8b52436..a3ab3bbd 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -1,11 +1,10 @@ using Test -using JuliaSyntax -using Base.Meta: @dump - -using JuliaSyntax: +# We need a relative include here as JuliaSyntax my come from Base. +using .JuliaSyntax: # Parsing ParseStream, + ParseState, SourceFile, parse!, parse,