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

Rob Aarnts rob at aarnts.com
Mon Jul 25 01:44:26 PDT 2011


Or:
 
SINGLE_QUOTED_STRING returns [string result]
    : SQUOTE
           val=((~SQUOTE)*)    { $result = val.Text; }
      SQUOTE
    ;
----------------------------------------------------- 
Rob Aarnts
phone: +31 2356 14444
mobile: +31 6 5582 2856
fax: +31 8 4227 4444
-----------------------------------------------------
On 24 jul 2011 15:07 "Bart Kiers" <bkiers at gmail.com> <bkiers at gmail.com>
wrote:
> 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>
> <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-addr
> > ess>
> List: <http://www.antlr.org/mailman/listinfo/antlr-interest>
> Unsubscribe:
> <http://www.antlr.org/mailman/options/antlr-interest/your-email-addres
> s>


More information about the antlr-interest mailing list