[antlr-interest] Unquoting strings
antlr at mirality.co.nz
Wed May 14 13:26:15 PDT 2008
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.:
> '\''! // 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
>: (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.
Though, you might also want to handle escape characters at the
same time. You will need to do a manual search/replace for those.
More information about the antlr-interest