Пример #1
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
Пример #2
0
def DownUp(down=None, up=None, stop=None):
    downup = util.Proxy()
    downup.subject = All(downup)
    if stop is not None:
        downup.subject = combine.Choice(stop, downup.subject)
    if up is not None:
        downup.subject = combine.Composition(downup.subject, up)
    if down is not None:
        downup.subject = combine.Composition(down, downup.subject)
    return downup
Пример #3
0
def Traverse(Subterms, down=None, up=None, stop=None, Enter=None, Leave=None):
    '''Generic traversal.'''
    traverse = util.Proxy()
    traverse.subject = Subterms(traverse)
    if Leave is not None:
        traverse.subject = Leave(traverse.subject)
    if stop is not None:
        traverse.subject = combine.Choice(stop, traverse.subject)
    if up is not None:
        traverse.subject = combine.Composition(traverse.subject, up)
    if down is not None:
        traverse.subject = combine.Composition(down, traverse.subject)
    if Enter is not None:
        traverse.subject = Enter(traverse.subject)
    return traverse
Пример #4
0
from transf import exception
from transf import transformation
from transf import operate
from transf.lib import base
from transf.lib import combine
from transf.lib import match
from transf.lib import build
from transf.lib import project
from transf.lib import annotation


_factory = aterm.factory.factory


get = combine.Composition(
	annotation.Get(match.ApplName('Path')),
	combine.Composition(project.args, project.first)
)


class Annotate(transformation.Transformation):
	'''Transformation which annotates the path of terms and subterms for which the
	supplied transformation succeeds.'''

	def __init__(self, operand = None, root = None):
		transformation.Transformation.__init__(self)
		if operand is None:
			self.operand = base.ident
		else:
			self.operand = operand
		if root is None:
			self.root = build.nil
Пример #5
0
def ApplNames(names):
    return combine.Where(combine.Composition(project.name, StrSet(names)))
Пример #6
0
def ApplName(name):
    return combine.Where(combine.Composition(project.name, Str(name)))
Пример #7
0
def Get(label):
    return combine.Composition(project.annos, lists.Fetch(label))
Пример #8
0
def Crush(tail, Cons, operand=None):
    return combine.Composition(project.subterms, Foldr(tail, Cons, operand))
Пример #9
0
head = Head()


class Tail(transformation.Transformation):
    def apply(self, trm, ctx):
        try:
            return trm.tail
        except AttributeError:
            raise exception.Failure("not a list construction term", trm)


tail = Tail()

first = head
second = combine.Composition(tail, first)
third = combine.Composition(tail, second)
fourth = combine.Composition(tail, third)


def Nth(n):
    if n > 1:
        nth = Tail()
        for i in range(2, n):
            nth = nth * tail
        nth = nth * head
    elif n < 1:
        raise ValueError
    else:  # n = 1
        n = head
Пример #10
0
def InnerMost(operand):
    innermost = util.Proxy()
    innermost.subject = BottomUp(
        combine.Try(combine.Composition(operand, innermost)))
    return innermost
Пример #11
0
 def __mul__(self, other):
     '''Multiplication operator. Shorthand for L{lib.combine.Composition}'''
     #warnings.warn("using deprecated composition operator", DeprecationWarning, stacklevel=2)
     from transf.lib import combine
     return combine.Composition(self, other)