[antlr-interest] Unquoting strings

Daniel Danciu ddr1975 at gmail.com
Thu May 15 01:15:02 PDT 2008


Thanks folks!

Daniel

On Wed, May 14, 2008 at 10:26 PM, Gavin Lambert <antlr at mirality.co.nz>
wrote:

> At 07:29 15/05/2008, Daniel Danciu wrote:
>
>> Browsing through some tutorials, I was left with the impression that
>> appending an exclamation mark to a character would remove that character
>> from the parsed token, e.g.:
>>
>> fragment
>> SingleQuotedString
>>  :
>>  '\''! // or single quoted string
>>  ( '\\'! '\''
>>  | ~('\''|'\n'|'\r')
>>  )*
>>   '\''!;
>>
>
> That works in ANTLR v2, but not v3.  In v3 the ! operator only works at the
> parser level (to leave a token out from the automatically-generated AST).
>
>  STRING
>> : (DoubleQuotedString | SingleQuotedString)
>>  {
>>          // Strip the surrounding quotes
>>          String txt = getText();
>>          setText(txt.substring(1, txt.length() -1));
>>  };
>>
>
> That's basically just "what you have to do" in v3.
>
> See: <http://www.antlr.org/wiki/pages/viewpage.action?pageId=1461>
>
> Though, you might also want to handle escape characters at the same time.
>  You will need to do a manual search/replace for those.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080515/0929af8e/attachment.html 


More information about the antlr-interest mailing list