-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
37 lines (28 loc) · 985 Bytes
/
utils.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
from re import S
import typer
def print_break_line():
typer.echo("==========================================\n")
def line_to_str(line: list[str]) -> str:
if line[-1] == ':':
return "".join(line)
total = " "
# line_len = len(line) - 1
for i, item in enumerate(line):
if i != 0 and item != ',':
total += " "
total += item
return total
def program_to_string(prog: list[list[str]]) -> str:
return "\n".join(map(line_to_str, prog))
def save_program(file_path: str, program: str, optimized: bool = False):
# make folder with same name as file with dot replaced with "_"
file_path = file_path.split('.')
if not optimized:
file_path[len(file_path)-1] = '.s'
else:
file_path[len(file_path)-1] = '_optimized.s'
file_path = ''.join(file_path)
# put both unoptimized and optimized file into that foldee
file = open(file_path, "w")
file.write(program)
file.close()