[antlr-interest] Modify java source code with ANTLR

Kamal Verma kverma at yahoo.com
Mon Oct 22 10:22:19 PDT 2007


You might want to check out Harmonia project as well.

http://harmonia.cs.berkeley.edu/harmonia/research/pmit/index.html
http://harmonia.cs.berkeley.edu/papers/maratb-icse03-extended-abstract.pdf

_K

----- Original Message ----
From: Austin Hastings <Austin_Hastings at Yahoo.com>
To: Jim Idle <jimi at temporal-wave.com>
Cc: antlr-interest at antlr.org
Sent: Monday, October 22, 2007 12:12:06 PM
Subject: Re: [antlr-interest] Modify java source code with ANTLR

Jim,

I have the impression that the OP wants to use ANTLR to generate a 
Rewriter, that will comment out methods in other, non-antlr, source
 files.

Friedhelm,

You might try examining the start/stop tokens associated with the 
methods in question. The easiest solution of all might be to generate a
 
sed script like

sed -e '22,44s,^,//~commented-out~,'

that you would run on the files, where 22,44 would be the starting and 
ending lines mentioned above. The rules have $start and $stop 
attributes, but I think that $stop can only be used inside an @after 
action on the rule. Something like

grammar java;
/* blah blah  blah */

method
    @after { System.out.println("Method " + $name.text + " starts at 
line: " + $start.line + " and ends at line: " + $stop.line); }
    : type name '{' statement* '}'
   ;

Except it's more complicated. :-(

=Austin

Jim Idle wrote:
>
> Do wish to actually comment them out, or just override them with 
> methods that do nothing, or something else of your choosing?
 Depending 
> on how deep you want to go into it, you may be able to just inherit 
> from the lexer or parser classes and implement your own methods? Of 
> course the source code is yours to do as you will with it, including 
> make derivates as say Loring has done, so if inheriting and
 overriding 
> is not practical for you, then you could just comment the code out
 and 
> recompile, as you suggest :-)
>
> Jim
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Friedhelm Hellerhoff
> > Sent: Monday, October 22, 2007 2:38 AM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] Modify java source code with ANTLR
> >
> > What is the best way to modify some only specific
> > methods in a java source code file using ANTLR?
> >
> > I have already downloaded and compiled the Java 1.5
> > grammar for v3. I can run the lexer and parser code
> > successfully.
> > I want to comment out a hand full of methods (with
> > specific names that I know) in different java files.
> >
> > Thanks for any answer!
> >
> >
> >
> >       Jetzt Mails schnell in einem Vorschaufenster überfliegen.
 Dies
> > und viel mehr bietet das neue Yahoo! Mail - www.yahoo.de/mail
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.488 / Virus Database: 269.15.5/1084 - Release Date:
> > 10/21/2007 3:09 PM
> >
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.488 / Virus Database: 269.15.5/1084 - Release Date: 
> 10/21/2007 3:09 PM
>  
>
>
 ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.488 / Virus Database: 269.15.5/1085 - Release Date:
 10/22/2007 10:35 AM
>   






__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071022/6b5f9ba9/attachment.html 


More information about the antlr-interest mailing list