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

update the extraction of conditions

parent 5e182635
No related branches found
No related tags found
No related merge requests found
Pipeline #14463 failed with stage
in 2 minutes and 14 seconds
...@@ -990,6 +990,7 @@ def extract_conditions(code, only_get_inside = True): ...@@ -990,6 +990,7 @@ def extract_conditions(code, only_get_inside = True):
return conditions_dico return conditions_dico
#Just because there is an 'if' doesn't necessarily mean there is an if bloc #Just because there is an 'if' doesn't necessarily mean there is an if bloc
found_if_bloc = False found_if_bloc = False
searching_for_else = False
conditions = [] conditions = []
if(code[start:start+2]=="if" and [quote_single, quote_double, triple_single, triple_double]==[False, False, False, False]): 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): ...@@ -1005,31 +1006,35 @@ def extract_conditions(code, only_get_inside = True):
else: else:
conditions_dico[f"{condition}$$__$${index_condition}"] = (start, end) conditions_dico[f"{condition}$$__$${index_condition}"] = (start, end)
index_condition+=1 index_condition+=1
searching_for_else = True
#conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) #conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside)
break break
searching_for_else = True
while(searching_for_else): while(searching_for_else):
searching_for_else = False searching_for_else = False
#Try to find an else corresponding #Try to find an else corresponding
if(found_if_bloc and code[end:].strip()[:4]=="else"): if(found_if_bloc and code[end:].strip()[:4]=="else"):
found_else_if = False found_else_if = False
#CASE of "else if" #CASE of "else if"
for match in re.finditer(r"else *if *\((.+)\)\s*\{", code[end:]): rest_of_code = code[end:]
found_else_if = True for match in re.finditer(r"\s*else *if *\((.+)\)\s*\{", rest_of_code):
searching_for_else = True
condition = match.group(1)
conditions.append(condition)
start_else, end_else = match.span(0) start_else, end_else = match.span(0)
start_else+=end if(start_else==0):
end_else = extract_curly(code, end_else+end) found_else_if = True
start_inside, end_inside = match.span(0)[1]+end, end_else-1 searching_for_else = True
if(only_get_inside): condition = match.group(1)
conditions_dico[f"{condition}$$__$${index_condition}"] = (start_inside, end_inside) printed_condition = ' && '.join(["!({})".format(v) for v in conditions])
else: printed_condition += " && "+condition
conditions_dico[f"{condition}$$__$${index_condition}"] = (start_else, end_else) conditions.append(condition)
index_condition+=1 start_else+=end
#conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) end_else = extract_curly(code, end_else+end)
break 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" #CASE of "else"
if(not found_else_if): if(not found_else_if):
for match in re.finditer(r"else\s*{", code[end:]): for match in re.finditer(r"else\s*{", code[end:]):
......
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