I want to use NimNode at runtime, simply because it's the genuine supported AST spec. I also want to use 'repr' on it, because it's the easiest way to get Nim text from the tree. It seems I cannot do it. What can I do instead at runtime? Let's say I want to build the tree from json handed me at runtime.
I see there's an internal unsupported -d:nimCompilerApi -- it's the next pragmatic option, working on PNode instead. But I feel I am missing the noble way to do this. What am I missing? What is the proper way to do this?
Depends on what you're trying to do. It's not possible for example to use the NimNodes at all during compile-time, apart from spitting out code of course. But this code then has to be compiled, so you can't use it for runtime metaprogramming.
The compiler itself is one of the biggest programs dealing with Nim code on runtime and the way it parses, creates, and renders this code is through PNodes. So that's probably what would be considered the "proper" way. But again, it all depends on what you're trying to achieve.