-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParsedObjects.py
More file actions
115 lines (100 loc) · 3.67 KB
/
Copy pathParsedObjects.py
File metadata and controls
115 lines (100 loc) · 3.67 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# coding=utf-8
__author__ = 'PaulieC'
# imports
from CodeReplacementTracker.ParserDataStructure import ParserDataStructure
class Window(ParserDataStructure):
def __init__(self):
super().__init__()
def set_line_dec(self, num: int) -> bool:
try:
self.line_declared = num
return True
except Exception:
return False
def set_line_ret(self, num: int) -> bool:
try:
self.line_returned = num
return True
except Exception:
return False
def add_gosub(self, line: int, val: str) -> bool:
try:
to_split = val
new_line = [-1]
while new_line:
new_line = to_split.split(" ", 1)
if new_line[0].lower() == "gosub":
temp = new_line[1].split(" ", 1)
self.gosub_lines.append([line, temp[0]])
to_split = new_line[1]
return True
except Exception:
return False
class Subroutine(ParserDataStructure):
def __init__(self):
super().__init__()
self.subroutine_list = []
def set_line_ret(self, num: int) -> bool:
try:
self.line_end = num
if self.subroutine_list:
self.subroutine_list[len(self.subroutine_list) - 1].set_line_ret(num - 1)
return True
except Exception:
return False
def add_gosub(self, line: int, val: str) -> bool:
try:
to_split = val
new_line = [-1]
while new_line:
new_line = to_split.split(" ", 1)
if new_line[0].lower() == "gosub":
temp = new_line[1].split(" ", 1)
if self.subroutine_list:
self.subroutine_list[len(self.subroutine_list) - 1].add_gosub(line, val)
else:
self.gosub_lines.append([line, temp[0]])
to_split = new_line[1]
return True
except Exception:
return False
def add_goto(self, line: int, val: str) -> bool:
try:
to_split = val
new_line = [-1]
while new_line:
new_line = to_split.split(" ", 1)
if new_line[0].lower() == "goto":
temp = new_line[1].split(" ", 1)
if self.subroutine_list:
self.subroutine_list[len(self.subroutine_list) - 1].add_goto(line, val)
else:
self.goto_lines.append([line, temp[0]])
to_split = new_line[1]
return True
except Exception:
return False
def add_exit(self, line: int, val: str) -> bool:
try:
to_split = val
new_line = [-1]
while new_line:
new_line = to_split.split(" ", 1)
if new_line[0].lower() == "exitto":
temp = new_line[1].split(" ", 1)
if self.subroutine_list:
self.subroutine_list[len(self.subroutine_list) - 1].add_exit(line, val)
else:
self.goto_lines.append([line, temp[0]])
to_split = new_line[1]
return True
except Exception:
return False
def add_subroutine(self, line: int, val: str) -> bool:
subroutine = Subroutine()
subroutine.set_name(val)
subroutine.set_line_dec(line)
if self.subroutine_list:
self.subroutine_list[len(self.subroutine_list) - 1].set_line_ret(line - 1)
self.subroutine_list.append(subroutine)
return True