Reputation: 531
Is it possible to use Sweet.Js to expand
{ "foo": "bar" }
to
{ "bar": "foo" }
for example?
My naïve attempt here doesn’t work and I don’t see an example in the documentation.
Thanks.
Upvotes: 0
Views: 89
Reputation: 5337
The trick is that :
has special meaning in patterns so you need to escape it with $[:]
macro bar {
rule { {$x $[:] $y} } => { {$y: $x} }
}
var o = bar { "bax": "quux" }
Upvotes: 1