> This is the result of dumpTree
... for something else, not for your example ;)
* * *
I have made your macro, but I won't (yet) post a complete solution. I'll try to
guide you so you can make it on your own.
This is what I have before I even start with macro:
import macros
type MyObject = object
aProperty1: int
aProperty2: string
aProperty3: bool
aProperty4: int
var anObject: MyObject
Run
and this is DSL I want to make, using `dumpTree` to see if it is valid:
dumpTree:
with anObject:
aProperty1 = 7
aProperty2 = "abc"
aProperty3 = true
aProperty4 = 42
Run
Try to run it to see what it prints.
Next, we can start writing our macro. Let us just `echo` some parts to see if
everything is as we expect:
macro with(obj: MyObject, body: untyped): untyped =
echo obj
for row in body:
echo row.repr
with anObject:
aProperty1 = 7
aProperty2 = "abc"
aProperty3 = true
aProperty4 = 42
Run
Ok, `row` is what we expected, but let us split it into pieces to see how that
looks like. Change your loop in the macro to:
for row in body:
for r in row:
echo r.repr
Run
We're starting to getting somewhere.
* * *
Our next stop is writing the macro to do what we want, and that is to produce:
anObject.aProperty1 = 7
anObject.aProperty2 = "abc"
anObject.aProperty3 = true
anObject.aProperty4 = 42
Run
so when we do (after calling our macro) `echo anObject` we get: `(aProperty1:
7, aProperty2: "abc", aProperty3: true, aProperty4: 42)`.
I'll leave that one for you.
If you get stuck, post **exactly** what you have tried.