[antlr-interest] Generated classes - annotations

Sam Barnett-Cormack s.barnett-cormack at lancaster.ac.uk
Sun Aug 2 03:54:12 PDT 2009


More specifically, I change Java.stg (after copying and renaming, in my 
case) so that the last few lines of outputFile are now

<docComment>
<actions.(actionScope).annotate>
<recognizer>

Then in my combined grammar I assume I can do:

@annotate {/* stuff for parser*/}
@lexer::annotate {/* stuff for lexer */}

I'm almost tempted to remove the existing <docComment> invocation and 
put one in using <actions.(actionScope).doc> or something.

Am I heading in the right direction?

Sam

Terence Parr wrote:
>  Don't tell anybody I told you this, but you can do this:
> 
> @annotatemethod { @SuppressWarnings("all") }
> 
> and then alter Java.stg so that it references
> 
> <actions.annotatemethod>
> 
> right before the method definition. Bob's your uncle, and you have 
> annotations.
> 
> ANTLR's output template mechanism allows you to name any action you want 
> and then reference it from the output templates.
> 
> Ter
> 
> On Aug 1, 2009, at 1:32 PM, Sam Barnett-Cormack wrote:
> 
>> Hey all,
>>
>> similar to previous discussions of doc-comments reaching the generated
>> classes, it'd be *really* nice if it were possible to annotate the
>> generated classes. Specifically, adding @SuppressWarnings("all") would
>> be lovely, as the generated code produces so many warnings (dead code,
>> unused local variables, unused imports...).
>>
>> If there were just something, akin to @header, that appeared between the
>> antlr-generated imports and the actual class, that would do the trick -
>> for doc-comments (of the class) and for annotations.
>>
>> Just a thought.
>>
>> -- 
>> Sam Barnett-Cormack
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: 
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 


-- 
Sam Barnett-Cormack


More information about the antlr-interest mailing list