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

Tony.Gray at ca.schneider-electric.com Tony.Gray at ca.schneider-electric.com
Fri Jul 9 09:54:53 PDT 2010


Thanks Andrew - after I'd posted, I did some poking around that led me 
right to CSharp2.stg.  It's very readable, and I thought about modifying 
it, but as you (and Yoda) pointed out, "Once you start modifying your 
distro, forever will it dominate your upgrades".   If there were an actual 
error I was trying to fix, sure, but this one isn't worth it.

Thanks for your help!

Tony Gray  |   Schneider Electric   



From:
Andrew Bradnan <andrew.bradnan at gmail.com>
To:
Tony.Gray at ca.schneider-electric.com
Cc:
antlr-interest at antlr.org
Date:
07/09/2010 07:09 AM
Subject:
Re: [antlr-interest] Can I embed the Antlr version number in my generated 
code using some kind of macro?
Sent by:
antlr-interest-bounces at antlr.org



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

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

________________________________________________________________________
This email has been scanned for SPAM content and Viruses by the 
MessageLabs Email Security System.
________________________________________________________________________





More information about the antlr-interest mailing list