Skip to content

Commit 7a5de3a

Browse files
committed
Fix parsing of parenthesized macro names
1 parent 92eac55 commit 7a5de3a

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/parser.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,18 +2335,10 @@ function fix_macro_name_kind!(ps::ParseState, macro_name_position, name_kind=not
23352335
if k == K"var"
23362336
macro_name_position = first_child_position(ps, macro_name_position)
23372337
k = peek_behind(ps, macro_name_position).kind
2338-
elseif k == K")"
2339-
# @(A) x => (macrocall @A x)
2340-
# TODO: Clean this up when K"parens" is implemented
2341-
while true
2342-
macro_name_position = ParseStreamPosition(macro_name_position.token_index-1,
2343-
macro_name_position.range_index-1)
2344-
b = peek_behind(ps, macro_name_position)
2345-
k = b.kind
2346-
if !has_flags(b.flags, TRIVIA_FLAG)
2347-
break
2348-
end
2349-
end
2338+
elseif k == K"parens"
2339+
# @(A) x ==> (macrocall (parens @A) x)
2340+
macro_name_position = first_child_position(ps, macro_name_position)
2341+
k = peek_behind(ps, macro_name_position).kind
23502342
elseif k == K"error"
23512343
# Error already reported in parse_macro_name
23522344
return
@@ -2373,12 +2365,12 @@ function parse_macro_name(ps::ParseState)
23732365
# @var"#" x ==> (macrocall (var #) @$ x)
23742366
bump_disallowed_space(ps)
23752367
mark = position(ps)
2376-
k = peek(ps)
23772368
parse_atom(ps, false)
2378-
if k == K"("
2369+
kb = peek_behind(ps, position(ps)).kind
2370+
if kb == K"parens"
23792371
emit_diagnostic(ps, mark,
23802372
warning="parenthesizing macro names is unnecessary")
2381-
elseif !(peek_behind(ps).kind in KSet"Identifier var")
2373+
elseif !(kb in KSet"Identifier var")
23822374
# @[x] y z ==> (macrocall (error (vect x)) y z)
23832375
emit(ps, mark, K"error", error="invalid macro name")
23842376
end

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ tests = [
321321
"[@foo x]" => "(vect (macrocall @foo x))"
322322
"[@foo]" => "(vect (macrocall @foo))"
323323
"@var\"#\" a" => "(macrocall (var @#) a)" => Expr(:macrocall, Symbol("@#"), LineNumberNode(1), :a)
324+
"@(A) x" => "(macrocall (parens @A) x)"
324325
"A.@x y" => "(macrocall (. A (quote @x)) y)"
325326
"A.@var\"#\" a"=> "(macrocall (. A (quote (var @#))) a)" => Expr(:macrocall, Expr(:., :A, QuoteNode(Symbol("@#"))), LineNumberNode(1), :a)
326327
"@+x y" => "(macrocall @+ x y)"

0 commit comments

Comments
 (0)