Skip to content

Commit 8c494eb

Browse files
committed
Fix X.at-y do parsing on 1.8+
1 parent 83ca48d commit 8c494eb

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/components/keywords.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function parse_blockexpr_sig(ps::ParseState, head)
246246
if isendoflinews(ps.ws)
247247
return EXPR(:block, EXPR[], nothing)
248248
else
249-
arg = @closer ps :comma @closer ps :ws parse_expression(ps)
249+
arg = @closer ps :comma @closer ps :ws parse_expression(ps)
250250
if iscomma(ps.nt) || !(is_wrapped_assignment(arg) || isidentifier(arg))
251251
arg = EXPR(:block, EXPR[arg])
252252
prevpos = position(ps)
@@ -289,6 +289,7 @@ end
289289
function parse_do(ps::ParseState, pre::EXPR)
290290
args, trivia = EXPR[pre], EXPR[EXPR(next(ps))]
291291
args1, trivia1 = EXPR[], EXPR[]
292+
292293
@closer ps :comma @closer ps :block while !closer(ps)
293294
push!(args1, @closer ps :ws a = parse_expression(ps))
294295
if kindof(ps.nt) === Tokens.COMMA

src/components/operators.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ function parse_operator_where(ps::ParseState, ret::EXPR, op::EXPR, setscope=true
370370
return ret
371371
end
372372

373+
function rewrite_macrocall_quotenode(op, ret, nextarg)
374+
mname = EXPR(op, EXPR[ret, EXPR(:quotenode, EXPR[nextarg.args[1]], nothing)], nothing)
375+
ret = EXPR(:macrocall, EXPR[mname], nextarg.trivia)
376+
for i = 2:length(nextarg.args)
377+
push!(ret, nextarg.args[i])
378+
end
379+
return ret
380+
end
381+
373382
function parse_operator_dot(ps::ParseState, ret::EXPR, op::EXPR)
374383
if kindof(ps.nt) === Tokens.LPAREN
375384
@static if VERSION > v"1.1-"
@@ -405,9 +414,11 @@ function parse_operator_dot(ps::ParseState, ret::EXPR, op::EXPR)
405414
elseif headof(nextarg) === :vect || headof(nextarg) === :braces
406415
ret = EXPR(op, EXPR[ret, EXPR(:quote, EXPR[nextarg], nothing)], nothing)
407416
elseif headof(nextarg) === :macrocall
408-
# TODO : ?
409-
mname = EXPR(op, EXPR[ret, EXPR(:quotenode, EXPR[nextarg.args[1]], nothing)], nothing)
410-
ret = EXPR(:macrocall, EXPR[mname], nextarg.trivia)
417+
ret = rewrite_macrocall_quotenode(op, ret, nextarg)
418+
elseif VERSION >= v"1.8.0-" && headof(nextarg) === :do && headof(nextarg.args[1]) === :macrocall
419+
mcall = rewrite_macrocall_quotenode(op, ret, nextarg.args[1])
420+
421+
ret = EXPR(:do, EXPR[mcall], nextarg.trivia)
411422
for i = 2:length(nextarg.args)
412423
push!(ret, nextarg.args[i])
413424
end

test/parser.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ end
454454
@test "@sprintf(\"%08d\", id)" |> test_expr
455455
@test "[@m @n a for a in A]" |> test_expr # ensure closer.insquare propogates
456456
@test CSTParser.parse("@__DIR__\n\nx", true)[1].span == 8
457+
458+
if VERSION >= v"1.8.0-"
459+
@test "M43018.@test43018() do; end" |> test_expr
460+
@test "@M43018.test43018() do; end" |> test_expr
461+
end
457462
end
458463

459464
@testset "Square " begin

0 commit comments

Comments
 (0)