antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

ParserRuleContext.stop is null with all optional rule?

Open neon12345 opened this issue 1 year ago • 3 comments

There is

functionQualifiers : 'const'? 'async'? 'unsafe'? ('extern' abi?)? ;

in the rust grammar from grammars-v4. This seems to give an empty stop on the FunctionQualifiersContext. Is this intentional?

neon12345 avatar Feb 17 '24 10:02 neon12345

You probably would like to raise the issue in grammars-v4 repository?

KvanTTT avatar Feb 17 '24 14:02 KvanTTT

You probably would like to raise the issue in grammars-v4 repository?

It seems this is true for every grammar with a similar rule as the first in a file. This is an antlr implementation detail/edge case I have not seen so far. I assume a null check on ParserRuleContext.stop is mandatory?

neon12345 avatar Feb 17 '24 14:02 neon12345

This is poorly specified but empty rules can be useful. I cannot remember if Rust requires a specific order but generally I woudl do something like this:

fundef: fq+=funQual* .... ; // named is not required - personal preference

funQual: const | async | unsafe | extern abi? ;

Then you test fq in your tree walk/visit

jimidle avatar Feb 17 '24 15:02 jimidle