[antlr-interest] Why is Filter thwarting me?

alan brown listbrownie at gmail.com
Wed Mar 5 23:54:27 PST 2008


Hmmmm.  I was unaware that grammars and lexers are frequently split into
different files.  It seems that putting the lexer in its own file is no
problem, but when I put the parser in its own file it complains (in red in
intellij) that it can't find any of the tokens my rule is referring to.

Is there some sort of #include that enables my parser to know where it's
looking for the tokens or should I consider the red squiggles under all my
token names as decoration?  :)

Also, I'm confused about your explanation (though it does seem to help).  If
filter=true is only a lexer rule then why should it be a problem defining it
in a hybrid (lexer/parser) grammar file?  Surely, as a lexer rule it should
only affect the lexer.

Currently, for lack of a better solution, I'm committing the cardinal sin of
having the lexer code in one file (with filter=true) and both the parser and
lexer in the other file, though it only generates the parser code of course.

I know I'm following worst practices here.  Can someone please illuminate
me?

alan

On Wed, Mar 5, 2008 at 11:05 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> At 19:53 6/03/2008, alan brown wrote:
> >I'm using 'filter=true' because I'm just trying to pluck out
> >parts of the input stream.  However, setting filter to true seems
> >to prevent my java code from running.  Here's an example:
> >
> >
> >grammar wibble;
> >
> >options {filter=false;}
>
> There's your problem right there :)  (Assuming you'd put
> filter=true instead.)
>
> 'filter=true' is a lexer option, and only works in lexer-only
> grammars.  It should actually produce a compiler error in other
> cases, but sadly at the moment it doesn't.
>
> Change your "grammar" to "lexer grammar" and remove the parser
> rules, and it should work properly.  (You can then create a
> separate "parser grammar" to deal with the output, if you want.)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080305/2a6c80e2/attachment.html 


More information about the antlr-interest mailing list