[antlr-interest] Use partial classes for C#
Dr. Hartmut Kocher
hwk.cortex-brainware at t-online.de
Wed Mar 28 06:57:45 PDT 2007
Hi,
Of course, this is how I do it for now. However, partial classes were
invented for exactly this reason: Mix generated and hand written code in one
class but in different files. ASP.NET / WinForms etc. do it and a whole
bunch of other generators do it as well. This is the standard way of
generating code in the .NET world.
So I think ANTLR should follow this.
Regards,
Dr. Hartmut Kocher
-----Ursprüngliche Nachricht-----
Von: Martin Probst [mailto:mail at martin-probst.com]
Gesendet: Mittwoch, 28. März 2007 10:31
An: hwk at cortex-brainware.de
Cc: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] Use partial classes for C#
Hi,
> Id 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