-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_map.py
More file actions
107 lines (90 loc) · 2.98 KB
/
make_map.py
File metadata and controls
107 lines (90 loc) · 2.98 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
import pickle
def input_seq (instruction, matches):
print(matches)
print(instruction)
if len(matches) == 0:
print('\n')
addition = input(" > ")
print('\n')
return addition
def build_map_section (comments, m):
for line in comments['section']:
if line.lstrip().startswith(b'/*'):
pass
elif line.lstrip().startswith(b'*/'):
pass
else:
try:
instruction = list(filter(lambda a: a != b'', line.lstrip().split(b' ')))[2:]
except:
instruction = False
if instruction:
print(instruction)
if instruction[0] not in m:
m[instruction[0]] = []
matches = m[instruction[0]]
print(matches)
addition = input_seq(instruction, matches)
if addition:
m[instructions[0]].append(addition)
return m
def build_map (sections, m):
print(m)
try:
for section in sections:
if section['type']:
comments = section
# out = build_map_section(section, out)
for line in comments['section']:
if line.lstrip().startswith(b'/*'):
pass
elif line.lstrip().startswith(b'*/'):
pass
else:
try:
instruction = list(filter(lambda a: a != b'', line.lstrip().split(b' ')))[2:]
except IndexError:
instruction = False
if instruction:
if instruction[0] not in m:
m[instruction[0]] = []
matches = m[instruction[0]]
addition = input_seq(instruction, matches)
if addition:
m[instruction[0]].append(addition)
except KeyboardInterrupt:
pass
return m
def preprocess_file(f):
sections = []
comment_switch = False
section = []
for line in f:
stripped = line.lstrip()
if stripped.startswith(b'/*'):
sections.append({'type' : comment_switch, 'section': section})
section = []
section.append(line)
comment_switch = True
elif stripped.startswith(b'*/'):
section.append(line)
sections.append({'type' : comment_switch, 'section': section})
section = []
comment_switch = False
else:
section.append(line)
return sections
if __name__ == "__main__":
try:
g = open('test.map', 'rb')
m = pickle.load(g)
except:
m = {}
print("{")
for k in m:
try:
print(" ",k, " : (lambda i: ", m[k][0], ")" )
except:
print(m[k])
print("error?")
print("}")