def matchPreviousLiteral(expr):
rep = Forward()<EOL>def copyTokenToRepeater(s,l,t):<EOL><INDENT>if t:<EOL><INDENT>if len(t) == <NUM_LIT:1>:<EOL><INDENT>rep << t[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>tflat = _flatten(t.asList())<EOL>rep << And( [ Literal(tt) for tt in tflat ] )<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rep << Empty()<EOL><DEDENT><DEDENT>expr.addParseAction(copyTokenToRepeater, callDuringTry=True)<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 = matchPreviousLiteral(first)
           matchExpr = first + ":" + second
       will match C{"1:1"}, but not C{"1:2"}.  Because this matches a
       previous literal, will also match the leading C{"1:1"} in C{"1:10"}.
       If this is not desired, use C{matchPreviousExpr}.
       Do *not* use with packrat parsing enabled.