Ejemplo n.º 1
0
 def _extend_cst(self, node):
     if node is None:
         return
     previous = self.cst
     if previous is None:
         self.cst = self._copy_node(node)
     elif is_list(node):
         if is_list(previous):
             previous.extend(node)
         else:
             self.cst = [previous] + node
     elif is_list(previous):
         previous.append(node)
     else:
         self.cst = [previous, node]
Ejemplo n.º 2
0
 def _extend_cst(self, node):
     if node is None:
         return
     previous = self.cst
     if previous is None:
         self.cst = self._copy_node(node)
     elif is_list(node):
         if is_list(previous):
             previous.extend(node)
         else:
             self.cst = [previous] + node
     elif is_list(previous):
         previous.append(node)
     else:
         self.cst = [previous, node]
Ejemplo n.º 3
0
 def _copy_node(self, node):
     if node is None:
         return None
     elif is_list(node):
         return node[:]
     else:
         return node
Ejemplo n.º 4
0
 def _copy_node(self, node):
     if node is None:
         return None
     elif is_list(node):
         return node[:]
     else:
         return node
Ejemplo n.º 5
0
 def walk(self, node, *args, **kwargs):
     supers_walk = super(DepthFirstWalker, self).walk
     if isinstance(node, Node):
         children = [self.walk(c, *args, **kwargs) for c in node.children()]
         return supers_walk(node, children, *args, **kwargs)
     elif isinstance(node, collections.Mapping):
         return {n: self.walk(e, *args, **kwargs) for n, e in node.items()}
     elif is_list(node):
         return [self.walk(e, *args, **kwargs) for e in iter(node)]
     else:
         return supers_walk(node, [], *args, **kwargs)
Ejemplo n.º 6
0
 def walk(self, node, *args, **kwargs):
     supers_walk = super(DepthFirstWalker, self).walk
     if isinstance(node, Node):
         children = [self.walk(c, *args, **kwargs) for c in node.children()]
         return supers_walk(node, children, *args, **kwargs)
     elif isinstance(node, collections.Mapping):
         return {n: self.walk(e, *args, **kwargs) for n, e in node.items()}
     elif is_list(node):
         return [self.walk(e, *args, **kwargs) for e in iter(node)]
     else:
         return supers_walk(node, [], *args, **kwargs)
Ejemplo n.º 7
0
    def set(self, key, value, force_list=False):
        key = self._safekey(key)

        previous = self.get(key, None)
        if previous is None:
            if force_list:
                super(AST, self).__setitem__(key, [value])
            else:
                super(AST, self).__setitem__(key, value)
            self._order.append(key)
        elif is_list(previous):
            previous.append(value)
        else:
            super(AST, self).__setitem__(key, [previous, value])
        return self
Ejemplo n.º 8
0
    def set(self, key, value, force_list=False):
        key = self._safekey(key)

        previous = self.get(key, None)
        if previous is None:
            if force_list:
                super(AST, self).__setitem__(key, [value])
            else:
                super(AST, self).__setitem__(key, value)
            self._order.append(key)
        elif is_list(previous):
            previous.append(value)
        else:
            super(AST, self).__setitem__(key, [previous, value])
        return self
Ejemplo n.º 9
0
 def copy(self):
     return AST(
         (k, v[:] if is_list(v) else v)
         for k, v in self.items()
     )
Ejemplo n.º 10
0
 def copy(self):
     return AST((k, v[:] if is_list(v) else v) for k, v in self.items())