Something similar to this partly works:
import macros
proc parseCustomStmt(code: string): NimNode {.compileTime.} =
let tree = parseStmt(code)
tree
macro parseAndVisit(code: static[string]): void =
let tree = parseCustomStmt(code)
proc visit(n: NimNode): void =
case n.kind
of nnkStmtList, nnkBlockStmt:
for child in n:
visit(child)
of nnkProcDef:
echo "Found procedure declaration: ", n[0].strVal
for child in n[2]:
visit(child)
of nnkAsgn:
echo "Found assignment to: ", n[0].strVal
visit(n[1])
of nnkCall:
echo "Found function call to: ", n[0].strVal
for arg in n[1..^1]:
visit(arg)
else:
discard
visit(tree)
parseAndVisit("""
proc foo(x, y: int): int =
let z = x
return z
""")
Run
The nodes in the function body are not triggered though. Not sure why.