Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase recursion limit and add error handling for deep recursion of… #747

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions transforms/code/code_profiler/python/src/UAST_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import json
from tree_sitter import Tree
import os
import sys
sys.setrecursionlimit(10000)

"""
Initialize the parser with a path for rules and grammar.
"""
Expand Down Expand Up @@ -251,7 +254,10 @@ def _dfs(self, AST_node, parent) :
parent = node

for child in AST_node.children:
self._dfs(AST_node= child, parent = parent)
try:
self._dfs(AST_node= child, parent = parent)
except RecursionError as e:
print(f"RecursionError caught: {str(e)}")

def _extract(self, ast_snippet, node_type, exec_string):
code_snippet = ast_snippet
Expand All @@ -262,4 +268,4 @@ def _extract(self, ast_snippet, node_type, exec_string):
try:
return self.grammar[node_type]["keyword"] + " " + self.extracted
except Exception as e:
print(e)
print(e)