-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatementCollectorExtention.py
More file actions
28 lines (24 loc) · 941 Bytes
/
Copy pathStatementCollectorExtention.py
File metadata and controls
28 lines (24 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class StatementCollectorExtention:
def __init__(self, tokens):
self.tokens = tokens
def summarize_statements(self):
statements = []
pos = 0
while ";" in self.tokens[pos:] or "end" in self.tokens[pos:] or len(self.tokens) > pos:
index = pos
if ";" in self.tokens[pos:]:
index = self.tokens[pos:].index(";")
join = ' '.join(self.tokens[pos:pos + index])
if "while" in join:
join_split = join.split("do")
statements.append(join_split[0] + " do")
statements.append(join_split[1])
elif "end" in join:
join_split = join.split("end")
statements.append(join_split[0])
statements.append("end")
else:
statements.append(join)
pos = pos + index + 1
pos = pos
return statements