I want to get access to the AST of a complete module (file) with nim. I found, that any macro can be used as a custom pragma, so I did something like this in file foo.nim:
import macros
macro getAst(ast: untyped): untyped =
echo "ast = ", treeRepr(ast)
{.getAst.} # <-- This should invoke the getAst() macro with the AST of the file
proc hello() =
echo "hello world"
But I get compiler error cannot attach a custom pragma to 'foo'
Is there a way to achieve this? I found that I can use the macro as a block macro like so, but I would really prefer to use it via pragma.
getAst:
proc hello() =
echo "hello world"