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

Arne Schröder arne.schroeder at gmail.com
Fri Jan 15 01:43:28 PST 2010


Thank you for your quick help. It might work in that case but does not help
me with my real problem. So I will alter the example to have it closer to my
real problem:

file    : section1 section2?
        ;

section1: 'Section1' method*
        ;

section2: 'Section2' method*
        ;

method  : ID LPARENT RPARENT
        ;

ID      : ('a'..'z'|'A'..'Z')+
        ;

LPARENT : '(' ;
RPARENT : ')' ;

SPACE   : ' ' {$channel = HIDDEN;}
        ;

If I now try to parse "Section1 bla()) Section2" something similar happens:
It parses up to the second ")" and then decides to skip the rest. And I
definitely do not want the second ")" to be there i.e. want it to throw a
recognition-error and recover itself.

On Fri, Jan 15, 2010 at 10:27 AM, Akira Akira <akira.lists.1948 at gmail.com>wrote:

> I am not sure if this is what you want, but what about changing to
> something like the following? (the parts I added are in bold)
>
>
> file    : section1 section2?
>        ;
>
> section1: 'Section1' *CONTENTS*
>        ;
>
> section2: 'Section2' *CONTENTS*
>
>        ;
>
> ID      : ('a'..'z'|'A'..'Z')+
>        ;
>
> *CONTENTS      : ('a'..'z'|'A'..'Z')*
>        ;*
>
> SPACE   : ' ' {$channel = HIDDEN;}
>        ;
>
>
>
> 2010/1/15 Arne Schröder <arne.schroeder at gmail.com>
>
>> 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
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "il-antlr-interest" group.
>> To post to this group, send email to il-antlr-interest at googlegroups.com.
>> To unsubscribe from this group, send email to
>> il-antlr-interest+unsubscribe at googlegroups.com<il-antlr-interest%2Bunsubscribe at googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/il-antlr-interest?hl=en.
>>
>>
>>
>>
>


More information about the antlr-interest mailing list