-
Notifications
You must be signed in to change notification settings - Fork 12
/
helpers.py
35 lines (32 loc) · 1.01 KB
/
helpers.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
COLOR_HEADER = '\033[95m'
COLOR_BLUE = '\033[94m'
COLOR_OKGREEN = '\033[92m'
COLOR_WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
COLOR_BOLD = '\033[1m'
COLOR_UNDERLINE = '\033[4m'
COLOR_GREEN = '\033[32m'
COLOR_GRAY = '\033[38;5;8m'
def opcode(exp):
if type(exp) != list:
return None
else:
return str(exp[0] if len(exp)>0 else None)
def format_exp(exp):
if type(exp) == str:
return f'"{exp}"'
if type(exp) == int:
if exp > 10**6 and exp % 10**6 != 0:
return hex(exp)
else:
return str(exp)
elif type(exp) != list:
return str(exp)
else:
if len(exp) == 0:
return COLOR_GRAY + '[]'+ENDC
if type(opcode(exp)) == list:
return COLOR_GRAY + '[' + ENDC + f'{COLOR_GRAY},{ENDC}'.join([format_exp(e) for e in exp]) + COLOR_GRAY+']'+ENDC
else:
return COLOR_GRAY + '[' + ENDC + f'{COLOR_GRAY},{ENDC}'.join([opcode(exp)] + [format_exp(e) for e in exp[1:]]) + COLOR_GRAY+']'+ENDC