Expronicon provides some tools for macro development. We will go through them in this section.
You can use
@expr to inspect an expression taken by a macro:
julia> @expr 1 + 2 :(1 + 2)
quote ... end or
@expr returns whatever is received by the macro without any modifications. This is useful when you want to check the input of an macro definition. For instance,
quote ... end will return a
Expr(:block, ...) expression, but
@expr will return the expression as is.
julia> @expr begin a = 1 b = 2 a + b end quote #= REPL:2 =# a = 1 #= REPL:3 =# b = 2 #= REPL:4 =# a + b end julia> @expr a + 1 :(a + 1)
Testing generated expressions
Expronicon provides a
@test_expr macro for testing generated expressions. It is similar to
Test package, but it takes
<lhs> = <rhs> where
<rhs> are two expression to compare with each other.
This macro only compares the semantic of the expressions, e.g it will ignore line number nodes, recursive code blocks, etc.
julia> lhs = quote a = 1 b = 2 a + b end julia> rhs = Expr(:block, :(a = 1), :(b = 2), :(a + b)) quote a = 1 b = 2 a + b end julia> lhs == rhs false julia> using Test julia> @test_expr lhs == rhs Test Passed
Test package to be loaded.