I have an ANTLR grammar file with the string definition as below
STRING
: '"' (EscapeSequence | ~('\\'|'"') )* '"' ;
fragment EscapeSequence
: '\\' .
;
But this Lexer rule ignore the escape character at the first instance of the quotes. The
id\=\"
is recognized as the start of the string whereas there is a preceding escape character. this is happening only for the first quote. All the subsequent quotes, if escaped, are recognized properly.
/id\=\"Testing\" -- Should not be a string as both quotes are escaped
/id\="Testing" -- Should be a string between the quotes, since they are not escaped
The main problem to solve is to avoid the lexer from trying to recognize a string if the character (only the last one character) preceding a quote is an escape character. If there are multiple escape characters, I need to consider just one character before the starting quote.