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