Is there any way for a macro to expand nested macros during its evaluation?
For example, if there are macros foo(x) and bar() and we write:
foo(bar())
Is it possible for foo to access the AST which would be generated by bar?
If foo has typed argument then bar() is evaluated first and then resulting AST is passed as argument. Note that bar's output AST would be fully expanded before being passed to foo
macro bar(): untyped = newLit("bar-expanded")
macro foo(arg: typed) = echo arg.treeRepr()
foo(bar())
StrLit "bar-expanded"
If foo has untyped argument then it would simply accept bar()
macro bar(): untyped = newLit("bar-expanded")
macro foo(arg: untyped) = echo arg.treeRepr()
foo(bar())
Call
Ident "bar"