MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / previous_sibling

Function previous_sibling

src/codetext/parser/language_parser.py:48–63  ·  view source on GitHub ↗

Search for the previous sibling of the node. TODO: C TreeSitter should support this natively, but not its Python bindings yet. Replace later.

(tree, node)

Source from the content-addressed store, hash-verified

46
47
48def previous_sibling(tree, node):
49 """
50 Search for the previous sibling of the node.
51 TODO: C TreeSitter should support this natively, but not its Python bindings yet. Replace later.
52 """
53 to_visit = [tree.root_node]
54 while len(to_visit) > 0:
55 next_node = to_visit.pop()
56 for i, node_at_i in enumerate(next_node.children):
57 if nodes_are_equal(node, node_at_i):
58 if i > 0:
59 return next_node.children[i-1]
60 return None
61 else:
62 to_visit.extend(next_node.children)
63 return ValueError("Could not find node in tree.")
64
65
66# if parent_node.type == 'variable_declarator':

Callers

nothing calls this directly

Calls 1

nodes_are_equalFunction · 0.85

Tested by

no test coverage detected