You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Jesper Steen Møller <je...@selskabet.org> on 2016/03/15 17:22:07 UTC

Groovy grammar ambiguity / question

Hi List

I’ve yet to fully understand the rules behind the parenthesis-less method invocation syntax. Basically, it seems that while parenthesis-less method invocation (“command style”) can sometimes be used as an expression, it’s not universally so.

I’d like to understand whether this is a merely an oversight or due to the current state of affairs in the parser, or intentional.

Consider:
	int a = b c
This is legal and equivalent to
	int a = b(c)
similarly:
	a = b c
Works fine, too, letting “b c” be a valid expression.
However, the following:
	if (b c) {
		// Stuff
	}
Gives an error:
	expecting ‘)’, found ‘c’ at line: 1, column: 11

So, is the “command” syntax a special pseudo-expression, and if so, where is it allowed? Only by itself (“statement”), and as the RHS og assignments and initializers?

I’d like to know this as it could get real nasty, depending on the answer, since allowing it everywhere will introduce some ambiguities, which will require some tweaks to keep the “non-left-recursion refactored” grammar we have now.

Also, great news:
Daniel Sun has started contributing fixes, submitting PR’s against the fork at https://github.com/jespersm/groovy/tree/antlr4 <https://github.com/jespersm/groovy/tree/antlr4> - he’s quite productive, thanks!

For coordination, I’ve started tracking some of the known “things to do” at https://github.com/jespersm/groovy/issues <https://github.com/jespersm/groovy/issues>

-Jesper


Re: Groovy grammar ambiguity / question

Posted by Jochen Theodorou <bl...@gmx.org>.

On 15.03.2016 17:22, Jesper Steen Møller wrote:
[...]
> So, is the “command” syntax a special pseudo-expression, and if so,
> where is it allowed? Only by itself (“statement”), and as the RHS og
> assignments and initializers?

we couldn't do more because otherwise the grammar was slapping us left 
and right in the face ;)

> I’d like to know this as it could get real nasty, depending on the
> answer, since allowing it everywhere will introduce some ambiguities,
> which will require some tweaks to keep the “non-left-recursion
> refactored” grammar we have now.

essentially you gave the answer of why there are not more cases to allow 
this. The existing version already took us some effort to rule out the 
ambiguities

> Also, great news:
> Daniel Sun has started contributing fixes, submitting PR’s against the
> fork at https://github.com/jespersm/groovy/tree/antlr4 - he’s quite
> productive, thanks!
>
> For coordination, I’ve started tracking some of the known “things to do”
> at https://github.com/jespersm/groovy/issues

always welcome and good idea!

bye Jochen

Re: Groovy grammar ambiguity / question

Posted by Guillaume Laforge <gl...@gmail.com>.
Yup.
But we have to be very careful, as we can't add that everywhere, as the
grammar would become really ambiguous, as Jochen mentioned.

On Tue, Mar 15, 2016 at 7:20 PM, Marc Paquette <ma...@mac.com> wrote:

>
>
> Le 15 mars 2016 à 12:51, Guillaume Laforge <gl...@gmail.com> a écrit :
>
> It was indeed limited to top-level statements initially, but there have
> been cases where we felt it could be opened up.
> Perhaps it's worth reopening the discussion.
> For example, inside statements like if, or things like asserts, perhaps we
> could allow it?
> Open for discussion on this.
>
>
> +1
>
> If I understand correctly, that would be nice for DSL, so instead of
> having
>
> boolean allAdults = every member of familyComposition is ADULT
> if (allAdults) { ... }
>
> we could have
>
> if (every member of familyComposition is ADULT) { ... }
>
> (with the proper dsl wired in of course).
>
>
> On Tue, Mar 15, 2016 at 5:45 PM, Дионисьев Павел <xs...@gmail.com>
> wrote:
>
>> Dear Jesper,
>>
>> As far as I remember, command expressions are allowed as statements only.
>> There will be lots of ambiguities otherwise.
>>
>> Also, there are known issues in grammar, listed in original repository
>> <https://github.com/xSeagullx/antlrv4_groovy_grammar/issues>. You might
>> want to have a look and incorporate them in your issue tracker.
>>
>> And thank you for working on this project!
>>
>> Pavel.
>> ​
>>
>> On 15 March 2016 at 17:22, Jesper Steen Møller <je...@selskabet.org>
>> wrote:
>>
>>> Hi List
>>>
>>> I’ve yet to fully understand the rules behind the parenthesis-less
>>> method invocation syntax. Basically, it seems that while parenthesis-less
>>> method invocation (“command style”) can sometimes be used as an expression,
>>> it’s not universally so.
>>>
>>> I’d like to understand whether this is a merely an oversight or due to
>>> the current state of affairs in the parser, or intentional.
>>>
>>> Consider:
>>> int a = b c
>>> This is legal and equivalent to
>>> int a = b(c)
>>> similarly:
>>> a = b c
>>> Works fine, too, letting “b c” be a valid expression.
>>> However, the following:
>>> if (b c) {
>>> // Stuff
>>> }
>>> Gives an error:
>>> expecting ‘)’, found ‘c’ at line: 1, column: 11
>>>
>>> So, is the “command” syntax a special pseudo-expression, and if so,
>>> where is it allowed? Only by itself (“statement”), and as the RHS og
>>> assignments and initializers?
>>>
>>> I’d like to know this as it could get real nasty, depending on the
>>> answer, since allowing it everywhere will introduce some ambiguities, which
>>> will require some tweaks to keep the “non-left-recursion refactored”
>>> grammar we have now.
>>>
>>> Also, great news:
>>> Daniel Sun has started contributing fixes, submitting PR’s against the
>>> fork at https://github.com/jespersm/groovy/tree/antlr4 - he’s quite
>>> productive, thanks!
>>>
>>> For coordination, I’ve started tracking some of the known “things to do”
>>> at https://github.com/jespersm/groovy/issues
>>>
>>> -Jesper
>>>
>>>
>>
>>
>> --
>> С уважением, Дионисьев П.А.
>>
>
>
>
> --
> Guillaume Laforge
> Apache Groovy committer & PMC Vice-President
> Product Ninja & Advocate at Restlet <http://restlet.com/>
>
> Blog: http://glaforge.appspot.com/
> Social: @glaforge <http://twitter.com/glaforge> / Google+
> <https://plus.google.com/u/0/114130972232398734985/posts>
>
>
>


