(self,other)
return ret
Implementation of * operator, allows use of ``expr * 3`` in place of
        ``expr + expr + expr``.  Expressions may also me multiplied by a 2-integer
        tuple, similar to ``{min,max}`` multipliers in regular expressions.  Tuples
        may also include ``None`` as in:
         - ``expr*(n,None)`` or ``expr*(n,)`` is equivalent
              to ``expr*n + ZeroOrMore(expr)``
              (read as "at least n instances of ``expr``")
         - ``expr*(None,n)`` is equivalent to ``expr*(0,n)``
              (read as "0 to n instances of ``expr``")
         - ``expr*(None,None)`` is equivalent to ``ZeroOrMore(expr)``
         - ``expr*(1,None)`` is equivalent to ``OneOrMore(expr)``

        Note that ``expr*(None,n)`` does not raise an exception if
        more than n exprs exist in the input stream; that is,
        ``expr*(None,n)`` does not enforce a maximum number of expr
        occurrences.  If this behavior is desired, then write
        ``expr*(None,n) + ~expr``
Implementation of * operator, allows use of ``expr * 3`` in place of
        ``expr + expr + expr``.  Expressions may also me multiplied by a 2-integer
        tuple, similar to ``{min,max}`` multipliers in regular expressions.  Tuples
        may also include ``None`` as in:
         - ``expr*(n,None)`` or ``expr*(n,)`` is equivalent
              to ``expr*n + ZeroOrMore(expr)``
              (read as "at least n instances of ``expr``")
         - ``expr*(None,n)`` is equivalent to ``expr*(0,n)``
              (read as "0 to n instances of ``expr``")
         - ``expr*(None,None)`` is equivalent to ``ZeroOrMore(expr)``
         - ``expr*(1,None)`` is equivalent to ``OneOrMore(expr)``
Implementation of * operator allows use of expr * 3 in place of expr + expr + expr . Expressions may also me multiplied by a 2 - integer tuple similar to { min max } multipliers in regular expressions . Tuples may also include None as in : - expr * ( n None ) or expr * ( n ) is equivalent to expr * n + ZeroOrMore ( expr ) ( read as at least n instances of expr ) - expr * ( None n ) is equivalent to expr * ( 0 n ) ( read as 0 to n instances of expr ) - expr * ( None None ) is equivalent to ZeroOrMore ( expr ) - expr * ( 1 None ) is equivalent to OneOrMore ( expr )
def __mul__(self,other):
        """
        Implementation of * operator, allows use of ``expr * 3`` in place of
        ``expr + expr + expr``.  Expressions may also me multiplied by a 2-integer
        tuple, similar to ``{min,max}`` multipliers in regular expressions.  Tuples
        may also include ``None`` as in:
         - ``expr*(n,None)`` or ``expr*(n,)`` is equivalent
              to ``expr*n + ZeroOrMore(expr)``
              (read as "at least n instances of ``expr``")
         - ``expr*(None,n)`` is equivalent to ``expr*(0,n)``
              (read as "0 to n instances of ``expr``")
         - ``expr*(None,None)`` is equivalent to ``ZeroOrMore(expr)``
         - ``expr*(1,None)`` is equivalent to ``OneOrMore(expr)``

        Note that ``expr*(None,n)`` does not raise an exception if
        more than n exprs exist in the input stream; that is,
        ``expr*(None,n)`` does not enforce a maximum number of expr
        occurrences.  If this behavior is desired, then write
        ``expr*(None,n) + ~expr``
        """
        if isinstance(other,int):
            minElements, optElements = other,0
        elif isinstance(other,tuple):
            other = (other + (None, None))[:2]
            if other[0] is None:
                other = (0, other[1])
            if isinstance(other[0],int) and other[1] is None:
                if other[0] == 0:
                    return ZeroOrMore(self)
                if other[0] == 1:
                    return OneOrMore(self)
                else:
                    return self*other[0] + ZeroOrMore(self)
            elif isinstance(other[0],int) and isinstance(other[1],int):
                minElements, optElements = other
                optElements -= minElements
            else:
                raise TypeError("cannot multiply 'ParserElement' and ('%s','%s') objects", type(other[0]),type(other[1]))
        else:
            raise TypeError("cannot multiply 'ParserElement' and '%s' objects", type(other))

        if minElements < 0:
            raise ValueError("cannot multiply ParserElement by negative value")
        if optElements < 0:
            raise ValueError("second tuple value must be greater or equal to first tuple value")
        if minElements == optElements == 0:
            raise ValueError("cannot multiply ParserElement by 0 or (0,0)")

        if (optElements):
            def makeOptionalList(n):
                if n>1:
                    return Optional(self + makeOptionalList(n-1))
                else:
                    return Optional(self)
            if minElements:
                if minElements == 1:
                    ret = self + makeOptionalList(optElements)
                else:
                    ret = And([self]*minElements) + makeOptionalList(optElements)
            else:
                ret = makeOptionalList(optElements)
        else:
            if minElements == 1:
                ret = self
            else:
                ret = And([self]*minElements)
        return ret
def __mul__ ( self , other ) : if isinstance ( other , int ) : minElements , optElements = other , 0 elif isinstance ( other , tuple ) : other = ( other + ( None , None ) ) [ : 2 ] if other [ 0 ] is None : other = ( 0 , other [ 1 ] ) if isinstance ( other [ 0 ] , int ) and other [ 1 ] is None : if other [ 0 ] == 0 : return ZeroOrMore ( self ) if other [ 0 ] == 1 : return OneOrMore ( self ) else : return self * other [ 0 ] + ZeroOrMore ( self ) elif isinstance ( other [ 0 ] , int ) and isinstance ( other [ 1 ] , int ) : minElements , optElements = other optElements -= minElements else : raise TypeError ( "cannot multiply 'ParserElement' and ('%s','%s') objects" , type ( other [ 0 ] ) , type ( other [ 1 ] ) ) else : raise TypeError ( "cannot multiply 'ParserElement' and '%s' objects" , type ( other ) ) if minElements < 0 : raise ValueError ( "cannot multiply ParserElement by negative value" ) if optElements < 0 : raise ValueError ( "second tuple value must be greater or equal to first tuple value" ) if minElements == optElements == 0 : raise ValueError ( "cannot multiply ParserElement by 0 or (0,0)" ) if ( optElements ) : def makeOptionalList ( n ) : if n > 1 : return Optional ( self + makeOptionalList ( n - 1 ) ) else : return Optional ( self ) if minElements : if minElements == 1 : ret = self + makeOptionalList ( optElements ) else : ret = And ( [ self ] * minElements ) + makeOptionalList ( optElements ) else : ret = makeOptionalList ( optElements ) else : if minElements == 1 : ret = self else : ret = And ( [ self ] * minElements ) return ret