Skip to content

Commit 7b80faf

Browse files
committed
Pass file name in Core hook for Expr creation
1 parent 734ac30 commit 7b80faf

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

src/hooks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function core_parser_hook(code, filename, lineno, offset, options)
3535
end
3636

3737
if any_error(stream)
38-
e = Expr(:error, ParseError(SourceFile(code), stream.diagnostics))
38+
e = Expr(:error, ParseError(SourceFile(code, filename=filename), stream.diagnostics))
3939
ex = options === :all ? Expr(:toplevel, e) : e
4040
else
41-
ex = build_tree(Expr, stream, wrap_toplevel_as_kind=K"None")
41+
ex = build_tree(Expr, stream, filename=filename, wrap_toplevel_as_kind=K"None")
4242
if Meta.isexpr(ex, :None)
4343
# The None wrapping is only to give somewhere for trivia to be
4444
# attached; unwrap!

src/source_files.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
SourceFile(code [, filename])
2+
SourceFile(code [; filename=nothing])
33
44
A UTF-8 source code string with associated file name and indexing structures.
55
"""

test/hooks.jl

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
@testset "Hooks for Core integration" begin
2-
JuliaSyntax.enable_in_core!()
2+
@testset "filename is used" begin
3+
ex = JuliaSyntax.core_parser_hook("@a", "somefile", 0, :statement)[1]
4+
@test Meta.isexpr(ex, :macrocall)
5+
@test ex.args[2] == LineNumberNode(1, "somefile")
6+
end
37

4-
@test Meta.parse("x + 1") == :(x + 1)
5-
@test Meta.parse("x + 1", 1) == (:(x + 1), 6)
8+
@testset "enable_in_core!" begin
9+
JuliaSyntax.enable_in_core!()
610

7-
# Test that parsing statements incrementally works and stops after
8-
# whitespace / comment trivia
9-
@test Meta.parse("x + 1\n(y)\n", 1) == (:(x + 1), 7)
10-
@test Meta.parse("x + 1\n(y)\n", 7) == (:y, 11)
11-
@test Meta.parse(" x#==#", 1) == (:x, 7)
11+
@test Meta.parse("x + 1") == :(x + 1)
12+
@test Meta.parse("x + 1", 1) == (:(x + 1), 6)
1213

13-
# Check that Meta.parse throws the JuliaSyntax.ParseError rather than
14-
# Meta.ParseError when Core integration is enabled.
15-
@test_throws JuliaSyntax.ParseError Meta.parse("[x")
14+
# Test that parsing statements incrementally works and stops after
15+
# whitespace / comment trivia
16+
@test Meta.parse("x + 1\n(y)\n", 1) == (:(x + 1), 7)
17+
@test Meta.parse("x + 1\n(y)\n", 7) == (:y, 11)
18+
@test Meta.parse(" x#==#", 1) == (:x, 7)
1619

17-
JuliaSyntax.enable_in_core!(false)
20+
# Check that Meta.parse throws the JuliaSyntax.ParseError rather than
21+
# Meta.ParseError when Core integration is enabled.
22+
@test_throws JuliaSyntax.ParseError Meta.parse("[x")
23+
24+
JuliaSyntax.enable_in_core!(false)
25+
end
1826
end

0 commit comments

Comments
 (0)