Skip to content

Commit 38fc0fa

Browse files
authored
Fix bug converting cmd string macros to Expr (#482)
1 parent 0cd5642 commit 38fc0fa

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/expr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ function _internal_node_to_Expr(source, srcrange, head, childranges, childheads,
231231
if k == K"?"
232232
headsym = :if
233233
elseif k == K"macrocall"
234-
if length(args) == 2
234+
if length(args) >= 2
235235
a2 = args[2]
236236
if @isexpr(a2, :macrocall) && kind(childheads[1]) == K"CmdMacroName"
237-
# Fix up for custom cmd macros like `` foo`x` ``
237+
# Fix up for custom cmd macros like foo`x`
238238
args[2] = a2.args[3]
239239
end
240240
end

test/expr.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@
673673
# Custom cmd macros
674674
@test parsestmt("foo`str`") ==
675675
Expr(:macrocall, Symbol("@foo_cmd"), LineNumberNode(1), "str")
676+
@test parsestmt("foo`str`flag") ==
677+
Expr(:macrocall, Symbol("@foo_cmd"), LineNumberNode(1), "str", "flag")
676678
@test parsestmt("foo```\n a\n b```") ==
677679
Expr(:macrocall, Symbol("@foo_cmd"), LineNumberNode(1), "a\nb")
678680
# Expr conversion distinguishes from explicit calls to a macro of the same name

test/parser.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,12 @@ tests = [
452452
"x\"s\"in" => """(macrocall @x_str (string-r "s") "in")"""
453453
"x\"s\"2" => """(macrocall @x_str (string-r "s") 2)"""
454454
"x\"s\"10.0" => """(macrocall @x_str (string-r "s") 10.0)"""
455-
#
455+
# Cmd macro sufficies
456+
"x`s`y" => """(macrocall @x_cmd (cmdstring-r "s") "y")"""
457+
"x`s`end" => """(macrocall @x_cmd (cmdstring-r "s") "end")"""
458+
"x`s`in" => """(macrocall @x_cmd (cmdstring-r "s") "in")"""
459+
"x`s`2" => """(macrocall @x_cmd (cmdstring-r "s") 2)"""
460+
"x`s`10.0" => """(macrocall @x_cmd (cmdstring-r "s") 10.0)"""
456461
],
457462
JuliaSyntax.parse_resword => [
458463
# In normal_context

0 commit comments

Comments
 (0)