[antlr-interest] Trouble modifying Java source w/ ANTLR

Terence Parr parrt at cs.usfca.edu
Thu Feb 19 15:18:47 PST 2004


On Feb 19, 2004, at 1:13 PM, Robert Colquhoun wrote:

> Hello,
>
> At 07:08 AM 20/02/2004, cliftonccraig wrote:
>> I just picked up ANTLR and I'm trying to determine the easiest way to
>> build a Java Parser that can insert and replace VERSION strings in my
>> Java source files. I have the Java grammar available on the ANTLR web
>> site and I have the source files from the TokenRewriting article also
>> on the site. Could someone walk me through where in the Java grammar I
>> should put logic to do the insert? I really need help on this and I
>> appreciate any and all help provided.
>
> Have you considered using ant(see the replace task) or sed or 
> something to
> do this?
>
> IF you you antlr possibly you could just lex it provided you knew the
> version string you were looking for was unique enough  Otherwise you 
> will
> need to parse it and then search through the resulting AST, do the 
> replace
> then print the AST  out again....remembering to preserve whitespace etc

Yep, sed would work if the variable was always on the same line 
completely specified.

The rewrite engine works great.  Just add an action to the rule(s) that 
match a member variable that replaces the expr token(s) with the text 
of what you want. :)  If you're new to parsers and grammars, it may be 
easier to just go the sed route.

Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list