[antlr-interest] Comments get removed after instrumenting source
Andreas Meyer
andreas.meyer at smartshift.de
Tue Jun 2 05:53:54 PDT 2009
if you use the TokenStreamHiddenTokenFilter from ANTLR2 (see section
"How to use this filter" in http://www.antlr2.org/doc/streams.html), it
will by itself call these functions. All you have to do is follow the
steps from that section. Take care about the calls to filter.discard and
filter.hide (you have to call those after constructing your lexer
instance, and you have to pass that filter to the parser, instead of
directly passing the lexer), and also remove the action
"$setType(Token.SKIP);" from the grammar, as the tokenStreamFilter is
now taking care of it. Later, you can access hidden tokens by calling
"getHiddenafter" (see following section "Tree Construction" in the same
manual).
The manual is a bit out of date I guess, but if you also look at the
source code of ANTLR2 in parallel, things should get clearer.
Andreas
vasanthi a schrieb:
> where should I use the setHiddenAfter / setHiddenBefore methods?
> Please let me know
>
> vasanthi.
>
> On Thu, May 7, 2009 at 4:19 PM, Andreas Meyer
> <andreas.meyer at smartshift.de <mailto:andreas.meyer at smartshift.de>> wrote:
>
> If you just skip the comment token, it will be discarded. If you
> want to
> retain it, you have to use the "setHiddenAfter" / "setHiddenBefore"
> methods mentioned in the antlr wiki. Once the comments are stored
> there,
> you have to take care that you print them while traversing the
> tree for
> output.
>
> Andreas
>
> vasanthi a schrieb:
> > HI All
> >
> > I have the below code for java grammar comment
> >
> >
> > // Single-line comments
> >
> > SL_COMMENT
> >
> > : "//" (~('\r'|'\n'))* {$setType(Token.SKIP);}
> >
> > ;
> >
> > After instrumenting the java code, it is removing the java
> comments .
> > Can you please let me know how to retain the comments
> >
> > after instrumenting the code..
> >
> >
> >
> > Please let me know, as I am stuck up with this from quite long time
> >
> >
> >
> > Vasanthi.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> ------------------------------------------------------------------------
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
--
Mit freundlichen Grüßen
Andreas Meyer
Consultant
_______
smartShift GmbH
Willy-Brandt Platz 6
68161 Mannheim
Germany
T +49 (0)621.400 67.613
Geschäftsführer: Stefan Hetges
Amtsgericht Hamburg, HRB 83484
Ust.-ID-Nr.: DE 813489791
More information about the antlr-interest
mailing list