def matchPreviousLiteral(expr):
 rep = Forward()
 def copyTokenToRepeater(s, l, t):
  if t:
   if (len(t) == 1):
    (rep << t[0])
   else:
    tflat = _flatten(t.asList())
    (rep << And([Literal(tt) for tt in tflat]))
  else:
   (rep << Empty())
 expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
 return rep

def matchPreviousLiteral ( expr ) : rep = Forward ( ) def copyTokenToRepeater ( s , l , t ) : if t : if ( len ( t ) == 1 ) : ( rep << t [ 0 ] ) else : tflat = _flatten ( t . asList ( ) ) ( rep << And ( [ Literal ( tt ) for tt in tflat ] ) ) else : ( rep << Empty ( ) ) expr . addParseAction ( copyTokenToRepeater , callDuringTry = True ) return rep
helper to define an expression that is indirectly defined from the tokens matched in a previous expression .