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

Update smalll bug + removing ternary operator from code

parent 418fb2a7
No related branches found
No related tags found
No related merge requests found
Pipeline #14427 failed with stage
in 2 minutes and 30 seconds
...@@ -21,6 +21,7 @@ class Code: ...@@ -21,6 +21,7 @@ class Code:
self.code_wo_comments = re.sub(constant.BACKSLAPSH_JUMP, ' ', self.code_wo_comments) self.code_wo_comments = re.sub(constant.BACKSLAPSH_JUMP, ' ', self.code_wo_comments)
self.code_wo_comments = self.code_wo_comments.replace("||", "$OR$") self.code_wo_comments = self.code_wo_comments.replace("||", "$OR$")
self.code_wo_comments = self.turn_single_condition_into_multiline(self.code_wo_comments) self.code_wo_comments = self.turn_single_condition_into_multiline(self.code_wo_comments)
self.code_wo_comments = self.rewrite_ternary_operation_to_normal_condition(self.code_wo_comments)
def check_its_nextflow(self): def check_its_nextflow(self):
...@@ -40,6 +41,25 @@ class Code: ...@@ -40,6 +41,25 @@ class Code:
old, new = r old, new = r
code = code.replace(old, new) code = code.replace(old, new)
return code return code
#This methods rewrite ternary operation into "normal" conditions
#variable = (condition) ? Expression2 : Expression3;
def rewrite_ternary_operation_to_normal_condition(self, code):
pattern = r"(\w+) *\= *([^?\n]+) *\? *([^:\n]+) *\: *([^\n]+)\n"
to_replace = []
for match in re.finditer(pattern, code):
variable = match.group(1)
condition = match.group(2).strip()
exp1, exp2 = match.group(3).strip(), match.group(4).strip()
old = match.group(0)
new = f"if ({condition}) {{\n{variable} = {exp1}\n}}\n\n"
new += f"if (!({condition})) {{\n{variable} = {exp2}\n}}\n\n"
#else {{\n{variable} = {exp2}\n}}\n"
to_replace.append((old, new))
for r in to_replace:
old, new = r
code = code.replace(old, new)
return code
def get_line(self, bit_of_code): def get_line(self, bit_of_code):
code = remove_comments(self.code) code = remove_comments(self.code)
......
...@@ -16,6 +16,9 @@ class Function(Nextflow_Building_Blocks): ...@@ -16,6 +16,9 @@ class Function(Nextflow_Building_Blocks):
def get_alias(self): def get_alias(self):
return self.alias return self.alias
def get_alias_and_id(self):
return f"{self.alias}_GG_{id(self)}"
def get_type(self): def get_type(self):
return "Function" return "Function"
......
...@@ -100,7 +100,6 @@ class Subworkflow(Main): ...@@ -100,7 +100,6 @@ class Subworkflow(Main):
def simplify_code(self): def simplify_code(self):
code = super().simplify_code() code = super().simplify_code()
for o in self.emit: for o in self.emit:
print(o.get_code(get_OG = True), o.simplify_code(), o.OG_code)
code = code.replace(o.get_code(get_OG = True), o.simplify_code(), 1) code = code.replace(o.get_code(get_OG = True), o.simplify_code(), 1)
return code return code
......
...@@ -749,7 +749,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -749,7 +749,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#Get the clusters and the code #Get the clusters and the code
relevant_processes = self.check_relevant_processes_in_workflow(relevant_processes) relevant_processes = self.check_relevant_processes_in_workflow(relevant_processes)
print(relevant_processes)
self.generate_user_view(relevant_processes = relevant_processes, processes_2_remove = []) self.generate_user_view(relevant_processes = relevant_processes, processes_2_remove = [])
clusters = self.graph.get_clusters_from_user_view() clusters = self.graph.get_clusters_from_user_view()
broken_subworkflows = get_workflows_broken(get_subworkflow_2_executors(), get_clusters_with_calls(clusters)) broken_subworkflows = get_workflows_broken(get_subworkflow_2_executors(), get_clusters_with_calls(clusters))
...@@ -767,7 +766,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -767,7 +766,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
broken_subworkflows = get_workflows_broken(get_subworkflow_2_executors(), get_clusters_with_calls(clusters)) broken_subworkflows = get_workflows_broken(get_subworkflow_2_executors(), get_clusters_with_calls(clusters))
#print(code)
...@@ -967,8 +966,16 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -967,8 +966,16 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#Replace names inside subworkflow #Replace names inside subworkflow
subworkflow_code = f"workflow {name} {{\n{take}\nmain:\n{body}\n{emit}\n}}" subworkflow_code = f"workflow {name} {{\n{take}\nmain:\n{body}\n{emit}\n}}"
for i in range(len(new_param_names)): for i in range(len(new_param_names)):
pattern = fr"[\=\,\(] *({re.escape(takes_param[i].get_code())})[\s\,\)\.]" if(takes_param[i].get_code() != new_param_names[i]):
subworkflow_code = replace_group1(subworkflow_code, pattern, new_param_names[i]) #pattern = fr"[\=\,\(] *({re.escape(takes_param[i].get_code())})[\s\,\)\.]"
pattern = fr"({re.escape(takes_param[i].get_code())})[\s\,\)\.]"
temp = subworkflow_code
subworkflow_code = replace_group1(subworkflow_code, pattern, new_param_names[i])
if(temp==subworkflow_code):
print(takes_param[i].get_code(), new_param_names[i])
print(pattern)
print(f'"{subworkflow_code}"')
raise Exception("Something went wrong -> cause the paramter wasn't updated")
#subworkflow_code = subworkflow_code.replace(takes_param[i].get_code(), new_param_names[i]) #subworkflow_code = subworkflow_code.replace(takes_param[i].get_code(), new_param_names[i])
#TODO -> added verification of conditions #TODO -> added verification of conditions
......
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