Skip to content

Commit ece589d

Browse files
authored
Custom cmd macro support + tests for cmd and string macros (#66)
1 parent ef9bd02 commit ece589d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/ast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function makeleaf(ctx, srcref, k::Kind, value; kws...)
143143
graph = syntax_graph(ctx)
144144
if k == K"Identifier" || k == K"core" || k == K"top" || k == K"Symbol" ||
145145
k == K"globalref" || k == K"Placeholder" || k == K"MacroName" ||
146-
k == "StringMacroName" || k == K"CmdMacroName"
146+
k == K"StringMacroName" || k == K"CmdMacroName"
147147
makeleaf(graph, srcref, k; name_val=value, kws...)
148148
elseif k == K"BindingId"
149149
makeleaf(graph, srcref, k; var_id=value, kws...)

src/macro_expansion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function expand_forms_1(ctx::MacroExpansionContext, ex::SyntaxTree)
334334
layerid = get(ex, :scope_layer, current_layer_id(ctx))
335335
makeleaf(ctx, ex, ex, kind=K"Identifier", scope_layer=layerid)
336336
end
337-
elseif k == K"Identifier" || k == K"MacroName" || k == K"StringMacroName"
337+
elseif k == K"Identifier" || k == K"MacroName" || k == K"StringMacroName" || k == K"CmdMacroName"
338338
layerid = get(ex, :scope_layer, current_layer_id(ctx))
339339
makeleaf(ctx, ex, ex, kind=K"Identifier", scope_layer=layerid)
340340
elseif k == K"var" || k == K"char" || k == K"parens"

test/macros_ir.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ module MacroMethods
1515
end
1616
end
1717

18+
macro strmac_str(ex, suff=nothing)
19+
s = "$(ex[1].value) from strmac"
20+
if !isnothing(suff)
21+
s = "$s with suffix $(suff.value)"
22+
end
23+
s
24+
end
25+
26+
macro cmdmac_cmd(ex, suff=nothing)
27+
s = "$(ex[1].value) from cmdmac"
28+
if !isnothing(suff)
29+
s = "$s with suffix $(suff.value)"
30+
end
31+
s
32+
end
33+
1834
#*******************************************************************************
1935
########################################
2036
# Simple macro
@@ -147,3 +163,27 @@ Suggestion: check for spelling errors or missing imports.
147163
5 (call %%₄)
148164
6 (return %₅)
149165

166+
########################################
167+
# Simple string macro
168+
strmac"hello"
169+
#---------------------
170+
1 (return "hello from strmac")
171+
172+
########################################
173+
# String macro with suffix
174+
strmac"hello"blah
175+
#---------------------
176+
1 (return "hello from strmac with suffix blah")
177+
178+
########################################
179+
# Simple cmd macro
180+
cmdmac`hello`
181+
#---------------------
182+
1 (return "hello from cmdmac")
183+
184+
########################################
185+
# Cmd macro with suffix
186+
cmdmac`hello`12345
187+
#---------------------
188+
1 (return "hello from cmdmac with suffix 12345")
189+

0 commit comments

Comments
 (0)