You could look at how a block of expressions is normally represented and try to rebuild that. For example
julia> a = quote
a = 1+1
b = a + 4
end
quote
#= REPL[16]:2 =#
a = 1 + 1
#= REPL[16]:3 =#
b = a + 4
end
julia> dump(a)
Expr
head: Symbol block
args: Array{Any}((6,))
1: LineNumberNode
line: Int64 2
file: Symbol REPL[16]
2: Expr
head: Symbol =
args: Array{Any}((2,))
1: Symbol a
2: Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol +
2: Int64 1
3: Int64 1
3: LineNumberNode
line: Int64 3
file: Symbol REPL[16]
4: Expr
head: Symbol =
args: Array{Any}((2,))
1: Symbol b
2: Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol +
2: Symbol a
3: Int64 4
Here the LineNumberNode
is not interesting, but what we see is that we just have an expression with head
being :block
, and the remaining expressions are in the args
. So if you have an array with expressions you could probably do something along the lines of
macro mymacro(args...)
exprs = preprocess(args) # Whatever you do to create the expression list
Expr(:block, exprs...) # Create a block expression with all sub-expressions
end