diff --git a/src/outils.py b/src/outils.py index 3f9662c38ac6a26755719622a3a724d5428b8a22..9491059ecbe8e5966fdf5b3353d18fdab81431f8 100644 --- a/src/outils.py +++ b/src/outils.py @@ -990,6 +990,7 @@ def extract_conditions(code, only_get_inside = True): return conditions_dico #Just because there is an 'if' doesn't necessarily mean there is an if bloc found_if_bloc = False + searching_for_else = False conditions = [] if(code[start:start+2]=="if" and [quote_single, quote_double, triple_single, triple_double]==[False, False, False, False]): @@ -1005,31 +1006,35 @@ def extract_conditions(code, only_get_inside = True): else: conditions_dico[f"{condition}$$__$${index_condition}"] = (start, end) index_condition+=1 + searching_for_else = True #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) break - searching_for_else = True while(searching_for_else): searching_for_else = False #Try to find an else corresponding if(found_if_bloc and code[end:].strip()[:4]=="else"): found_else_if = False #CASE of "else if" - for match in re.finditer(r"else *if *\((.+)\)\s*\{", code[end:]): - found_else_if = True - searching_for_else = True - condition = match.group(1) - conditions.append(condition) + rest_of_code = code[end:] + for match in re.finditer(r"\s*else *if *\((.+)\)\s*\{", rest_of_code): start_else, end_else = match.span(0) - start_else+=end - end_else = extract_curly(code, end_else+end) - start_inside, end_inside = match.span(0)[1]+end, end_else-1 - if(only_get_inside): - conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) - else: - conditions_dico[f"{condition}$$__$${index_condition}"] = (start_else, end_else) - index_condition+=1 - #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) - break + if(start_else==0): + found_else_if = True + searching_for_else = True + condition = match.group(1) + printed_condition = ' && '.join(["!({})".format(v) for v in conditions]) + printed_condition += " && "+condition + conditions.append(condition) + start_else+=end + end_else = extract_curly(code, end_else+end) + start_inside, end_inside = match.span(0)[1]+end, end_else-1 + if(only_get_inside): + conditions_dico[f"{printed_condition}$$__$${index_condition}"] = (start_inside, end_inside) + else: + conditions_dico[f"{printed_condition}$$__$${index_condition}"] = (start_else, end_else) + index_condition+=1 + #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) + break #CASE of "else" if(not found_else_if): for match in re.finditer(r"else\s*{", code[end:]):