[antlr-interest] ANTLRWorks 2 (for ANTLR v4)

Sam Harwell sharwell at pixelminegames.com
Mon Sep 12 09:14:48 PDT 2011


In these cases, you'll want to override the Recover method in your generated
grammar and throw a new exception (derived from RuntimeException, not
RecognitionException) containing better information about the cause of the
error. In .NET I throw an OperationCanceledException. This should work for
all types of grammars.

 

This uses an unchecked but appropriate exception for the situation. Allowing
user-specified checked exceptions in a mix of generated and library code is
unnecessary and impractical.

 

Sam

 

From: Wujek Srujek [mailto:wujek.srujek at googlemail.com] 
Sent: Monday, September 12, 2011 10:40 AM
To: Sam Harwell
Subject: Re: [antlr-interest] ANTLRWorks 2 (for ANTLR v4)

 

Hi.

I think the @rulecatch has to be specified per rule, which makes it at least
cumbersome for pretty much all grammars. Please correct me if I am wrong.

How about the lexer?

Do you mean failing on first error is useless? I think it is not - [removed
example before sending to public list]. I don't want any recovery here, with
some artificial tokens inserted for me - I want the whole [.] to fail. As I
was not the only one who searched for an answer (the ANTLR site has a
dedicated site for it) I guess it is not so uncommon.

I agree that recovery is nice in some cases, but not in all of them.

 

Thank you for your answer.

 

wujek

On Mon, Sep 12, 2011 at 5:26 PM, Sam Harwell <sharwell at pixelminegames.com>
wrote:

This is easy for a parser. Just add the following to your grammar.

@rulecatch{}

Aside from answering the single question "In the input recognized by this
grammar? (yes/no)", this is a rather useless thing to do. There are many,
many other ways to approach error handling that are more appropriate for any
other task.

Sam


-----Original Message-----
From: antlr-interest-bounces at antlr.org

[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Wujek Srujek
Sent: Monday, September 12, 2011 4:18 AM
To: antlr-interest Interest
Subject: Re: [antlr-interest] ANTLRWorks 2 (for ANTLR v4)


I am new to ANTLR3 and haven't yet got a lot of experience with it. The one
thing that is bugging me, though, is how hard it was to make sure ANTLR
doesn't perform any recovery and fails on first error with checked
exceptions. And it involved a nasty trick with sneaky throwing... I would
love to see it made easier.

wujek



 



More information about the antlr-interest mailing list