[antlr-interest] Is it possible to do rewriting for lexer?

Bart Kiers bkiers at gmail.com
Sun Jul 24 06:07:22 PDT 2011


Hi Qiao,

With Java as the target, you could do:

SINGLE_QUOTED_STRING
@after {
  String s = getText();
  setText(s.substring(1, s.length() - 1));
}
  :  SQUOTE (~SQUOTE)* SQUOTE
  ;


Regards,

Bart.


On Sun, Jul 24, 2011 at 2:43 PM, Mu Qiao <qiaomuf at gmail.com> wrote:

> I have some token rules like:
> SINGLE_QUOTED_STRING: SQUOTE (~SQUOTE)* SQUOTE;
> I'd like to hide the first SQUOTE token and the last SQUOTE token from
> the parser grammar. Is there any way to do that? I've tried the hidden
> channel and the skip() method, but they work for the whole rule, not
> just for the tokens I need to hide.
>
> --
> Best wishes,
> Mu Qiao
> GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list