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
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
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
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))))
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))))
def AtSuffixR(operand): atsuffix = util.Proxy() atsuffix.subject = combine.Choice(congruent.Cons(base.ident, atsuffix), operand) return atsuffix