If I have a statement such as:
let val = "test text"
Then how can I get the AST for val?For the actual AST as in the code, use dumpAstGen from std/macros:
import std/macros
dumpAstGen:
let val = "test text"
For a more readable representation that is very similar but not directly usable code, use dumpTree from the same lib:
import std/macros
dumpTree:
let val = "test text"
Note, that for clarification: That is the AST of the entire statement.
https://nim-lang.org/docs/macros.html#getImpl%2CNimNode
macro getBody(a: typed): untyped =
echo a.getImpl.repr
As you say, what that does is print the statement AST.
What I am really trying to do is get the NimNode value for val, and be able to programmatically interrogate it.