[antlr-interest] Unquoting strings

Daniel Danciu ddr1975 at gmail.com
Wed May 14 12:29:12 PDT 2008


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')
  )*
   '\''!;



Would cause the enclosing quotes to be removed. This seems to not be
happening in the Java generated code, so I had to resort to the following
ugly hack, which manually removes the quotes:

STRING
: (DoubleQuotedString | SingleQuotedString)
  {
          // Strip the surrounding quotes
          String txt = getText();
          setText(txt.substring(1, txt.length() -1));
  };

This works, but it's not nice. Does anybody know what I might be doing wrong
in the SingleQotedString rule?

Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080514/2e2ebe6e/attachment.html 


More information about the antlr-interest mailing list