Skip to content

Commit 7b23532

Browse files
authored
Tweaks to allow vendoring into Base (#119)
* Simplify `@doc` usage for use in Base bootstrap. * 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. * Relative include for JuliaSyntax tests. This allows these files to be run during precompilation even when JuliaSyntax isn't a standalone module.
1 parent 6465cce commit 7b23532

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/parser_api.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function _parse(rule::Symbol, need_eof::Bool, ::Type{T}, text, index=1; version=
9696
tree, last_byte(stream) + 1
9797
end
9898

99-
"""
99+
_parse_docs = """
100100
parse(TreeType, text, [index];
101101
version=VERSION,
102102
ignore_trivia=true,
@@ -130,12 +130,14 @@ source file name.
130130
A `ParseError` will be thrown if any errors or warnings occurred during
131131
parsing. To avoid exceptions due to warnings, use `ignore_warnings=true`.
132132
"""
133+
133134
parse(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:statement, true, T, text; kws...)[1]
134135
parseall(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:toplevel, true, T, text; kws...)[1]
135136
parseatom(::Type{T}, text::AbstractString; kws...) where {T} = _parse(:atom, true, T, text; kws...)[1]
136137

137-
@eval @doc $(@doc parse) parseall
138-
@eval @doc $(@doc parse) parseatom
138+
@eval @doc $_parse_docs parse
139+
@eval @doc $_parse_docs parseall
140+
@eval @doc $_parse_docs parseatom
139141

140142
parse(::Type{T}, text::AbstractString, index::Integer; kws...) where {T} = _parse(:statement, false, T, text, index; kws...)
141143
parseall(::Type{T}, text::AbstractString, index::Integer; kws...) where {T} = _parse(:toplevel, false, T, text, index; kws...)

sysimage/precompile.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function precompile_JuliaSyntax(mod, juliasyntax_path)
2+
Base.include(mod, joinpath(juliasyntax_path, "test", "test_utils.jl"))
3+
Base.include(mod, joinpath(juliasyntax_path, "test", "parser.jl"))
4+
JuliaSyntax.enable_in_core!()
5+
Meta.parse("x+y+z-w .+ [a b c]")
6+
end

sysimage/precompile_exec.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import JuliaSyntax
2-
Base.include(@__MODULE__(), joinpath(pkgdir(JuliaSyntax), "test", "test_utils.jl"))
3-
Base.include(@__MODULE__(), joinpath(pkgdir(JuliaSyntax), "test", "parser.jl"))
4-
JuliaSyntax.enable_in_core!()
5-
Meta.parse("x+y+z-w .+ [a b c]")
2+
include("precompile.jl")
3+
precompile_JuliaSyntax(@__MODULE__(), pkgdir(JuliaSyntax))

test/parser.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function test_parse(production, code; v=v"1.6")
22
stream = ParseStream(code, version=v)
3-
production(JuliaSyntax.ParseState(stream))
4-
t = JuliaSyntax.build_tree(GreenNode, stream, wrap_toplevel_as_kind=K"None")
3+
production(ParseState(stream))
4+
t = build_tree(GreenNode, stream, wrap_toplevel_as_kind=K"None")
55
source = SourceFile(code)
66
s = SyntaxNode(source, t)
7-
if JuliaSyntax.kind(s) == K"None"
7+
if kind(s) == K"None"
88
join([sprint(show, MIME("text/x.sexpression"), c) for c in children(s)], ' ')
99
else
1010
sprint(show, MIME("text/x.sexpression"), s)

test/test_utils.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using Test
2-
using JuliaSyntax
32

4-
using Base.Meta: @dump
5-
6-
using JuliaSyntax:
3+
# We need a relative include here as JuliaSyntax my come from Base.
4+
using .JuliaSyntax:
75
# Parsing
86
ParseStream,
7+
ParseState,
98
SourceFile,
109
parse!,
1110
parse,

0 commit comments

Comments
 (0)