-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathliblintel.py
112 lines (89 loc) · 3.34 KB
/
liblintel.py
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
#!/usr/bin/env python3
# liblintel.py - The Lintel Library.
# (c) 2025 DWNfonts.
def _locateMagicList(char):
__MAGIC_LIST = [ # everytime I name the list/dict as magic
"〾", # IDCs followed by 1 char/IDS
"⿰⿱⿴⿵⿶⿷⿸⿹⿺⿻", # IDCs followed by 2 chars/IDSs
"⿲⿳", # IDCs followed by 3 chars/IDSs
]
for i in range(len(__MAGIC_LIST)):
if char in __MAGIC_LIST[i]:
return i + 1
return 0
class Lintel:
def __init__(
self, idc: None | str, chars: tuple, notProcessed=""
) -> None: # force-creating, danger as fuck
self.idc = idc
self.chars = chars
self.notProcessed = notProcessed
def __repr__(self) -> str:
if isinstance(self.idc, str):
return (
f"Lintel<{ self.idc + "".join([str(x) for x in self.chars]) }+{ self.notProcessed }>"
if self.notProcessed != ""
else f"Lintel<{ self.idc + ''.join([str(x) for x in self.chars]) }>"
)
else:
return (
f"Lintel<{ ''.join([str(x) for x in self.chars]) }+{ self.notProcessed }>"
if self.notProcessed != ""
else f"Lintel<{ ''.join([str(x) for x in self.chars]) }>"
)
def __str__(self) -> str:
if isinstance(self.idc, str):
return self.idc + "".join([str(x) for x in self.chars]) + self.notProcessed
else:
return "".join([str(x) for x in self.chars]) + self.notProcessed
class LintelWithSource:
def __init__(self, ids: Lintel | str, source: list) -> None:
self.ids = ids
self.source = source
def __repr__(self) -> str:
return f"LWS^{self.ids}$({"".join(self.source)})"
def importIDS(ids) -> Lintel | str:
if len(ids) == 0:
return ""
firstChar = ids[0]
loop = _locateMagicList(firstChar)
match loop:
case 0:
return firstChar
case _:
idc = firstChar
remainCharList = []
remainChars = ids[1:]
for _ in range(loop):
lintel = importIDS(remainChars)
if isinstance(lintel, Lintel):
noNotProcessed = Lintel(lintel.idc, lintel.chars)
remainCharList.append(noNotProcessed)
remainChars = (
lintel.notProcessed
if isinstance(remainCharList[-1], Lintel)
else remainChars[1:]
)
else:
if lintel != "":
remainCharList.append(lintel)
remainChars = remainChars[1:]
chars = tuple(remainCharList)
return Lintel(idc, chars, notProcessed=remainChars)
def importIDSWithSource(idswsrc):
import re
MAGIC_RE = "^\\^[^ ]*\\$([^ ]*)"
if not re.match(MAGIC_RE, idswsrc):
raise Exception("Invalid IDS")
else:
idc, source = idswsrc.split("$")
idc, source = idc[1:], source[1:-1]
return LintelWithSource(importIDS(idc), source)
def _test():
def _debug(text, lf=False):
import sys
end = "" if lf else "\n"
print(text, file=sys.stderr, end=end)
lws = importIDSWithSource("^⿰衤⿱𥫗灭$(GT)")
print([lws])
# if __name__ == "__main__": _test()