I am attempting to use a lexer mode with ANTLR4 with the following lexer grammar:
STRING: '"' -> pushMode(STRING_MODE);
mode STRING_MODE;
STRING_CONTENTS: ~('"'|'\n'|'\r')+ -> type(STRING);
END_STRING: '"' -> type(STRING), popMode;
STRING_UNMATCHED: . -> type(UNMATCHED);
- Is there a way to return a single token of type STRING for all the characters captured within the mode and including the characters which caused an entrance to the mode?
- When does the mode end?
I am aware that I can also write the string token like so:
STRING: '"' (~["\n\r]|'\\"')* '"';