[antlr-interest] Can I embed the Antlr version number in my generated code using some kind of macro?

Andrew Bradnan andrew.bradnan at gmail.com
Fri Jul 9 07:08:34 PDT 2010


You would have to modify the string template for the CSharp2 target in the
antlr-3.2.jar file.
It lives at antlr-3.2_jar\org\antlr\codegen\templates\CSharp2\CSharp2.stg
You can update if you have a copy of winzip handy.  Just unzip, update the
stg. file and rezip.
Of course that change will be null and void with the next version of antlr
which will have a new version of the string template.  That is how to update
the generated code however.

Hope that helps.
Andrew

On Thu, Jul 8, 2010 at 11:08 AM, <Tony.Gray at ca.schneider-electric.com>wrote:

> The ANTLR generated code has lots of nice identifier comments in it with
> the file, line number and grammar file contents that generated the code.
> Are there anything like preprocessor macros I can use to get direct access
> to that info?
>
> I'm using the C# target and what I'm really after is the ability to add a
> custom code attribute to my generated classes to instruct code analysis
> tools that this is generated code.  It It should be easy to just embed
> that as hard-coded output in the @parser::header { } stuff like so:
>
>        [GeneratedCodeAttribute("ANTLR","3.2")]
>
> but I'd really like to have the generator drop the version number in for
> that string the way it does in the automatically generated comments, like
>
> // $ANTLR 3.2 Sep 23, 2009 12:02:23
>
> I spent 20 minutes googling and came up dry - any suggestions?
>
>
> Tony Gray
> Schneider Electric
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
/Andrew


More information about the antlr-interest mailing list