[antlr-interest] getText()

Jim Idle jimi at temporal-wave.com
Fri Oct 21 10:11:43 PDT 2011


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-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Tim Poole
> Sent: Friday, October 21, 2011 9:39 AM
> To: antlr-interest at 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


More information about the antlr-interest mailing list