Feature is relatively new. Arguments are of course possible or custom pragmas were of no practical use. The main thing to remember that pragmas are attached to symbols (type NimSym or NimNode of nnkSym kind), so you need look for a way to get a symbol from what you have. Here is an example:
import macros
template mykey(s: string{lit}) {.pragma.}
type
MyObj = object
a1 {.mykey("a").} : int
macro my(t: typedesc): untyped =
echo t.getTypeInst[1].symbol.getImpl.treeRepr
my(MyObj)
You need to use latest Nim dev version to compile my example.
You got it almost correct. Nim has a notion of Symbol. Symbols (procs, typedefs, variables and etc) have many attributes like scope, type and others. Most importantly, symbols have implementations that you can access using getImpl proc and symbol implementations will have pragmas you are looking for.
The rest as you say: NimNodes of the nnkSym kind contain NimSym that can be extract using symbol proc.
P.S. There is more doc in the very last section of https://github.com/nim-lang/Nim/blob/devel/doc/manual/pragmas.txt
I see. My initial attempt looked something like this:
proc test(t: typedesc) {.compileTime.} =
echo t.getTypeImpl.treeRepr
static:
test(MyObj)
This did give me field names and types, but no pragmas. It seems like the pragma information isn't attached directly to the symbol, but to the NimNodes you can get from it, so why doesn't getTypeImpl (as used in my snippet) return the same NimNodes? I'm also confused about the argument received by the macro: it seems to be the unevaluated expression typedesc[MyObj]. Is MyObj just syntax sugar for that? Also, is there a workaround for custom pragmas with parameters in the last stable release, or do I have to use the latest dev version?