I wouldn't even bother doing this here in the lexer, it is extra work.
Just process the token if you use it later. However:

STRINGLITERAL
      : (QUOTE (ESCAPEQUOTE | CHARNOQUOTE)* QUOTE)
      | (APOS st=EC
                {setText("\"" + $st.text + "\"");}
      ;

fragment EC : (ESCAPEAPOS | CHARNOAPOS)* ;

Should do it (untested).

Jim

> -----Original Message-----
> From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
> boun...@antlr.org] On Behalf Of Tim Poole
> Sent: Friday, October 21, 2011 9:39 AM
> To: antlr-interest@antlr.org
> Subject: [antlr-interest] getText()
>
> Hi,
>
> I have just had to use this to change the single quotes around a string
> to double quotes:
>
> STRINGLITERAL
>      : (QUOTE (ESCAPEQUOTE | CHARNOQUOTE)* QUOTE)
>      | (APOS  (ESCAPEAPOS | CHARNOAPOS)* APOS)
> {setText(getText().replace('\'','\"'));}
>      ;
>
> It's an adaptation of:
>
> http://antlr.org/grammar/1264460091565/XPath2.g
>
> I tried to do the following, without success:
>
> STRINGLITERAL
>      : (QUOTE (ESCAPEQUOTE | CHARNOQUOTE)* QUOTE)
>      | (APOS st=(ESCAPEAPOS | CHARNOAPOS)* APOS) {setText("\"" +
> $st.text + "\"");}
>      ;
>
> Any ideas on how I can implement something along the lines of the
> second one?  It was easy to rewrite this time, but next time might not
> be so easy!
>
> Thanks in advance,
>
> Tim.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to