Getting unquoted string from Antlr

Hi, I have a string matching rule like this:

string_lit : STRING ;

STRING : ‘’’ ( ~’’’ | ‘\’’ )* ‘’’;

I’d like to get the contents of the string without the quotes. How can I do this with ANTLR4?

Hi Reinout. This can be done in different ways.

  1. This is what I would do: do that outside ANTLR, in a successive processing step
  2. Use a semantic action to override the text, if supported by the target considered
  3. Use modes: switch to mode IN_STRING on the " character and then in that mode capture the token STRING_CONTENT

Hope this helps