[antlr-interest] Fwd: Simple question, Hard answer?
Kausch, Robert
Robert.Kausch at ottogroup.com
Wed Sep 3 04:13:38 PDT 2008
You can ignore tokens by sending them on a different channel. The following grammar ignores everything that is not 'okko' and works for me:
grammar test;
start: (T1)*;
T1: 'okko';
T2: ~(T1) { $channel = HIDDEN; } ;
Regards,
Robert
-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] Im Auftrag von Bill Mayfield
Gesendet: Mittwoch, 3. September 2008 12:20
An: Matt Palmer; antlr-interest at antlr.org
Betreff: Re: [antlr-interest] Fwd: Simple question, Hard answer?
So it is impossible to have a ANTLR match only a part of the input and ignore the rest?
Regards,
Bill
On Wed, Sep 3, 2008 at 11:59 AM, Matt Palmer <mattpalms at gmail.com> wrote:
> I am not an expert - and I don't have a solution - but chaos* will
> match any sequence of T1 or T2, so it will consume all the tokens.
> You'll never get to match pattern.
>
> Regards,
>
> Matt Palmer.
>
> On Wed, Sep 3, 2008 at 10:36 AM, Bill Mayfield
> <antlrinterest at gmail.com>
> wrote:
>>
>> Okay... but what if this isn't a lexer problem? Suppose I my input is
>> only made up of 'o' and 'k'
>>
>> oooookooookkooo -> 1 match
>> oookkoooookkoook -> 2 matches
>>
>> what would my grammar look like?
>>
>> grammar test;
>>
>> start : chaos* pattern* chaos*;
>>
>> pattern : T1 T2 T2 T1;
>>
>> chaos : T1 | T2;
>>
>> T1 : 'o';
>> T2 : 'k';
>>
>>
>> This one compains that it can match multiple alternatives. I don't
>> understand since I read it like: match any iteration of T1 or T2
>> tokens followed by T1 T2 T2 T1 followed by any iteration of T1 or T2
>> tokens....
>>
>>
>> Thanks again :o)
>>
>>
>> Kind regards,
>> Bill
>>
>>
>>
>> On Wed, Sep 3, 2008 at 11:23 AM, Thomas Brandon
>> <tbrandonau at gmail.com>
>> wrote:
>> > On Wed, Sep 3, 2008 at 7:13 PM, Bill Mayfield
>> > <antlrinterest at gmail.com>
>> > wrote:
>> >> Hi,
>> >>
>> >> Suppose I want to recognize each pattern 'okko' in a random string
>> >> of characters. Some examples:
>> >>
>> >> aaaaaoookoooookkooooaaa -> should yield one match of 'okko'
>> >> aaaokkookko -> should yield two matches of 'okko'
>> >>
>> >>
>> >>
>> >> Here is a grammar that won't work ;o)
>> >>
>> >> grammar test;
>> >>
>> >> start : .* pattern .*;
>> >>
>> >> pattern : T1 T2 T2 T1;
>> >>
>> >>
>> >> T1 : 'o';
>> >> T2 : 'k';
>> >>
>> > Wildcards in parser rules match any token, not any character. As
>> > your lexer only matches 'o'|'k' anything else will cause a lexer
>> > error. Try adding a lexer rule to match any other input after your
>> > other lexer rules, like:
>> > OTHER: .;
>> > Or you may want to look at filtering lexers as they may be better
>> > suited to your task.
>> >
>> > Tom.
>> >>
>> >> No matter what grammar I try. I can't get it to work... how hard
>> >> can it be?
>> >>
>> >>
>> >> Thanks for any input you may provide,
>> >> Bill
>> >>
>> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> >> Unsubscribe:
>> >> http://www.antlr.org/mailman/options/antlr-interest/your-emai
>> >> l-address
>> >>
>> >>
>> >
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-a
>> ddress
>>
>
>
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list