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

Terence Parr parrt at cs.usfca.edu
Mon Sep 24 11:13:54 PDT 2012


On Sep 21, 2012, at 12:29 PM, Stephen Gaito wrote:

> 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.

All you have to do is place the template files before the standard distribution in your class path. I use a resource loader to get those templates and so we will see your modified version's first. no fuss no muss.

This is also true if you want to alter the CTarget.java file or whatever. Just put your own version first in the class that and it will override the standard one when it loads.

 This will also be true of v4.

 Does this do what you want?

Ter
> 
> 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
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list