Skip to content

Commit 9bac746

Browse files
committed
Bug in argument index for macro calls
1 parent 749ca83 commit 9bac746

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/@aml/@aml_parse.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include("@aml_parse/literals.jl")
2+
include("@aml_parse/custom_code.jl")
23

34
"""
45
@aml parser function
@@ -16,11 +17,14 @@ function aml_parse(expr::Expr)
1617

1718
argsexpr = expr.args[3] # arguments of the type
1819

20+
# TODO: optimize and fuse these
1921
areargs_inds = findall(x->!(isa(x, LineNumberNode)), argsexpr.args)
22+
macronum = count(x-> isa(x, Tuple{Symbol, Expr}), argsexpr.args)
2023

2124
data = argsexpr.args[areargs_inds]
25+
2226
datanum = length(areargs_inds)
23-
argsnum = datanum - 1
27+
argsnum = datanum - (1 + macronum) # 1 for struct name
2428

2529
args_param = Vector{Union{Expr,Symbol}}(undef, argsnum) # Expr(:parameters)[]
2630
args_var = Vector{Union{Expr,Symbol}}(undef, argsnum)
@@ -36,10 +40,10 @@ function aml_parse(expr::Expr)
3640
struct_nodetype = AbsDocOrNode
3741
struct_function = Array{Union{Missing, Symbol, Function},0}(missing)
3842

39-
43+
iMacro = 0
4044
for iData = 1:datanum # iterating over arguments of each type argument
4145

42-
iArg = iData-1
46+
iArg = iData - (1+ iMacro)
4347
i = areargs_inds[iData] # used for argsexpr.args[i]
4448

4549
ei = data[iData] # type argument element i
@@ -93,7 +97,7 @@ function aml_parse(expr::Expr)
9397

9498
# Custom Code
9599
elseif isa(ei, Tuple{Symbol, Expr})
96-
100+
iMacro += 1
97101
# Row for code insertion (insert before iArg-th argument)
98102
if ei[1] == :creator
99103
args_custom_creator[iArg] = ei[2]

0 commit comments

Comments
 (0)