[antlr-interest] v2->v3 Skip chars in Lexer?
Bart Kiers
bkiers at gmail.com
Sat Apr 16 03:18:35 PDT 2011
On Sat, Apr 16, 2011 at 12:06 PM, Ruslan Zasukhin <
ruslan_zasukhin at valentina-db.com> wrote:
> ...
>
> How to remove that quotes in v3? :-)
>
>
Here's a way:
DELIMITED
@init {
String q = null;
}
@after {
String text = getText();
// remove the first and last quote, replace all 2 quotes with a single
quote
setText(text.substring(1, text.length()-1).replace(q+q, q));
}
: ( DQUOTE (~DQUOTE | DQUOTE DQUOTE)+ DQUOTE {q = $DQUOTE.text;}
| BQUOTE (~BQUOTE | BQUOTE BQUOTE)+ BQUOTE {q = $BQUOTE.text;}
) { $type = IDENT; }
;
or create your own token that handles the replacements internally:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1844
Regards,
Bart.
More information about the antlr-interest
mailing list