def iterate(self, order: int) -> 'NodeIterator': if self._last_node is None: self._last_node = Node(node_ext=next(self._iter_ext), ctx=self.ctx) TreeOrder.check_order(order) self._order = order return NodeIterator(iterator((self._last_node.node_ext), order), self.ctx)
def __next__(self) -> Union[ResultMultiType, Node]: next_node = next(self._iter_ext) if isinstance(next_node, NodeExt): # save last node for potential re-iteration self._last_node = Node(node_ext=next_node) return self._last_node # non node (bool, str, etc) return next_node
def __next__(self) -> Node: next_val = next(self._nodeit) is_node = isinstance(next_val, Node) val = next_val.internal_node if is_node else next_val # Skip positions and non dicts/lists, the later if only_nodes = True skip = False if isinstance(val, dict): if "@type" not in val or val["@type"] == "uast:Positions": skip = True elif self._only_nodes: skip = True if skip: val = self.__next__().internal_node ret_val = next_val if is_node else Node(value=val) self._last_node = ret_val return ret_val
def root(self) -> Node: return Node(node_ext=self.ctx.root(), ctx=self.ctx)