def matchPreviousExpr(expr):
 rep = Forward()
 e2 = expr.copy()
 rep <<= e2
 def copyTokenToRepeater(s, l, t):
  matchTokens = _flatten(t.asList())
  def mustMatchTheseTokens(s, l, t):
   theseTokens = _flatten(t.asList())
   if (theseTokens != matchTokens):
    raise ParseException('', 0, '')
  rep.setParseAction(mustMatchTheseTokens, callDuringTry=True)
 expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
 rep.setName(('(prev) ' + _ustr(expr)))
 return rep

def matchPreviousExpr ( expr ) : rep = Forward ( ) e2 = expr . copy ( ) rep <<= e2 def copyTokenToRepeater ( s , l , t ) : matchTokens = _flatten ( t . asList ( ) ) def mustMatchTheseTokens ( s , l , t ) : theseTokens = _flatten ( t . asList ( ) ) if ( theseTokens != matchTokens ) : raise ParseException ( '' , 0 , '' ) rep . setParseAction ( mustMatchTheseTokens , callDuringTry = True ) expr . addParseAction ( copyTokenToRepeater , callDuringTry = True ) rep . setName ( ( '(prev) ' + _ustr ( expr ) ) ) return rep
helper to define an expression that is indirectly defined from the tokens matched in a previous expression .