fix python parsing, update deps
python parsing was broken & openai changed their internal API
This commit is contained in:
0
parse/__init__.py
Normal file
0
parse/__init__.py
Normal file
30
parse/py.py
Normal file
30
parse/py.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import re
|
||||
|
||||
def find_toplevel_funcs(lines):
|
||||
functions = []
|
||||
function_head = ""
|
||||
function_content = ""
|
||||
function_body_indent_level = 0
|
||||
|
||||
for line in lines:
|
||||
curr_indent_level = len(line) - len(line.lstrip())
|
||||
function_found = re.search('^def(\s+)(.*)\(.*\)(\s*):(\s*)$', line.strip())
|
||||
|
||||
if len(function_head.strip()) > 0 and (curr_indent_level < function_body_indent_level):
|
||||
functions.append({
|
||||
"head": function_head,
|
||||
"content": function_content
|
||||
})
|
||||
if function_found:
|
||||
function_head = ""
|
||||
function_content = ""
|
||||
|
||||
if function_found and len(function_head) == 0:
|
||||
function_head = re.search("(\s+)(.*)\(.*\)", line).string.replace('def', '').replace('):', ')').strip()
|
||||
function_content = line
|
||||
function_body_indent_level = curr_indent_level + 1
|
||||
|
||||
elif not function_found and len(function_head.strip()) > 0 and curr_indent_level >= function_body_indent_level:
|
||||
function_content += line
|
||||
|
||||
return functions
|
||||
Reference in New Issue
Block a user