mike-lischke / antlr4ng

Next Generation TypeScript runtime for ANTLR4
Other
65 stars 11 forks source link

ParseRuleContext in empty input has undefined stop token #71

Open lonely-lockley opened 1 month ago

lonely-lockley commented 1 month ago

In java ANTLR4 implementation the code like:

var parseTree = parser.parse();

returns a ParseRuleContext object with start and stop token pointing to EOF for zero-length input. This library returns start as expected, but stop property value is undefined. This breaks the logic of searching for the rule bounds (from parseTree.start!.start to parseTree.stop!.stop). I've added additional checks, but it would be nice not to have them at all.

antlr4ng version 3.0.4 antlr4ng-cli version 2.0.0

mike-lischke commented 1 month ago

Odd, the stop token is only omitted in case of errors. At least that's what I though until now.