From 6f43247fd9899454c633d5903f8e6cb1bd61b25f Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Thu, 13 Mar 2025 14:30:31 +0100 Subject: [PATCH] Updated the extraction of the executor from the middle -> it wasn't working correctly --- src/operation.py | 6 ++- src/outils.py | 119 ++++++++++++++++++++++++----------------------- src/workflow.py | 11 ++++- 3 files changed, 75 insertions(+), 61 deletions(-) diff --git a/src/operation.py b/src/operation.py index afba839..5f81ec7 100644 --- a/src/operation.py +++ b/src/operation.py @@ -726,7 +726,11 @@ class Operation(Executor): start+=1 searching=True call_code = get_end_call(text, start, end) - call = Call(code =call_code, origin =self, OG_code=self.dico_OG_call_2_new_call[call_code]) + try: + OG_code=self.dico_OG_call_2_new_call[call_code] + call = Call(code =call_code, origin =self, OG_code=OG_code) + except: + call = Call(code =call_code, origin =self) call.initialise() self.calls[str(call)] = call break diff --git a/src/outils.py b/src/outils.py index 44c5980..a60cf22 100644 --- a/src/outils.py +++ b/src/outils.py @@ -205,45 +205,7 @@ def extract_executor_from_middle(code, start, end): save_start, save_end = start, end find_start, find_end = False, False - #Basically the logic here is that at the start of operation curly or parenthese count can be positive but never negative (see example below) - curly_count, parenthese_count = 0, 0 - quote_single, quote_double = False, False - - - while(not find_start): - if(start<0): - raise Exception(f"Couldn't find the start of the executor : {code[save_start:save_end]}") - - if(code[end]=="{" and not quote_single and not quote_double): - curly_count+=1 - if(code[end]=="}" and not quote_single and not quote_double): - curly_count-=1 - if(code[end]=="(" and not quote_single and not quote_double): - parenthese_count+=1 - if(code[end]==")" and not quote_single and not quote_double): - parenthese_count-=1 - if(code[end]=="'" and not quote_single and not quote_double): - if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_single=True - elif(code[end]=="'" and quote_single and not quote_double): - if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_single=False - if(code[end]=='"' and not quote_single and not quote_double): - if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_double=True - elif(code[end]=='"' and not quote_single and quote_double): - if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_double=False - - next_character, _ = get_next_element_caracter(code, start) - character_before, _ = get_before_element_caracter(code, start) - - - if(code[start]=='\n' and (re.fullmatch("\w", next_character) or next_character in ['(']) and character_before not in ['(', '[', ',', '.', '|'] and curly_count>=0 and parenthese_count>=0 and not quote_single and not quote_single): - #if(code[start]=='\n' and character_before not in ['(', '[', ',', '.', '|'] and curly_count>=0 and parenthese_count>=0 and not quote_single and not quote_single): - find_start = True - else: - start-=1 + #Basically the logic here is that at the end of operation curly or parenthese count can be negative but never positive @@ -261,8 +223,8 @@ def extract_executor_from_middle(code, start, end): #} #.set { trim_reads } - curly_count, parenthese_count = 0, 0 - quote_single, quote_double = False, False + curly_count_right, parenthese_count_right = 0, 0 + quote_single_right, quote_double_right = False, False while(not find_end): @@ -270,26 +232,26 @@ def extract_executor_from_middle(code, start, end): raise Exception(f"Couldn't find the end of the executor : {code[start:save_end]}") - if(code[end]=="{" and not quote_single and not quote_double): - curly_count+=1 - if(code[end]=="}" and not quote_single and not quote_double): - curly_count-=1 - if(code[end]=="(" and not quote_single and not quote_double): - parenthese_count+=1 - if(code[end]==")" and not quote_single and not quote_double): - parenthese_count-=1 - if(code[end]=="'" and not quote_single and not quote_double): + if(code[end]=="{" and not quote_single_right and not quote_double_right): + curly_count_right+=1 + if(code[end]=="}" and not quote_single_right and not quote_double_right): + curly_count_right-=1 + if(code[end]=="(" and not quote_single_right and not quote_double_right): + parenthese_count_right+=1 + if(code[end]==")" and not quote_single_right and not quote_double_right): + parenthese_count_right-=1 + if(code[end]=="'" and not quote_single_right and not quote_double_right): if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_single=True - elif(code[end]=="'" and quote_single and not quote_double): + quote_single_right=True + elif(code[end]=="'" and quote_single_right and not quote_double_right): if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_single=False - if(code[end]=='"' and not quote_single and not quote_double): + quote_single_right=False + if(code[end]=='"' and not quote_single_right and not quote_double_right): if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_double=True - elif(code[end]=='"' and not quote_single and quote_double): + quote_double_right=True + elif(code[end]=='"' and not quote_single_right and quote_double_right): if(code[end-1]!="\\" or (code[end-1]=="\\" and code[end-2]=="\\")): - quote_double=False + quote_double_right=False @@ -306,11 +268,52 @@ def extract_executor_from_middle(code, start, end): #v1 #if(code[end]=='\n' and (re.fullmatch("\w", next_character) or next_character in ['}', '/', '|']) and curly_count<=0 and parenthese_count<=0 and not quote_single and not quote_single): #v2 - if(code[end]=='\n' and (re.fullmatch("\w", next_character) or next_character in ['}', '/', '|']) and character_before not in [','] and next_next_character not in ['.', '|'] and curly_count<=0 and parenthese_count<=0 and not quote_single and not quote_single): + if(code[end]=='\n' and (re.fullmatch("\w", next_character) or next_character in ['}', '/', '|']) and character_before not in [','] and next_next_character not in ['.', '|'] and curly_count_right<=0 and parenthese_count_right<=0 and not quote_single_right and not quote_single_right): find_end = True else: end+=1 + + #Basically the logic here is that at the start of operation curly or parenthese count can be positive but never negative (see example below) + curly_count_left, parenthese_count_left = 0, 0 + quote_single_left, quote_double_left = False, False + + + while(not find_start): + if(start<0): + raise Exception(f"Couldn't find the start of the executor : {code[save_start:save_end]}") + + if(code[start]=="{" and not quote_single_left and not quote_double_left): + curly_count_left+=1 + if(code[start]=="}" and not quote_single_left and not quote_double_left): + curly_count_left-=1 + if(code[start]=="(" and not quote_single_left and not quote_double_left): + parenthese_count_left+=1 + if(code[start]==")" and not quote_single_left and not quote_double_left): + parenthese_count_left-=1 + if(code[start]=="'" and not quote_single_left and not quote_double_left): + if(code[start-1]!="\\" or (code[start-1]=="\\" and code[start-2]=="\\")): + quote_single_left=True + elif(code[start]=="'" and quote_single_left and not quote_double_left): + if(code[start-1]!="\\" or (code[start-1]=="\\" and code[start-2]=="\\")): + quote_single_left=False + if(code[start]=='"' and not quote_single_left and not quote_double_left): + if(code[start-1]!="\\" or (code[start-1]=="\\" and code[start-2]=="\\")): + quote_double_left=True + elif(code[start]=='"' and not quote_single_left and quote_double_left): + if(code[start-1]!="\\" or (code[start-1]=="\\" and code[start-2]=="\\")): + quote_double_left=False + + next_character, _ = get_next_element_caracter(code, start) + character_before, _ = get_before_element_caracter(code, start) + + + if(code[start]=='\n' and (re.fullmatch("\w", next_character) or next_character in ['(']) and character_before not in ['(', '[', ',', '.', '|'] and (curly_count_left+curly_count_right)==0 and (parenthese_count_left+parenthese_count_left)==0 and not quote_single_left and not quote_single_left): + #if(code[start]=='\n' and character_before not in ['(', '[', ',', '.', '|'] and curly_count>=0 and parenthese_count>=0 and not quote_single and not quote_single): + find_start = True + else: + start-=1 + return code[start:end].strip() diff --git a/src/workflow.py b/src/workflow.py index 4e677bb..69eb6c9 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -637,7 +637,13 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen for ele in things_added_in_cluster: if(ele.get_type() == "Operation"): for o in ele.get_origins(): - channels_2_sources[o] = replace_thing_by_call(o.get_source()) + if(o.get_type() in ["Channel", "Emitted"]): + channels_2_sources[o] = replace_thing_by_call(o.get_source()) + else: + if(o.get_first_element_called().get_type()=="Function"): + None + else: + raise Exception("This shouldn't happen") elif(ele.get_type() == "Call"): for param in ele.get_parameters(): if(param.get_type()=="Channel"): @@ -939,7 +945,8 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen origins = ele.get_origins() for o in origins: if(o.get_type()=="Call"): - calls_in_operations.append(o) + if(o.get_first_element_called().get_type()!="Function"): + calls_in_operations.append(o) values = [] for condition in ele.get_all_conditions(): -- GitLab