[antlr-interest] antlr works ignoring whitespace

Ron AF Greve antlrlist at moonlit.xs4all.nl
Mon Jan 8 09:09:49 PST 2007


Hi,

Thanks Kay. I was actually indeeed more interested to get it to work in 
antlr-works. It seems like a big time saver to be able to debug a grammar in 
the gui instead of compiling the stuff to C++ (still using antlr2 actually) 
and debugging the grammar there.

I scrunitized the menus but found that it seems to be the 'guess' button in 
the interpreter menu that does the trick. In any case it does ignore 
whitespace now

Thanks :-)


Regards, Ron AF Greve

http://moonlit.xs4all.nl

----- Original Message ----- 
From: "Kay Roepke" <kroepke at classdump.org>
To: "Ron AF Greve" <antlrlist at moonlit.xs4all.nl>
Cc: <antlr-interest at antlr.org>
Sent: Sunday, January 07, 2007 11:58 PM
Subject: Re: [antlr-interest] antlr works ignoring whitespace


> Hi Ron!
>
> On 7. Jan 2007, at 21:53 , Ron AF Greve wrote:
>
>> I am trying to use antlr-works to develop my grammar. It looks like  a 
>> great tool. I tried to use it to test some input files. However I  don't 
>> seem to be able to make it ignore whitespace. I tried the v2  and v3 ways 
>> like skip, channel=99, channel=HIDDEN, filter, but  everything seems to 
>> fail. As soon as it hits whitespace the grammar  fails. Anyone knows how 
>> to do this or is it not (yet) possible.
>>
>> Below my grammar and last attempt with the filter option.
>
> the filter option is not to specify which tokens to skip or hide, it  is 
> to turn on filter mode in a lexer.
> Also, note that the 'protected' keyword is now called 'fragment' in v3.
>
>> Grammar
>> ----------------------------------
>> grammar HTML;
>>
>> options {
>>
>> filter=WHITESPACE;
>>
>> }
>
> this should be
> options {
> filter=true;
> }
>
> if you truly want filter mode (see <http://www.antlr.org/wiki/display/ 
> ANTLR3/Lexical+filters> for more info on that).
> But without knowing what you want to achieve, I'd say you don't want 
> filter mode...ANTLRWorks doesn't support filter mode
> right now, anyway, because the Interpreter can't handle syntactic 
> predicates yet.
>
>> protected
>>
>> WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
>>
>> ;
>
> Use this instead:
>
> WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+  { $channel=HIDDEN;} 
> ;
>
> note the missing fragment keyword and the $ in front of the channel.
>
> When you use ANTLRWorks to test sample input it should figure out  which 
> tokens to ignore automatically.
> There's a dropdown list, IIRC, to specify tokens to ignore, but that 
> shouldn't be necessary.
>
> I haven't looked too close at your grammar to say whether there's  another 
> problem somewhere, but this
> should get you started.
>
> HTH,
>
> -k
>
>
> -- 
> Kay Röpke
> http://classdump.org/
>
>
>
>
> 



More information about the antlr-interest mailing list