Many languages associate a string with a quote, for example:
"Rob Malda is smart."
ANTLR 4 can match such a string with the lexer rule as follows:
QuotedString : '"' .*? '"';
To use certain characters inside a string, they must be escaped, possibly like this:
"Rob \"Commander Taco\" Malda is smart."
ANTLR 4 may also correspond to this line;
EscapedString : '"' ('\\"|.)*? '"';
(taken from p96 Defining ANTLR 4 Reference)
Here's my problem: suppose the character to escape is the same character as the line separator. For instance:
"Rob ""Commander Taco"" Malda is smart."
(This is completely legal in Powershell.)
Which lexer rule will match this? I would think this would work:
EscapedString : '"' ('""'|.)*? '"';
But this is not so. The lexer symbolizes the escape character " as the end of the line separator.
source share