[antlr-interest] Missing error when tokens are left to parse

Jim Idle jimi at temporal-wave.com
Fri Jan 15 09:05:41 PST 2010


This is an FAQ I think. Your start rule does not end in EOF and so  
ANTLR stops parsing when the next token is not predicted.

Jim

On Jan 15, 2010, at 0:57, Arne Schröder <arne.schroeder at gmail.com>  
wrote:

> Hello,
>
> I am trying to write a parser for an initialization-file. This file is
> devided in sections which are not embraced but have a keyword to  
> start them.
>
> Unfortunately the parser stops when encountering a problem and just  
> ends the
> parsing-process, not even reporting an error.
>
> For demostration of the problem I wrote the following example-grammar:
>
> file    : section1 section2?
>        ;
>
> section1: 'Section1'
>        ;
>
> section2: 'Section2'
>        ;
>
> ID      : ('a'..'z'|'A'..'Z')+
>        ;
>
> SPACE   : ' ' {$channel = HIDDEN;}
>        ;
>
> Now using the input "Section1 bla Section2", I would expect the  
> parser to
> stop at "bla", throw an UnwantedTokenException, do a  
> SingleTokenDeletion as
> error-recovery and just continue parsing "Section2".
> What happens is that it stops at "bla", does not recognize it as  
> section2
> and just terminates, leaving the two tokens unparsed and not  
> reporting any
> error.
>
> So my question is: How can I avoid my parser doing stuff like that  
> without
> changing my files' syntax?
>
>
> Thanks in advance
>
> Arne
>
> 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