[antlr-interest] Passing user defined exceptions through the parser.

Johannes Luber JALuber at gmx.de
Thu Jan 15 00:26:00 PST 2009


> I have implemented this feature in my local copy of the C# port of the
> ANTLR tool, but I still need to make a decision about a couple aspects
> of it. Due to the declaration of BaseRecognizer.mTokens, non-fragment
> rules in a lexer that uses the Java target cannot specify user
> exceptions.
> 
> This condition only applies to the Java target, and even then a user
> could derive from a class other than BaseRecognizer as a workaround.
> Based on this, the following conditions need to be considered:
> 
> * All parser rules may have user-specified exceptions in the exceptions
> specification (nothing to decide on here)
> * In theory, all fragment rules in a lexer can have user-specified
> exceptions, as long as they are handled by the non-fragment lexer rules
> that reference them. Should we allow this?
> * In theory, non-fragment lexer rules can specify user exceptions so
> long as the generated class derives from a user-created class where the
> mTokens function declares other exceptions. Other targets such as C# are
> not limited like this, and the exceptions spec would only be used as
> part of an XML comment at the function declaration. Should we allow this
> in the grammar?

I'd say that we should allow everything which can be useful and doesn't influence the non-users of the features. As the suggestions above fall into this camp, I'm all for it. Anyway, thrown exceptions have to be caught always somewhere and there have been enough people complaining about the lack of user-defined exceptions in the Java target.

Johannes
> 
> Sam
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Peter C. Chapin
> Sent: Wednesday, January 14, 2009 6:32 AM
> Cc: antlr-interest
> Subject: Re: [antlr-interest] Passing user defined exceptions
> throughtheparser.
> 
> Sam Harwell wrote:
> 
> > I just checked and the feature is not implemented in the code
> generator
> > yet. At least in the C# port of the tool it will cause recognition
> > exceptions if you use it in a grammar right now.
> >   
> 
> Okay, thanks for pointing this out. I'll take a look and keep my eye on
> it.
> 
> Peter
> 
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org
> > [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Sam Harwell
> > Sent: Tuesday, January 13, 2009 10:06 AM
> > To: Peter C. Chapin
> > Cc: antlr-interest
> > Subject: Re: [antlr-interest] Passing user defined exceptions through
> > theparser.
> >
> > There is a throwsSpec in the ANTLR tool grammar that *should* be able
> to
> > be used like this:
> >
> > my_rule /*returns [Object o]*/ throws RecognitionException,
> > OperationCanceledException
> >  : ...
> >  ;
> >
> > It doesn't apply to C# so it's not implemented in my CSharp3 target.
> >
> > Sam
> >   
> 
> 
> 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

-- 
Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a


More information about the antlr-interest mailing list