Beispiel #1
0
def SplitAllAfter(operand, ):
    splitall = util.Proxy()
    splitall.subject = (combine.GuardedChoice(
        SplitAfter(operand), congruent.Cons(base.ident,
                                            project.head * splitall),
        build.List((base.ident, ))))
    return splitall
Beispiel #2
0
def Foldr(tail, Cons, operand=None):
    if operand is None:
        operand = base.ident
    foldr = util.Proxy()
    foldr.subject = combine.GuardedChoice(
        match.nil, tail,
        Cons(combine.Composition(project.head, operand),
             combine.Composition(project.tail, foldr)))
    return foldr
Beispiel #3
0
    def __pow__(self, other):
        '''Exponentiation operater. Shorthand for L{lib.combine.GuardedChoice}.

		For example, C{t1 **t2** t3} is equivalent, to C{lib.combine.GuardedChoice(t1, t2,
		t3)}. The exponentiation operator is right associative, so C{t1 **t2** t3
		**t4** t5} is the same as C{t1 **t2** (t3 **t4** t5)}. However note that its
		precedence is higher than other operators, therefore parenthesis must be used
		around them.

		@see: U{http://docs.python.org/ref/summary.html} for a summary of Python's
		operators precedence.
		'''
        #warnings.warn("using deprecated guarded choice operator", DeprecationWarning, stacklevel=2)
        from transf.lib import combine
        if isinstance(other, tuple):
            return combine.GuardedChoice(self, *other)
        else:
            return (self, other)
Beispiel #4
0
def _CountOne(operand):
    return combine.GuardedChoice(operand, build.one, build.zero)
Beispiel #5
0
def Leaves(operand, isLeaf):
    return iterate.Rec(
        lambda self: combine.GuardedChoice(isLeaf, operand, All(self)))
Beispiel #6
0
def ManyBU(operand):
    return iterate.Rec(lambda self: combine.GuardedChoice(
        Some(self), combine.Try(operand), operand))
Beispiel #7
0
def ManyTD(operand):
    return iterate.Rec(lambda self: combine.GuardedChoice(
        operand, All(combine.Try(self)), Some(self)))