def matchPreviousExpr(expr):
rep = Forward()<EOL>e2 = expr.copy()<EOL>rep <<= e2<EOL>def copyTokenToRepeater(s,l,t):<EOL><INDENT>matchTokens = _flatten(t.asList())<EOL>def mustMatchTheseTokens(s,l,t):<EOL><INDENT>theseTokens = _flatten(t.asList())<EOL>if  theseTokens != matchTokens:<EOL><INDENT>raise ParseException("<STR_LIT>",<NUM_LIT:0>,"<STR_LIT>")<EOL><DEDENT><DEDENT>rep.setParseAction( mustMatchTheseTokens, callDuringTry=True )<EOL><DEDENT>expr.addParseAction(copyTokenToRepeater, callDuringTry=True)<EOL>rep.setName('<STR_LIT>' + _ustr(expr))<EOL>return rep<EOL>
Helper to define an expression that is indirectly defined from
    the tokens matched in a previous expression, that is, it looks for
    a 'repeat' of a previous expression.  For example::

        first = Word(nums)
        second = matchPreviousExpr(first)
        matchExpr = first + ":" + second

    will match ``"1:1"``, but not ``"1:2"``.  Because this
    matches by expressions, will *not* match the leading ``"1:1"``
    in ``"1:10"``; the expressions are evaluated first, and then
    compared, so ``"1"`` is compared with ``"10"``. Do *not* use
    with packrat parsing enabled.