mike-lischke / antlr4ng

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

Parser Rule getText Causes Issues #33

Closed abirmingham closed 5 months ago

abirmingham commented 5 months ago

Steps to Reproduce:

  1. Create a grammar with parser rule getText
  2. Run antlr4ng
  3. Attempt to compile the resulting Parser.ts file
  4. Observe many tsc compile errors in the Parser file, indicating incompatible symbols (at first I thought this was a typescript strict issue, as the incompatibilty is with a type union that includes null)

As an antlr4 newbie, I was bit by the above this morning. I am guessing that this is because of a naming conflict with the getText method that the parser class inherits. I am not sure if this is something that antlr4ng should handle differently - perhaps it could output a warning or an error if a parser rule conflicts with a native method? At any rate, I wanted to document the gotcha in case anyone else ran into it and became confused, as I was. Feel free to resolve if no changes to antlr4ng are prudent.

Thanks for the great tool!

mike-lischke commented 5 months ago

The generated methods could use a unique name. Maybe a configurable prefix/postfix would help here? I'll take a note in the ANTLRng feature ideas list.