representing this in the AST is not the primary issue here. There are several idioms in Groovy and most of our grammar is based on different forms of method calls. For example
can be seen as a method call to the method "if" with two parameters that are "b" and the block "
{println foo}
". When I now look at
doSomething() unless (x > 10)
then I see a method call "doSomething()" like before with the if, but what follows? I can't be a method call if multiple arguments, because of the () and because no block follows. So what is it then? The solution I showed is based on an expression consisting of
and a method called on the result of that expression. So in my view it does not fit the overall style used in Groovy and I am tempted to say no to this, if your example is the only usage of a whole new idiom.
what we could have is
unless(x>10){doSomething}which is more or less like an if with a negated condition. The other order is a bit problematic in Groovy because there is no execution style like that in all of groovy. That would mean adding a new idiom, which makes the language more complicated. What could be done, would maybe:
{doSomething}.unless(x>10)which is not exactly like in Python, but I think that is good enough. For this solution a category could be used to see if it is good.