[antlr-interest] Where to put general intialisation logic for a parser?

Miguel Ping mblp at mega.ist.utl.pt
Tue Apr 10 17:30:40 PDT 2007


Another (maybe not so frequent) problem is that if you load a class
and explicitly do not initialize it(the 2nd parameter in forName()),
the static {} block never runs...

Class.forName("sample.Test", false, Random.class.getClassLoader());


On 4/10/07, David Holroyd <dave at badgers-in-foil.co.uk> wrote:
> On Tue, Apr 10, 2007 at 11:55:08PM +0200, Johannes Luber wrote:
> > David Holroyd wrote:
> > > How about putting a (dirty dirty!) instance initialiser block into
> > > @members?
>
> > > That'll confuse anyone who looks at the grammar :)
> >
> > Guaranteed! I had to look up, what instance initialisers were because I
> > haven't used them myself.
>
> I only know about this Java feature from having seen that the 'static'
> is optional, while reading some grammar or other.  I've never used it,
> other then to prove to myself that javac actually accepts the syntax :)
>
> Anyway, a more basic option; just add some setter-methods and use a
> 'builder' pattern to obtain parser instances?  Might be easier to write
> unit tests that way...
>
> --
> http://david.holroyd.me.uk/
>


More information about the antlr-interest mailing list