Great,

 I found the problem.

Firs I would like to thank Jim for his help. Even if the problem was
just my fold (see below) your article was very helpful to gain deeper
understanding. And you are right, I need to have catch and resync on
other rules.

I had an action in the rule handhistory (not included in my previos
post) which prints out each matched game. In the case of an error the
text of the return value from rule game is null. I didn't test this.
Therefore the parser didn't proceed.

Christian

2009/12/28 Jim Idle <[email protected]>:
> Firstly you probably want:
>
> handhistory: game* EOF ;
>
> Then, did you read the wiki article:
>
> http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery
>
> You probably need to have catch and/or resync on the other rules in your game 
> parsing productions.
>
> Jim
>
>> -----Original Message-----
>> From: [email protected] [mailto:antlr-interest-
>> [email protected]] On Behalf Of Christian Kihm
>> Sent: Monday, December 28, 2009 11:32 AM
>> To: [email protected]
>> Subject: [antlr-interest] custom error recovery
>>
>> Hi,
>>
>> I try to implement a logfile parser. Content of the logfile is a
>> sequense of games like this:
>>
>>
>>    PokerStars Game #35139121861: Hold'em No Limit ($0.05/$0.10 USD) -
>> 2009/11/09 16:48:09 ET
>>    ...
>>
>>    PokerStars Game #35139121865: Hold'em No Limit ($0.05/$0.10 USD) -
>> 2009/11/09 16:48:45 ET
>>    ...
>>
>>
>> If there is an syntax error within a game, I would like to skip the
>> whole game and start parsing the next. To do this I disabled the
>> default recovery by overriding recoverFromMismatchedToken with:
>>
>>    protected Object recoverFromMismatchedToken(IntStream input, int
>> ttype, BitSet follow)
>>        throws RecognitionException
>>    {
>>        throw new MismatchedTokenException(ttype, input);
>>    }
>>
>>
>> I also changed the default rule catch clause with this one:
>>
>>
>> @rulecatch {
>>  catch (RecognitionException e) {
>>
>>    reportError(e);
>>    throw e;
>>  }
>> }
>>
>> For the parser rule "game" I have my own catch clause wich in case of
>> an error will consume Until the Token SITE, "PokerStars" for the above
>> example. Here are the relevant parts of the grammar:
>>
>>
>> handhistory
>>         : ( game )*
>>         ;
>>
>> game
>>        : game_info
>>          table
>>          hand
>>          summary
>>        ;
>>                             catch [RecognitionException re] {
>>                                reportError(re);
>>                                consumeUntil(input, SITE);
>>                             }
>>
>>  game_info
>>        :  site
>>           primarykey
>>           COLON (cash | tournament)
>>           MINUS datetime
>>        ;
>>
>>
>>  site
>>       : SITE
>>       ;
>>
>> ...
>>
>>
>> Unfortunately it don't works as expected. In case of an invalid game
>> the parser goes into the game catch clause, but don't continue
>> parsing. To debug I also have override the consumeUntil Method:
>>
>> public void consumeUntil(IntStream input, int tokenType) {
>>    super.consumeUntil(input, tokenType);
>>
>>    System.out.println("### NEXT Token ### " +
>> getCurrentInputSymbol(input));
>>  }
>>
>>
>> The output of the parser is:
>>
>> line 61:59 [handhistory, game, game_info, tournament, buyin, rake,
>> recoverFromMismatchedToken] mismatched input
>> [...@699,1923:1923='$',<98>,61:59] expecting RAKE
>> ### GAME CATCH ###
>> ### NEXT Token ### [...@1350,3688:3702='PokerStars',<4>,123:0]
>>
>>
>> I am wondering why the parser stops parsing here. As you could see in
>> the output the next Token is as expectet "PokerStars". I would be very
>> happy for each hint.
>>
>> best regards, Christian
>>
>> 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
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.


Reply via email to