-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Product Ninja & Advocate at Restlet <http://restlet.com>

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>

Re: Groovy grammar ambiguity / question

Posted by Marc Paquette <ma...@mac.com>.

> Le 15 mars 2016 à 12:51, Guillaume Laforge <gl...@gmail.com> a écrit :
> 
> It was indeed limited to top-level statements initially, but there have been cases where we felt it could be opened up.
> Perhaps it's worth reopening the discussion.
> For example, inside statements like if, or things like asserts, perhaps we could allow it?
> Open for discussion on this.
> 

+1

If I understand correctly, that would be nice for DSL, so instead of having 

	boolean allAdults = every member of familyComposition is ADULT
	if (allAdults) { ... }

we could have

	if (every member of familyComposition is ADULT) { ... }

(with the proper dsl wired in of course).


> On Tue, Mar 15, 2016 at 5:45 PM, Дионисьев Павел <xseagullx@gmail.com <ma...@gmail.com>> wrote:
> Dear Jesper,
> 
> As far as I remember, command expressions are allowed as statements only. There will be lots of ambiguities otherwise.
> 
> Also, there are known issues in grammar, listed in original repository <https://github.com/xSeagullx/antlrv4_groovy_grammar/issues>. You might want to have a look and incorporate them in your issue tracker.
> 
> And thank you for working on this project!
> 
> Pavel.
> 
> 
> On 15 March 2016 at 17:22, Jesper Steen Møller <jesper@selskabet.org <ma...@selskabet.org>> wrote:
> Hi List
> 
> I’ve yet to fully understand the rules behind the parenthesis-less method invocation syntax. Basically, it seems that while parenthesis-less method invocation (“command style”) can sometimes be used as an expression, it’s not universally so.
> 
> I’d like to understand whether this is a merely an oversight or due to the current state of affairs in the parser, or intentional.
> 
> Consider:
> 	int a = b c
> This is legal and equivalent to
> 	int a = b(c)
> similarly:
> 	a = b c
> Works fine, too, letting “b c” be a valid expression.
> However, the following:
> 	if (b c) {
> 		// Stuff
> 	}
> Gives an error:
> 	expecting ‘)’, found ‘c’ at line: 1, column: 11
> 
> So, is the “command” syntax a special pseudo-expression, and if so, where is it allowed? Only by itself (“statement”), and as the RHS og assignments and initializers?
> 
> I’d like to know this as it could get real nasty, depending on the answer, since allowing it everywhere will introduce some ambiguities, which will require some tweaks to keep the “non-left-recursion refactored” grammar we have now.
> 
> Also, great news:
> Daniel Sun has started contributing fixes, submitting PR’s against the fork at https://github.com/jespersm/groovy/tree/antlr4 <https://github.com/jespersm/groovy/tree/antlr4> - he’s quite productive, thanks!
> 
> For coordination, I’ve started tracking some of the known “things to do” at https://github.com/jespersm/groovy/issues <https://github.com/jespersm/groovy/issues>
> 
> -Jesper
> 
> 
> 
> 
> -- 
> С уважением, Дионисьев П.А.
> 
> 
> 
> -- 
> Guillaume Laforge
> Apache Groovy committer & PMC Vice-President
> Product Ninja & Advocate at Restlet <http://restlet.com/>
> 
> Blog: http://glaforge.appspot.com/ <http://glaforge.appspot.com/>
> Social: @glaforge <http://twitter.com/glaforge> / Google+ <https://plus.google.com/u/0/114130972232398734985/posts>

