Jim,

Thanks for this - I didn't reply immediately because this didn't work, I 
think because the ESCAPEQUOTE and CHARNOQUOTE needed to be in the same 
rule for some reason, so I resorted to a regular expression.

The good news is that I used this fragment technique for another 
challenge in the same grammar, and it worked beautifully, so thank you!

Regards,

Tim.

On 21/10/2011 18:11, Jim Idle wrote:
> 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: [email protected] [mailto:antlr-interest-
>> [email protected]] On Behalf Of Tim Poole
>> Sent: Friday, October 21, 2011 9:39 AM
>> To: [email protected]
>> 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
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2012.0.1831 / Virus Database: 2092/4565 - Release Date: 10/21/11

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to