[antlr-interest] V4 Feature Request: Externally loadable target generators

Stephen Gaito stephen at perceptisys.co.uk
Fri Sep 21 12:29:13 PDT 2012


Ter,

*Problem:*

Maybe I missed it, but one of the serious drawbacks I found in using 
your excellent ANTLR V3, was the inability of cleanly loading a new or 
slightly altered target (C/C++/Java/...) generator.

If I remember correctly in reading through the Java code for the Tool, 
the list of the various target generators were hard-coded into the Tool.

If my memory is correct, to load my own generator I would need to alter 
your code... which, if I were to open-source my own project, would get 
seriously messy... with a (potential) proliferation of different forks 
of ANTLR.  (Or alternatively with a very large number of "pull" requests 
back into the main project).

*Request:*

As the community begins to develop or port targets for the ANTLR v4, it 
would be nice to have a clean way of developing and deploying targets 
which exist /outside/ of the official ANTLR4 project.

*Benefits:*

This should make maintaining the core ANTLR4 project much easier, and it 
would allow users of ANTLR v4 more flexibility in their choice of targets.

For example, from Sam's comments on the "standard" C++ target, this C++ 
target /might/ make use of "external" dependencies which /might/ 
preclude the use of a generated grammar inside, for example, the PHP engine.

If ANTLR v4 allowed externally loadable target generators, then I (for 
example) might be able to make simple changes to the standard C++ target 
(or alternatively write my own) so that grammars generated using my 
generator would be embeddable inside, for example, the PHP engine.

Then in my (eventually) open-source project I could distribute an 
additional jar file to be loaded at runtime.  This additional jar file 
could, cleanly, contain "my" version of the C++ target generator as 
required by my project.  (Of course I would also provide my C++ target 
as an un-official but, hopefully,  useful GitHub project).

*Possible implementation?*

I know that ANTLR v4 now makes extensive use of Java's reflection 
mechanisms.  Could you use this reflection mechanism to find externally 
loadable target generator interfaces?

Alternatively, could you search for all instances of a suitably named 
file in the resources to load any external target generator?

Regards,

Stephen Gaito




More information about the antlr-interest mailing list