Skip to content
Snippets Groups Projects
Commit eb2a0a40 authored by George Marchment's avatar George Marchment
Browse files

Added sort length of parameters before replacing

parent 14e6ee30
No related branches found
No related tags found
No related merge requests found
Pipeline #14484 failed with stage
in 2 minutes and 23 seconds
......@@ -76,7 +76,16 @@ class Call(Executor):
tag_to_add = "//AREA TO ADD PARAMS"
code = f"{tag_to_add}\n{code}"
index = 1
#We do this so that the longest parameters are rewritten first in the code -> to avoid problems
parameters_2_length = {}
for param in self.parameters:
#TODO -> make sure of you change the parameters of the get_code -> you do the same below
temp_code = param.get_code(get_OG=True)
parameters_2_length[param] = len(temp_code)
sorted_parameters_2_length = {k: v for k, v in sorted(parameters_2_length.items(), key=lambda item: item[1], reverse=True)}
for param in sorted_parameters_2_length:
param_new_name = f"{self.get_first_element_called().get_alias_and_id()}_param_{index}"
#Case the param is a call
......@@ -84,6 +93,7 @@ class Call(Executor):
#If it's not a function -> then we rewrite it
if(param.get_first_element_called().get_type()!="Function"):
temp = code
#TODO -> make sure of you change the parameters of the get_code -> you do the same above
code = replace_group1(code, fr"[^\w]({re.escape(param.get_code(get_OG=True))})", param_new_name)
if(temp==code):
raise Exception("This souldn't happen")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment