I have been starting to write scripts to do some simple work in modifying existing code files - mostly finding some block of text, and making a few changes based on regular expressions within that block.
These are the kinds of tasks that are beyond simple sed (or even awk) style search and replace or modify in a stream. Basically one or mote files need to be opened (header and implementation files would be the use case for multiple files), some text needs to be inserted and other text changed at particular locations.
I had been starting to use Perl, but it occurred to me that it would be interesting to find out what other scripting languages I was not familiar with would work well for this, and why... I don't mind learning a new language and would like to write the scripts using the best tool for the job.
Thus, I'm treating this as a rosetta stone kind of problem where I have a specific input file and manipulation to perform, and we'll see what people come up with.
As an aside, the reason I would like to limit this to scripting languages specifically is because I would like to be able to make small changes on the fly without recompilation steps.
The task then - given this input file:
============== Task.m =============
@implementation Task
@synthesize myVar;
- (void) someMethod
{
int a = 4;
}
- (void) dealloc
{
[super dealloc];
}
@end
================================
Write a script that is given the file name (either argument or env variable), and a variable name in the environment variable "RELEASEME". The output would be a modified Task.m file, where the dealloc block is moved to just before someMethod, and a line of code inserted in the dealloc block that reads:
[RELEASEME release]; RELEASEME = nil;
So given Task.m and RELEASEME having a value of "fredObject", the output would look like:
============== Task.m (modified) =============
@implementation Task
@synthesize myVar;
- (void) dealloc
{
[fredObject release]; fredObject = nil;
[super dealloc];
}
- (void) someMethod
{
int a = 4;
}
@end
================================
It wouldn't necessarily have to preserve formatting or whitespace, just move and insert code in such a way that it would compile. Since there will not really be an answer as such, I'm making this a community wiki in case anyone feels the need to tweak the question.