Re: Groovy grammar ambiguity / question

Posted by Guillaume Laforge <gl...@gmail.com>.
It was indeed limited to top-level statements initially, but there have
been cases where we felt it could be opened up.
Perhaps it's worth reopening the discussion.
For example, inside statements like if, or things like asserts, perhaps we
could allow it?
Open for discussion on this.

On Tue, Mar 15, 2016 at 5:45 PM, Дионисьев Павел <xs...@gmail.com>
wrote:

> Dear Jesper,
>
> As far as I remember, command expressions are allowed as statements only.
> There will be lots of ambiguities otherwise.
>
> Also, there are known issues in grammar, listed in original repository
> <https://github.com/xSeagullx/antlrv4_groovy_grammar/issues>. You might
> want to have a look and incorporate them in your issue tracker.
>
> And thank you for working on this project!
>
> Pavel.
> ​
>
> On 15 March 2016 at 17:22, Jesper Steen Møller <je...@selskabet.org>
> wrote:
>
>> Hi List
>>
>> I’ve yet to fully understand the rules behind the parenthesis-less method
>> invocation syntax. Basically, it seems that while parenthesis-less method
>> invocation (“command style”) can sometimes be used as an expression, it’s
>> not universally so.
>>
>> I’d like to understand whether this is a merely an oversight or due to
>> the current state of affairs in the parser, or intentional.
>>
>> Consider:
>> int a = b c
>> This is legal and equivalent to
>> int a = b(c)
>> similarly:
>> a = b c
>> Works fine, too, letting “b c” be a valid expression.
>> However, the following:
>> if (b c) {
>> // Stuff
>> }
>> Gives an error:
>> expecting ‘)’, found ‘c’ at line: 1, column: 11
>>
>> So, is the “command” syntax a special pseudo-expression, and if so, where
>> is it allowed? Only by itself (“statement”), and as the RHS og assignments
>> and initializers?
>>
>> I’d like to know this as it could get real nasty, depending on the
>> answer, since allowing it everywhere will introduce some ambiguities, which
>> will require some tweaks to keep the “non-left-recursion refactored”
>> grammar we have now.
>>
>> Also, great news:
>> Daniel Sun has started contributing fixes, submitting PR’s against the
>> fork at https://github.com/jespersm/groovy/tree/antlr4 - he’s quite
>> productive, thanks!
>>
>> For coordination, I’ve started tracking some of the known “things to do”
>> at https://github.com/jespersm/groovy/issues
>>
>> -Jesper
>>
>>
>
>
> --
> С уважением, Дионисьев П.А.
>



-- 
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Product Ninja & Advocate at Restlet <http://restlet.com>

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>

Re: Groovy grammar ambiguity / question

Posted by Дионисьев Павел <xs...@gmail.com>.
Dear Jesper,

As far as I remember, command expressions are allowed as statements only.
There will be lots of ambiguities otherwise.

Also, there are known issues in grammar, listed in original repository
<https://github.com/xSeagullx/antlrv4_groovy_grammar/issues>. You might
want to have a look and incorporate them in your issue tracker.

And thank you for working on this project!

Pavel.
​

On 15 March 2016 at 17:22, Jesper Steen Møller <je...@selskabet.org> wrote:

> Hi List
>
> I’ve yet to fully understand the rules behind the parenthesis-less method
> invocation syntax. Basically, it seems that while parenthesis-less method
> invocation (“command style”) can sometimes be used as an expression, it’s
> not universally so.
>
> I’d like to understand whether this is a merely an oversight or due to the
> current state of affairs in the parser, or intentional.
>
> Consider:
> int a = b c
> This is legal and equivalent to
> int a = b(c)
> similarly:
> a = b c
> Works fine, too, letting “b c” be a valid expression.
> However, the following:
> if (b c) {
> // Stuff
> }
> Gives an error:
> expecting ‘)’, found ‘c’ at line: 1, column: 11
>
> So, is the “command” syntax a special pseudo-expression, and if so, where
> is it allowed? Only by itself (“statement”), and as the RHS og assignments
> and initializers?
>
> I’d like to know this as it could get real nasty, depending on the answer,
> since allowing it everywhere will introduce some ambiguities, which will
> require some tweaks to keep the “non-left-recursion refactored” grammar we
> have now.
>
> Also, great news:
> Daniel Sun has started contributing fixes, submitting PR’s against the
> fork at https://github.com/jespersm/groovy/tree/antlr4 - he’s quite
> productive, thanks!
>
> For coordination, I’ve started tracking some of the known “things to do”
> at https://github.com/jespersm/groovy/issues
>
> -Jesper
>
>


-- 
С уважением, Дионисьев П.А.