[antlr-interest] Use partial classes for C#

Jiho Han jhan at InfinityInfo.com
Wed Mar 28 06:27:13 PDT 2007


Partial classes come in real handy in situations like where you have
code generation like antlr.  You have your own changes in one file and
the other file would contain generated code.  This way code generation
doesn't disrupt your manually edited code.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Martin Probst
Sent: Wednesday, March 28, 2007 4:31 AM
To: hwk at cortex-brainware.de
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Use partial classes for C#

Hi,

> I'd like to see the use of partial classes in the C# code generator  
> of ANTLR
> 3. This would simplify coding parsers as new code can be added to a
> generated class in a separate file (without using the @members  
> directive).
> This gives all the advantages of having Intellisense during  
> development.

Why don't you simply have your Parser/Lexer/Whatever extend an  
abstract base class that defines the required methods and be done  
with it? I do this in Java development with v2.7, like this:
class MyParser extends Parser("com.example.mypackage.AbstractParser");

Then in AbstractParser you define the methods you really need as  
abstract. In my case I didn't need any, it's only the concrete parser  
using methods of the abstract parser, but it's possible to e.g. define:
 > public abstract void expr() throws RecognitionException;
(or similar in .NET), and then use that method. So you can happily  
code in your regular IDE.

I generally really wonder why one would need something like partial  
classes, it seems like a totally superfluos feature to me if you have  
inheritance and abstract base classes...

Regards,
Martin


More information about the antlr-interest mailing list