Files
manual_slop/debug_ast.py
2026-02-28 09:06:45 -05:00

19 lines
498 B
Python

import tree_sitter
import tree_sitter_python
code = """def hot_func():
# [HOT]
print(1)"""
PY_LANGUAGE = tree_sitter.Language(tree_sitter_python.language())
parser = tree_sitter.Parser(PY_LANGUAGE)
tree = parser.parse(bytes(code, "utf8"))
def walk(node, indent=0):
content = code[node.start_byte:node.end_byte].strip()
print(f"{' ' * indent}{node.type} ({node.start_byte}-{node.end_byte}): {content[:20]}")
for child in node.children:
walk(child, indent + 1)
walk(tree.root_node)