Doug Dickinson - 2008-03-01

Hi,  I had a little thought about replacement and type conversion.  How about adding the possibility of using an NSValueTransformer to do a conversion.  It would be very similar to the decimal or date conversions you currently have, but would open up a lot of conversion possibilities.  I'm imagining something like this (NB This is just the first syntax that came into my head, I'm not wild about it - especially the multiple colons and nested braces):

${1:@v:MyTransformerName}

where MyTransformerName would be the name of a transformer which was previously registered using NSValueTransformer's +setValueTransformer:forName: method. 

What would be even more flexible is if the transformer could take an array of values.  Again, the syntax is a bit tough to imagine, but the possibilities are huge:

${@v:SumOfInputs:${1:%d},${2:%x},${42:%f}}

or

${@v:LongestString:$3, $4, $5}

This assumes the value transformer does some operation or set of operations which turn the array into a single output.  It would be even better if it could also output an array.  That would be straightforward when doing the capturing in Objective-C, but it would be nice to have a syntax that worked in text as well.  What about:

${@v:<firstWord>,<secondWord>,<thirdWord>=Alphabetise:$1,$2,$3}

this wouldn't actually output anything, it would create new captures called "firstWord", "secondWord" etc, which could be used later in the expression.  So for example,

subject: John, Paul, George, Ringo
regex:  \w*, \w*, \w*, \w*
replacement: "${@v:<b1>,<b2>,<b3>,<b4>=Alphabetise:$1,$2,$3,$4}The Beatles, $<b1>, $<b2>, $<b3> and $<b4> sang and played musical instruments"
result: The Beatles, George, John, Paul and Ringo sang and played musical instruments

or even (going from the weird to the weirder still)

${@v:<words>=AlphabetiseArray:$1,$2,$3}

and then introduce the ability to use a subscript in the capture replacement

subject and regex as above
replacement: "${@v:<beatle>=Alphabetise:$1,$2,$3,$4}The Beatles, $<beatle[1]>, $<beatle[2]>, $<beatle[3]> and $<beatle[4]> sang and played musical instruments"
result as above

I guess for consistency, it could boil down to something like this to handle all cases:

{@v:<captureName>=TransformerName:arg1,arg2...}

and that never outputs anything, but it makes captureName available for use thereafter.

Regards
Doug Dickinson --dd