[antlr-interest] Most efficient way to handle character escapes?

Scott Royston scott.royston at gmail.com
Fri May 9 11:00:22 PDT 2008


I'm trying to write a set of grammar actions to convert String literals with
character escapes to the final string value,  e.g.:'/47Hello World/47'
should conver to the value 'Hello World' (because /47 is the octal escape
value for ').

My initial try was something like this:
fragment EscapeSequence
:  OctalEscapeSequence {
setText(Character.toString(Character.forDigit(Integer.parseInt(getText()),
8))); }
;

Which doesn't work, I believe because it's a fragment, and setText(...) is a
token construct.

The only obvious way I see to do it is to convert the fragments to tokens
and build up the string, which seems really slow.

I've searched around but can't find any grammars with example actions
handling this.

Am I missing something obvious?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080509/92fc9a53/attachment.html 


More information about the antlr-interest mailing list