def originalTextFor(expr, asString=True):
 locMarker = Empty().setParseAction((lambda s, loc, t: loc))
 endlocMarker = locMarker.copy()
 endlocMarker.callPreparse = False
 matchExpr = ((locMarker('_original_start') + expr) + endlocMarker('_original_end'))
 if asString:
  extractText = (lambda s, l, t: s[t._original_start:t._original_end])
 else:
  def extractText(s, l, t):
   del t[:]
   t.insert(0, s[t._original_start:t._original_end])
   del t['_original_start']
   del t['_original_end']
 matchExpr.setParseAction(extractText)
 return matchExpr

def originalTextFor ( expr , asString = True ) : locMarker = Empty ( ) . setParseAction ( ( lambda s , loc , t : loc ) ) endlocMarker = locMarker . copy ( ) endlocMarker . callPreparse = False matchExpr = ( ( locMarker ( '_original_start' ) + expr ) + endlocMarker ( '_original_end' ) ) if asString : extractText = ( lambda s , l , t : s [ t . _original_start : t . _original_end ] ) else : def extractText ( s , l , t ) : del t [ : ] t . insert ( 0 , s [ t . _original_start : t . _original_end ] ) del t [ '_original_start' ] del t [ '_original_end' ] matchExpr . setParseAction ( extractText ) return matchExpr
helper to return the original .