MCPcopy Create free account
hub / github.com/Persper/code-analytics / parse

Method parse

persper/analytics/patch_parser.py:40–90  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

38 self.deletions.append([self.del_start, self.cur - 1])
39
40 def parse(self, text):
41 self.clean()
42 for line in text.split('\n'):
43 line = line.strip()
44 if not self.in_chunk:
45 if line.startswith('@@'):
46 self.in_chunk = True
47 else:
48 continue
49
50 if line.startswith('@@'):
51 m = self.re_chunk_header.search(line)
52 self.cur = max(int(m.groups()[0]), 1)
53 elif line.startswith('-'):
54 # print("in minus")
55 if self.in_add:
56 self.finish_add()
57 self.start_del()
58 elif self.in_del:
59 pass
60 else:
61 self.start_del()
62 self.cur += 1 # always increment in minus
63 elif line.startswith('+'):
64 # print("in plus")
65 if self.in_add:
66 self.add_num_lines += 1
67 elif self.in_del:
68 self.finish_del()
69 self.start_add()
70 else:
71 self.start_add()
72 elif line.startswith('\\'):
73 # Ignore \No newline at the end of file
74 pass
75 else:
76 # print("in blank")
77 if self.in_add:
78 self.finish_add()
79 elif self.in_del:
80 self.finish_del()
81 else:
82 pass
83 self.cur += 1 # always increment in blank
84
85 if self.in_add:
86 self.finish_add()
87 elif self.in_del:
88 self.finish_del()
89
90 return self.additions, self.deletions

Callers 2

_parse_patchMethod · 0.45
transform_src_to_treeFunction · 0.45

Calls 5

cleanMethod · 0.95
finish_addMethod · 0.95
start_delMethod · 0.95
finish_delMethod · 0.95
start_addMethod · 0.95

Tested by

no test coverage detected