def transformString( self, instring ):
out = []<EOL>lastE = <NUM_LIT:0><EOL>self.keepTabs = True<EOL>for t,s,e in self.scanString( instring ):<EOL><INDENT>out.append( instring[lastE:s] )<EOL>if t:<EOL><INDENT>if isinstance(t,ParseResults):<EOL><INDENT>out += t.asList()<EOL><DEDENT>elif isinstance(t,list):<EOL><INDENT>out += t<EOL><DEDENT>else:<EOL><INDENT>out.append(t)<EOL><DEDENT><DEDENT>lastE = e<EOL><DEDENT>out.append(instring[lastE:])<EOL>return "<STR_LIT>".join(map(_ustr,out))<EOL>
Extension to scanString, to modify matching text with modified tokens that may
           be returned from a parse action.  To use transformString, define a grammar and
           attach a parse action to it that modifies the returned token list.
           Invoking transformString() on a target string will then scan for matches,
           and replace the matched text patterns according to the logic in the parse
           action.  transformString() returns the resulting transformed string.