I’m writing a recursive procedure, called “subliner3”. To be simple it replaces:
[object method]withObject->method()[object method:attr1 attr2 ...]withobject->method(attr1,attr2,...)
It is recursive to replace (1) and (2) inside (2). Any attr may be like (1) or (2).
So, this code causes problem:
while {[regsub -all {\[([^\[\]:]+)[:]([^\[\]]+)\]} $subline "[subliner3 "\\1" "\\2"]" subline]} {}
This is supposed to find exactly (2) in subline (subline is an attribute list) and call function again for it. The problem is that, when subline is called with regsub’s \1 and \2 subliner3 really gets “\1” and “\2”, so looks like they are interpreted afted subliner3 call. How can I manage to call [subliner3 “\1” “\2”] with interpreted \1 & \2?
Sample Input:
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:5], [CCCallFunc actionWithTarget:self selector:@selector(resetMessage)], nil]];
Output:
self->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(5), CCCallFunc::actionWithTarget(self, @selector(resetMessage)), nil);
You can do it (under some assumptions, such as no use of arrays) but you really need to work inside out and to put your substitution code in a loop.
The code above is rather brittle as it doesn’t actually understand Objective-C, so you should check that its output is reasonable on your real input data…