Hi Jim,
Yes, I found the wiki after sending the e-mail yesterday. Thanks
for taking the time on writing that as it was really helpful.
Now, continuing on the subject, I need to go a step further for my
use case. Just so you understand, in my case, due to syntactic
predicates, even if the next token is on the follow set, the
"statement" rule can still fail. So, the question is: how to stay in
the loop, skipping/deleting tokens, until it either succeeds in
parsing the rest of the input or EOF is found?
compilationUnit
: resync (statement resync)* EOF
;
Thanks,
Edson
2010/10/5 Jim Idle <[email protected]>:
> Please read the article in the wiki on error recovery methods. You can see
> there how to keep a parse loop going instead of it breaking out. You can
> also see a real world example if you download the source code for the JavaFX
> compiler, as I wrote the error recovery article after writing that parser.
>
> http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery
>
> Jim
>
>> -----Original Message-----
>> From: [email protected] [mailto:antlr-interest-
>> [email protected]] On Behalf Of Edson Tirelli
>> Sent: Monday, October 04, 2010 3:27 PM
>> To: [email protected]
>> Subject: [antlr-interest] How to force error recovery?
>>
>> Hi all,
>>
>> Look at this simple grammar:
>>
>> grammar testGrammar;
>> options {
>> output=AST;
>> }
>>
>> compilationUnit
>> : statement* EOF
>> ;
>>
>> statement
>> : A^
>> | B^ C
>> ;
>>
>> A : 'a';
>>
>> B : 'b';
>>
>> C : 'c';
>>
>> WS : ( ' '
>> | '\t'
>> | '\r'
>> | '\n'
>> ) {$channel=HIDDEN;}
>> ;
>>
>>
>> Using the above grammar, it will successfully parse an input like:
>>
>> a b c a
>>
>> Now, if the input is:
>>
>> a c a
>>
>> The generated parser will parse "a", and will fail at "c", as it is
> not a valid
>> statement. Reading the error recovery chapter on the ANTLR book, I would
>> imagine ANTLR would delete/skip the "c" token and try to recover,
>> successfully parsing the second "a", as that is a valid statement again.
> But it is
>> not working like this. It is aborting the parsing with an error at "c".
>>
>> Question: how do I force it to recover from the error and continue
> parsing?
>>
>> The actual scenario is that the parser I am working on is used by an
> IDE
>> environment (eclipse), so we need it to continue parsing and presenting
> the
>> users with all the errors found in the file, not just the first one. The
> error
>> recovery seems to work on some rules, but not on the top rule
>> (compilationUnit).
>>
>> Thanks,
>> Edson
>>
>> --
>> Edson Tirelli
>> JBoss Drools Core Development
>> JBoss by Red Hat @ www.jboss.com
>>
>> 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
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
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.