Open SimonSntPeter opened 4 years ago
Just noticed I asked for this 4 years ago and it was closed back then for good reason (https://github.com/antlr/antlr4/issues/1086 "...it could collide with legacy grammars"), however I'd really like this in some form or other, as an optional flag or something, I wrote a small python script for detecting these and I'm very glad indeed that I did, but it would be - I think - a very good think to somehow roll this into the Antlr, it's caused me much wasted time, and for others too.
Just been bitten by this again though in a new form:
call_stack returns [CallStack cs] : { $cs = new CallStack(); } ;
Spot the problem. I got a baffling ambiguity error. It's quit right, it is ambiguous but ANTLR's tolerance of empty productions is disconcerting.
Accidental empty productions have been a major nuisance for me to the point I wrote a short python script to detect and report them and made it part of my automated workflow. It saved me a lot of time.
I propose that ANTLR disallow them, or at least have a flag that disallows them.
As they might sometimes necessary explicitly (though I doubt it given the standard * or ? operators), or just desirable for clarity, I use the convention
where
empty_production : ;