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

Taken into account cases where map is written in parentheses

parent 3dd4c955
No related branches found
No related tags found
No related merge requests found
Pipeline #14495 failed with stage
in 2 minutes
...@@ -21,8 +21,8 @@ class Code: ...@@ -21,8 +21,8 @@ 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)
self.code_wo_comments = self.remove_things_inside_map(self.code_wo_comments ) self.code_wo_comments = self.remove_things_inside_map(self.code_wo_comments )
self.code_wo_comments = self.rewrite_ternary_operation_to_normal_condition(self.code_wo_comments)
self.code_wo_comments = self.rewrite_jump_dot(self.code_wo_comments) self.code_wo_comments = self.rewrite_jump_dot(self.code_wo_comments)
...@@ -130,24 +130,28 @@ class Code: ...@@ -130,24 +130,28 @@ class Code:
while(searching): while(searching):
searching = False searching = False
#TODO -> do the same with flatMap -> 668 #TODO -> do the same with flatMap -> 668
patterns = [r"\.\s*map\s*{", r"\.\s*flatMap\s*{"]
for word in ["map", "flatMap"]: for word in ["map", "flatMap"]:
pattern = r"\.\s*"+word+r"\s*{" for end_char in ['{', '\(']:
for match in re.finditer(pattern, code): pattern = fr"\.\s*"+word+r"\s*"+end_char
start_map, end = match.span(0) for match in re.finditer(pattern, code):
end_map = extract_curly(code, end) start_map, end = match.span(0)
if(end_char=="{"):
old = code[end:end_map-1] end_map = extract_curly(code, end)
new = f"¤{id(self)}_{index}¤" old = code[end:end_map-1]
self.add_map_element(old, new) else:
old = get_code_until_parenthese_count(code[end:], -1)
old_code = code[start_map:end_map] end_map = end+len(old)
new_code = f".{word}_modified {{ {new} }}" old = old.strip()[:-1]
code = code.replace(old_code, new_code) new = f"¤{id(self)}_{index}¤"
self.add_map_element(old, new)
searching = True
index+=1 old_code = code[start_map:end_map]
break new_code = f".{word}_modified {{ {new} }}"
code = code.replace(old_code, new_code)
searching = True
index+=1
break
return code return code
......
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