[antlr-interest] Escaping single quotes in a lexer

Emanuele Gesuato egesuato at ibc.it
Mon Mar 30 01:54:08 PDT 2009


Gavin Lambert wrote:
> At 05:25 28/03/2009, Emanuele Gesuato wrote:
>  >DELIM : "\'' ('\\' ('\'')? | ~('\\' | '\''))* '\'";
>  >
>  >As described below i'm using antlr 2.7.6. I've tried to use it
>  >as a delimiter to my string using:
>  >
>  >STRING : DELIM((JOLLY)?(PAROLE|INTEGER)(JOLLY)?)DELIM;
> 
> The rule I posted is not a delimiter rule; it is a rule for matching the 
> entire STRING.
> 
> In v2 syntax it'd be:
> 
> STRING : "'" ("\\" ("'")? | ~("\\" | "'"))* "'";
> 
> (I don't quite remember if you need to double the backslashes in v2, but 
> I think you do.)
> 

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 ?


Here is the other definitions that help you understand what is STRING:
protected SPAZIO    : ' ';
protected CIFRA        : '0'..'9';
protected LETTERA    : ('a'..'z'|'A'..'Z'|'_'|'\\'|'.'|'-');
protected PAROLA    : LETTERA(CIFRA|LETTERA)*;
protected PAROLE    : PAROLA((SPAZIO)+(PAROLA))*;
protected INTEGER    : (CIFRA)+;
JOLLY            : "*";


Thanks,
Emanuele




More information about the antlr-interest mailing list