antlr-kotlin icon indicating copy to clipboard operation
antlr-kotlin copied to clipboard

$ symbol is not escaped properly in generated code

Open MartinHaeusler opened this issue 1 year ago • 1 comments

I'm trying to build a parser for MongoDB query expressions. The corresponding grammar has a lot of terminals which start with $, e.g.:

  • $eq
  • $and
  • $not
  • etc.

The problem is that the kotlin code generator does not escape those $ symbols properly. For example, in the generated lexer file, the LITERAL_NAMES contains:

"'\"$and\"'"

... which of course translates to a template expression in Kotlin that inserts the value of the variable and into the string. This is clearly not what we want. The proper escaping would be:

"\"${'$'}and\""

MartinHaeusler avatar Aug 11 '22 10:08 MartinHaeusler