Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
# Special cases for various expression heads
loc = source_location(LineNumberNode, node.source, node.position)
if headsym === :macrocall
insert!(args, 2, loc)
if args[1] == Symbol("@.")
args[1] = Symbol("@__dot__")
end
reorder_parameters!(args, 2)
insert!(args, 2, loc)
elseif headsym in (:dotcall, :call, :ref)
# Julia's standard `Expr` ASTs have children stored in a canonical
# order which is often not always source order. We permute the children
Expand Down
13 changes: 13 additions & 0 deletions test/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,17 @@
@testset "where" begin
@test parse(Expr, "A where {X, Y; Z}") == Expr(:where, :A, Expr(:parameters, :Z), :X, :Y)
end

@testset "macrocall" begin
# line numbers
@test parse(Expr, "@m\n") == Expr(:macrocall, Symbol("@m"), LineNumberNode(1))
@test parse(Expr, "\n@m") == Expr(:macrocall, Symbol("@m"), LineNumberNode(2))
# parameters
@test parse(Expr, "@m(x; a)") == Expr(:macrocall, Symbol("@m"), LineNumberNode(1),
Expr(:parameters, :a), :x)
@test parse(Expr, "@m(a=1; b=2)") == Expr(:macrocall, Symbol("@m"), LineNumberNode(1),
Expr(:parameters, Expr(:kw, :b, 2)), Expr(:(=), :a, 1))
# @__dot__
@test parse(Expr, "@.") == Expr(:macrocall, Symbol("@__dot__"), LineNumberNode(1))
end
end