-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibparser.py
More file actions
94 lines (85 loc) · 3.59 KB
/
libparser.py
File metadata and controls
94 lines (85 loc) · 3.59 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
#libparser.py
def funcparser(f):
pass
class mcfParser:
def __init__(self):
self.replacedict={";":"\n"}
self.keywords=list(self.replacedict.keys())+[]
self.stringPool = []
self.docPool = []
self.jsonPool = []#unimplemented
def putCode(self,code,linear=False):
if linear:
self.code = self.code + "\n" + code
else:
self.code = code
def _handle_Replace(self,keyword,keyindex,char=None):
if not char:
char=self.replacedict[keyword]
self.code = char.join(self.code.split(keyword))
def _pre_process(self):
code = self.code.split("\n")[1:]
for lineIndex in range(len(code)):
in_string=False
in_brace=0
charIndex=0
string_headIndex=None
brace_headIndex=None
while 1:
if charIndex >= len(code[lineIndex]):
break
if not in_brace:
if not in_string:
if code[lineIndex][charIndex] == '"':
in_string = True
string_headIndex = charIndex
elif code[lineIndex][charIndex] == "#":
#print("@#")
offset = str(hex(len(self.docPool)))[::-1]
self.docPool.append(code[lineIndex][charIndex+1:])
code[lineIndex]=code[lineIndex][:charIndex]+"#d"+offset+"#"
break
elif code[lineIndex][charIndex:charIndex+2] == "//":
#print("@//")
code[lineIndex]=code[lineIndex][:charIndex]
break
elif code[lineIndex][charIndex] == '"':
in_string = False
offset = str(hex(len(self.stringPool)))[::-1]
self.stringPool.append(code[lineIndex][string_headIndex+1:charIndex])
code[lineIndex]=code[lineIndex][:string_headIndex]+"#s"+offset+"#"+code[lineIndex][charIndex+1:]
print(code)
charIndex = string_headIndex+2+len(offset)
if code[lineIndex][charIndex] == "{" and not in_string:
if not in_brace:
brace_headIndex=charIndex
#print("@{")
in_brace += 1
elif code[lineIndex][charIndex] == "}":
in_brace -= 1
if not in_brace:
offset = str(hex(len(self.jsonPool)))[::-1]
self.jsonPool.append(code[lineIndex][brace_headIndex+1:charIndex])
code[lineIndex]=code[lineIndex][:brace_headIndex]+"#j"+offset+"#"+code[lineIndex][charIndex+1:]
print(code)
charIndex = brace_headIndex+2+len(offset)
charIndex += 1
self.code = "\n".join(code)
def _handle_simplereplace(self):
for keyword in self.keywords:
if keyword in self.code:
keyindex = self.code.index(keyword)
self._handle_Replace(keyword,keyindex)
def handle(self):
self._pre_process()
self._handle_simplereplace()
"""parser=mcfParser()
parser.code=""
while 1:
u=input(":")
if u == ".":
break
parser.putCode(u,linear=True)
parser.handle()
for offset in parser.__dict__:
print(offset+":"+str(parser.__dict__[offset]))"""