[antlr-interest] Accessing HIDDEN tokens in the C target.
Jim Idle
jimi at temporal-wave.com
Thu Aug 28 16:38:15 PDT 2008
On Thu, 2008-08-28 at 16:33 -0700, Jim Idle wrote:
> On Thu, 2008-08-28 at 16:16 -0700, Robin Green wrote:
>
> > Hello!
> >
> >
> > Longtime listener, firstime, er, caller.
> >
> >
> > I am using the "C" target and I am trying to get access to the
> > $channel=HIDDEN tokens from the parser, but only inside one rule.
> > The FAQ and advice on the mailing list that I have read talk about
> > subclassing the ANTLR3_COMMON_TOKEN_STREAM class and rewriting the
> > skipOffTokenChannels() function to send back every token in the
> > stream.
>
>
> When you want to do this in one rule, just use get it directly
> starting from the current index. Say you want to look back from a
> particular token in a rule to see if there was a comment on channel 2
> (please note that I have not compiled this, just typed it in from
> memory). Basically though you can do anything you can do in Java (more
> in fact), just by looking a ta Java example and realizing that the C
> methods are all the same names (just about) but instead of x.y(z),
> you use x->y(x, z).
>
> rule
> : f=FUNCTION x y z
> {
> int sIndex;
> pANTLR3_COMMON_TOKEN tok;
>
> sIndex = $f->getTokenIndex($f) - 1; // Index for first token
>
> // Now look back up looking for tokens
> tok = INPUT->get(INPUT, sIndex);
Actually, this should be:
tok = (pANTLR3_COMMON_TOKEN)(INPUT->get(INPUT, sIndex)->super);
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080828/4bd1208d/attachment.html
More information about the antlr-interest
mailing list