@@ -5,17 +5,17 @@ def main():
55
66 try :
77 with open ("defs.txt" , "r" , encoding = "utf-8" ) as defs_file :
8- defs_data = defs_file .readlines ( )
8+ defs_data = defs_file .read (). split ( ' \n ' )
99 except IOError :
1010 print ("Unable to locate defs file" )
1111 quit ()
12-
12+
1313 functions = parse_defs (defs_data )
1414 sorted_keys = sorted (list (functions .keys ()))# Good for comparing diffs
1515 function_registry = generate_snippet_format (sorted_keys , functions )
1616
17- with open ("squirrel.json" , "w" , encoding = "utf-8" ) as json_test :
18- dump (function_registry , json_test , indent = 2 )
17+ with open ("squirrel.json" , "w" , encoding = "utf-8" ) as squirrel_json :
18+ dump (function_registry , squirrel_json , indent = 2 )
1919
2020def parse_defs (defs_data : str ) -> dict :
2121 '''
@@ -31,28 +31,26 @@ def parse_defs(defs_data: str) -> dict:
3131 functions = {}
3232 quad_defs_entry = 0
3333 most_recent_function = ""
34+
3435 for line in defs_data :
35- text = line [0 :- 1 ] # necessary because ".readlines()" injects newlines
3636
3737 match ["function" , "signature" , "description" , "space" ][quad_defs_entry % 4 ]:
3838 case "function" :
39- most_recent_function = text
39+ most_recent_function = line
4040 functions [most_recent_function ] = {
41- "function" : text ,
41+ "function" : line ,
4242 "signature" : "" ,
4343 "description" : "" ,
4444 }
4545 case "signature" :
4646 if functions [most_recent_function ]["signature" ] == "" :
47- functions [most_recent_function ]["signature" ] = text
47+ functions [most_recent_function ]["signature" ] = line
4848 case "description" :
4949 if functions [most_recent_function ]["description" ] == "" :
50- functions [most_recent_function ]["description" ] = text .replace (
50+ functions [most_recent_function ]["description" ] = line .replace (
5151 "\\ " , "\\ \\ "
5252 )
53- functions [most_recent_function ]["description" ] = functions [
54- most_recent_function
55- ]["description" ].replace ('"' , '\\ "' )
53+ functions [most_recent_function ]["description" ] = functions [most_recent_function ]["description" ].replace ('"' , '\\ "' )
5654
5755 quad_defs_entry += 1
5856 return functions
@@ -74,11 +72,13 @@ def generate_snippet_format(sorted_keys: list[str], functions: dict) -> dict:
7472 for key in sorted_keys :
7573 prefix , body = "" , ""
7674 base_signature = functions [key ]["signature" ]
77- paren_index = base_signature .find ("(" )
78- if paren_index >= 0 :
79- prefix = base_signature [0 :paren_index ].split (" " )[- 1 ]
75+
76+ parentheses_index = base_signature .find ("(" )
77+
78+ if parentheses_index >= 0 :
79+ prefix = base_signature [0 :parentheses_index ].split (" " )[- 1 ]
8080 # We need to parse params
81- params = base_signature [paren_index + 1 : - 1 ].split (", " )
81+ params = base_signature [parentheses_index + 1 : - 1 ].split (", " )
8282 body = prefix + "("
8383 quad_defs_entry = 1
8484 if params [0 ] != "" :
@@ -102,6 +102,7 @@ def generate_snippet_format(sorted_keys: list[str], functions: dict) -> dict:
102102 }
103103 }
104104 function_registry .update (function_entry )
105+
105106 return function_registry
106107
107108if __name__ == "__main__" :
0 commit comments