I'm trying to write a sweet.js
macro which needs to generate method call syntax, obj.method()
, but the method
is passed in to the macro as a literal expression. For example:
mcall(obj, toString().length);
// becomes
obj.toString().length;
I've got something that's close:
macro mcall {
rule { ($o, $m:expr) } => { $o.$m }
}
mcall(obj, toString().length);
However, this apparently expands to this:
obj . ( toString ( ) . length );
Where are these extra parentheses coming from, and how do I get rid of them? Should I be using case rules and #{}
? I tried permutations of that but still couldn't succeed at generating a method call without extra parentheses.