[antlr-interest] Use partial classes for C#

Martin Probst mail at martin-probst.com
Wed Mar 28 01:30:43 PDT 2007


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