Exemplo n.º 1
0
def SplitAllKeep(operand, ):
    splitall = util.Proxy()
    splitall.subject = (combine.GuardedChoice(
        SplitKeep(operand),
        congruent.Cons(base.ident,
                       congruent.Cons(base.ident, project.head * splitall)),
        build.List((base.ident, ))))
    return splitall
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def SplitBefore(operand):
    tail = types.term.Term('tail')
    return scope.Scope(
        (tail, ),
        build.List((AtSuffix(
            congruent.Cons(operand, base.ident) * match.Var(tail) * build.nil),
                    build.Var(tail))))
Exemplo n.º 5
0
def SplitAfter(operand):
    tail = types.term.Term('tail')
    return scope.Scope(
        (tail, ),
        build.List(
            (AtSuffix(congruent.Cons(operand,
                                     match.Var(tail) * build.nil)),
             build.Var(tail))))
Exemplo n.º 6
0
def AtSuffixR(operand):
    atsuffix = util.Proxy()
    atsuffix.subject = combine.Choice(congruent.Cons(base.ident, atsuffix),
                                      operand)
    return atsuffix