-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GROOVY-8551: simplify parser rules for array
- Loading branch information
1 parent
8d94b6f
commit 3084279
Showing
5 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
def foo = new double[2][][5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
def foo = new double[2] { 1.0, 2.0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change made? It was very intentional to have dimensions with an expression (
dim1
) followed by empty dimensions (dim0
). It made for very clean matching and processing.This should have come with a separate issue and separate discussion and review.
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try our best to avoid using similar rules, e.g. dim0, dim1. It is hard for parser to choose which branch to go. Though they can work finally, parsing performance is impacted.
The simplifed rules have same function and better prompt for syntax errors.
BTW, we had friendly prompt for missing right parenthesis, but the similar rules make parsing performance very poor, so we have to remove it.
Did you create any PR or discussion for the changes?
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rules were designed so that the choice is clear. One rule has expression and one does not. I sat on GROOVY-8551 for a very long time. Then as soon as I make a change that satisfies all the tests, you go in and change it, calling such change "simpler". I do not agree that the ASB builder change that you needed to support this is simpler.
If you feel a change does not meet your expectations, a test case or discussion point is the wat forward. You should not make it a practice to modify others changes without at least discussing why such a change is needed. This goes for all the "trivial tweak" changes as well.
A smile or smirk is not a good answer to why this comes in on master with no tracking or notification.
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"simpler" is for parser and not for AST walker, i.e. AstBuilder.
Apart from the parsing performance, friendly prompt is important for parser, the simplifed/tweaked version can achieve the goal.
I really appreciate your hard and amazing work on Groovy development for years. As we all know, you are also the main energy. Go as you want.
Just smile, no smirk, sincerely.
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You both provide wonderful contributions to Groovy! Thanks for keeping the conversation civil. I think it is really important that folks of all backgrounds feel comfortable discussing design choices in all our forums.
In this case, it looks like an opportunity to potentially progress this iteratively since you both have different thoughts but lots of knowledge. Actually for my benefit, can either of you point me to something which changes for Groovy users between the two implementations? Like error message Daniel mentioned?
3084279
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Paul,
Let me explain a bit more.
I had thought Eric did not find a graceful solution to implement the feature of GROOVY-8551, because I found similar rules violating DRY principle, e.g. dim0, dim1. and no friendly error prompt provided. so I thought I could give a hand, and I do know it is not easy to pursue both goals.
Luckily, I tried my best and achieved both goal in the early hours of morning, and pushed the improvement directly to master, which "reverted" some intentional changes by Eric. To be frank, I did not know the changes are intentional. I want to apologize sincerely if Eric is still angry now.
Here is one of friendly error prompt:
3084279#diff-03f7d07e002c1a3986a4913911349066b6f85fc3cf1d18506dc85c4ef83a1478R3517
It's very important to keep grammar rules simple even if increasing complexity of AST walker because the grammar rules control the behavior of parser generated by antlr4 but the AST walker is written by us, i.e. under our control. Also, friendly prompt is important for users, multi-dimentions array is not easy to use, friendly prompt can help users a lot.