コード例 #1
0
ファイル: traverse.py プロジェクト: uxmal/idc
def OnceTD(operand, stop=None):
    '''Performs a left to right depth first search/transformation that
	stops as soon as the the transformation has been successfuly applied.
	'''
    if stop is None:
        return iterate.Rec(lambda self: combine.Choice(operand, One(self)))
    else:
        return iterate.Rec(
            lambda self: combine.Choice(operand, -stop * One(self)))
コード例 #2
0
ファイル: traverse.py プロジェクト: uxmal/idc
def AllTD(operand):
    '''Apply a transformation to all subterms, but stops recursing
	as soon as it finds a subterm to which the transformation succeeds.
	'''
    alltd = util.Proxy()
    alltd.subject = combine.Choice(operand, All(alltd))
    return alltd
コード例 #3
0
ファイル: traverse.py プロジェクト: uxmal/idc
def One(operand):
    '''Applies a transformation to exactly one direct subterm of a term.'''
    one = util.Proxy()
    one.subject = congruent.Subterms(
        # FIXME: write a non-recursive implementation
        combine.Choice(congruent.Cons(operand, base.ident),
                       congruent.Cons(base.ident, one)),
        base.fail)
    return one
コード例 #4
0
ファイル: traverse.py プロジェクト: uxmal/idc
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
コード例 #5
0
ファイル: traverse.py プロジェクト: uxmal/idc
def Some(operand):
    '''Applies a transformation to as many direct subterms of a term, but at list one.'''
    some = util.Proxy()
    some.subject = congruent.Subterms(
        # FIXME: write a non-recursive implementation
        combine.Choice(
            congruent.Cons(operand, lists.Map(combine.Try(operand))),
            congruent.Cons(base.ident, some),
        ),
        base.fail)
    return some
コード例 #6
0
ファイル: traverse.py プロジェクト: uxmal/idc
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
コード例 #7
0
def AtSuffixR(operand):
    atsuffix = util.Proxy()
    atsuffix.subject = combine.Choice(congruent.Cons(base.ident, atsuffix),
                                      operand)
    return atsuffix
コード例 #8
0
ファイル: traverse.py プロジェクト: uxmal/idc
def AllBU(operand):
    allbu = util.Proxy()
    allbu.subject = combine.Choice(All(allbu), operand)
    return allbu
コード例 #9
0
ファイル: traverse.py プロジェクト: uxmal/idc
def SomeBU(operand):
    return iterate.Rec(lambda self: combine.Choice(Some(self), operand))
コード例 #10
0
ファイル: traverse.py プロジェクト: uxmal/idc
def SomeTD(operand):
    return iterate.Rec(lambda self: combine.Choice(operand, Some(self)))
コード例 #11
0
ファイル: traverse.py プロジェクト: uxmal/idc
def OnceBU(operand):
    return iterate.Rec(lambda self: combine.Choice(One(self), operand))
コード例 #12
0
ファイル: transformation.py プロジェクト: uxmal/idc
 def __add__(self, other):
     '''Addition operator. Shorthand for L{lib.combine.Choice}'''
     #warnings.warn("using deprecated choice operator", DeprecationWarning, stacklevel=2)
     from transf.lib import combine
     return combine.Choice(self, other)