Yes, you need result for a macro - it is what the macro's invocation is 
substituted with. That is, the macro not changes in-place what it gets, but 
returns its result.

You can just assign `body` argument to `result`, and then change it item by 
item. Much of what you want.

You may instead create a new statement list for the result - `result = 
newStmtList()`. And then add to it statements, instead of modifying them 
(`result.add ...`).

If you want to create statements from strings (kind with `eval` in interpreted 
languages) - `parseStmt` is what you want. Otherwise there's a bunch of 
`new...` procs in `macros` module.

To get the opposite a source-code representation from a NimNode, use `repr`.  
I.e. `someCode.parseStmt.repr == someCode` should generally hold (except for 
whitespace).  


Yet `result = quote do: some code here` is an easy way to start.

* * *

Code passed to a macro should be a valid Nim code. Probably you cannot use 
those dots at line starts. Just remove them. Add them in your macro.

If you want your passed to the macro code be in arbitrary syntax - then you 
need to use strings (`"""your multiline code here"""`), like is used for `asm` 
statements. Then your `body` argument needs to be a `static[string]`. You'll 
get as just a string, may do any manipulations with it, and use `parseStmt` for 
parsing into NimNodes. 

Reply via email to