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...) 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)) 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,