[antlr-interest] Re: wierdness - or perhaps my ignorance
genericised
trigonometric at softhome.net
Mon Aug 5 06:15:11 PDT 2002
This works:
class SillyLexer extends Lexer;
BLAH : c:. {
System.out.println("ignoring: " + c);
} ;
I'd be interested to know if anyone knows how to do
this using a filter.
--- In antlr-interest at y..., "genericised" <trigonometric at s...> wrote:
> That doesn't work. I was under the impression that the
> rule didn't need to be anything, because it was set as
> the filter for the lexer with options { filter=blah; }.
>
> A filter has to be protected. The same output occurs
> if a filter is specified or not and the rule is protected,
> or not, if the rule contains a dot, the rule is not protected
> and no filter is used and if the token type is set or not.
>
> Davy
>
> --- In antlr-interest at y..., Bogdan Mitu <bogdan_mt at y...> wrote:
> > Hi Davy,
> >
> > First of all, protected rules don't return any token. Second, if
> you set the
> > token type to SKIP, lexer won't output it. Third, if the rule is
> empty, it
> > won't consume any char. Try:
> >
> > BLAH : . // Note the dot, which means "anything"
> > { System.out.println("ignoring: "+ $getText); }
> > ;
> >
> > Bogdan
> >
> > --- genericised <trigonometric at s...> wrote:
> > > class SillyLexer extends Lexer;
> > > options { filter=BLAH; }
> > >
> > > protected BLAH : {
> > > $setType(Token.SKIP);
> > > System.out.println("ignoring: "+getText());
> > > } ;
> > > ---------------------------------------------------
> > >
> > > called from a main like so:
> > >
> > > ---------------------------------------------------
> > > while(true) {
> > > try {
> > > sillyLexer.nextToken();
> > > } catch(Exception e) {}
> > > }
> > > ---------------------------------------------------
> > >
> > > when executed, no output is generated and
> > > the lexer gets stuck in an infinate loop, why?
> > >
> > > I comprehend that if newlines were an issue I
> > > would have to catch them otherwise the lexer
> > > would be stuck on one line, but here input is
> > > from stdin so newlines should not be an issue?
> > >
> > > Note: I am not trying to achieve anything specific
> > > here, I am just curious.
> > >
> > > Davy
> > >
> > >
> > >
> > >
> > > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> > >
> > >
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Health - Feel better, live better
> > http://health.yahoo.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list