Open JFinis opened 10 years ago
True it breaks the pattern but (x) is same as x. why use (x) then?
This issue will hopefully be resolved by the introduction of an optimization pass to remove unnecessary blocks sometime after the Tool is rewritten using ANTLR 4 grammars and parse trees instead of ANTLR 3 and ASTs which it uses now.
@parrt See my text below the example: A human would of course leave out the block. However, a grammar generation tool might introduce a block and it would be cumbersome to remove the blocks by hand after running such tool.
oh right. yep.
:warning: When this is fixed, we will need to report a warning whenever removing parentheses around a top-level alternative causes it to be treated as a prefix operator. Otherwise you will have a silent change in behavior for some grammars due to the issue described in the following question:
Another "use case" which might introduce such parenthesis: When manually inlining a left-recursive rule, I'd wish to clearly separate the inlined part, and the obvious choice would be parentheses, which should not alter semantics.
Here is the description of this problem from stackoverflow:
http://stackoverflow.com/questions/23626376/antlr4-mutual-left-recursion
Here is the issue:
This provokes a mutually left recursion error. When removing the parenthesis around classOrInterfaceType, then everything is fine. The parentheses are superfluous but are inserted by some grammar generation tools, so it would be fine if this would work!