[antlr-interest] Escaping single quotes in a lexer

Gavin Lambert antlr at mirality.co.nz
Tue Mar 31 01:06:29 PDT 2009


At 21:54 30/03/2009, Emanuele Gesuato wrote:
 >What if i want to maintain as inalterate as possibile the 
original
 >STRING ?
 >
 >STRING : "'"((JOLLY)?(PAROLE|INTEGER)(JOLLY)?)"'";
 >
 >Is it possible to change it to something similar to
 >
 >STRING : "'"((JOLLY)?(PAROLE|INTEGER|ESCAPE)(JOLLY)?)"'";
 >
 >Where ESCAPE is a regexp to match the escaping of single quotes 
?

Yes, it's possible, but you shouldn't do that.  It's best to match 
the entire string (defined as "anything within quotes") as a 
single lexical unit, and worry about validating the specific 
content of the text later on (eg. in the parser or calling code).

Which is what I said before, and what the rule I specified does.



More information about the antlr-interest mailing list