chore: Checkpoint commit of unstaged changes, including new tests and debug scripts
This commit is contained in:
29
inspect_ast.py
Normal file
29
inspect_ast.py
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
import tree_sitter
|
||||
import tree_sitter_python
|
||||
|
||||
language = tree_sitter.Language(tree_sitter_python.language())
|
||||
parser = tree_sitter.Parser(language)
|
||||
|
||||
code = """
|
||||
@core_logic
|
||||
def decorated_func():
|
||||
"""Docstring."""
|
||||
print("core logic here")
|
||||
|
||||
def hot_func():
|
||||
# [HOT]
|
||||
print("hot logic here")
|
||||
|
||||
def normal_func():
|
||||
print("normal logic here")
|
||||
"""
|
||||
|
||||
tree = parser.parse(bytes(code, "utf8"))
|
||||
|
||||
def print_node(node, indent=0):
|
||||
print(" " * indent + f"{node.type} [{node.start_byte}-{node.end_byte}] " + (f"'{code[node.start_byte:node.end_byte]}'" if node.type in ["decorator", "comment", "identifier"] else ""))
|
||||
for child in node.children:
|
||||
print_node(child, indent + 1)
|
||||
|
||||
print_node(tree.root_node)
|
||||
Reference in New Issue
Block a user