Exemplo n.º 1
0
 def __call__(self, t):
     if t.root == self.head:
         if not self.params and not self.body.subtrees:  # e.g. "r := q"
             return TreeTransform.Scalar(self.body.root)
         elif len(t.subtrees) == len(
                 self.params):  # e.g. "r := p(a,b)" or "r(a) := p(a,b)"
             tun = self.o.tuning
             subst = dict(
                 map(self._single_out, zip(self.params, t.subtrees)))
             body = tun.local_.before(self.body)
             return tun.local_.after(TreeSubstitution(subst)(body))
Exemplo n.º 2
0
 def __call__(self, tree):
     w = self.replace_what
     if isinstance(w, type(tree)):
         compare_with = w
     else:
         compare_with = type(tree)(w)
     if tree.root == w and isinstance(self.replace_with, list):
         return type(tree)([], self.replace_with)
     if tree.root == w and not isinstance(self.replace_with,
                                          type(tree)):
         return TreeTransform.Scalar(self.replace_with)
     elif tree == compare_with:
         if isinstance(self.replace_with, list):
             return type(tree)([], self.replace_with)
         elif isinstance(self.replace_with, type(tree)):
             return self.replace_with
         else:
             return type(tree)(self.replace_with)