Some enums, presented to a macro ...
var enumlist {.compileTime.} : NimNode
macro gettheenums(body : untyped) : untyped =
enumlist = body
result = body
macro letstest(body : typed) : untyped =
echo astGenRepr(enumlist)
gettheenums:
type dtlist = enum e1a,e2a,e3a
type etlist = enum e1b,e1c,e1d
letstest:
var dummy = ""
# the macro prints the enum-related AST....
Run
I want to ask the compiler about enum membership of particular NimIdent Nodes.
I can do it "manually" \- making the enums "statically" available first with a
global `{.compileTime.}` `NimNode` , then parsing through the `nnkStmtList /
nnkTypeSection/nnkTypeDef/nnkEnumTy` Tree. But, since the compiler already made
some typechecks (and the macro got the typed AST) , I would think that the
compiler could resolve the IdentNodes themselves too. (I wouldn't expect it
automatically for the untyped AST though) . How can this be made possible? I
didn't find an appropriate function in the macro API. Is there a simple
solution available? Thanks.