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