-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlit.py
More file actions
86 lines (77 loc) · 2.75 KB
/
lit.py
File metadata and controls
86 lines (77 loc) · 2.75 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
import datetime
import json
import os.path
import sys
import time
import executor
from lexer import *
from builder import *
from executor import *
from operators import *
operation = ""
arg = []
args = sys.argv
for b in range(1, args.__len__()):
i = args[b]
match i:
case "-b":
operation = "build"
case "-r":
operation = "run"
case "-c":
operation = "combine"
case "-d":
operation = "debug"
case "-l":
operation = "link"
case _: arg.append(i)
if operation != "build" and operation != "run" and operation != "combine" and operation != "debug" and operation != "link":
print("\x1b[1;38;5;196mError Occured:\x1b[0m\x1b[1m Unknown operation\x1b[0m")
quit(-1)
for i in arg:
if not os.path.isfile(i):
print(args)
print("\x1b[1;38;5;196mError Occured:\x1b[0m\x1b[1m Invalid arguments\x1b[0m")
quit(-1)
match operation:
case "run":
execute(open(arg[0]).read(), "app")
case "debug":
execute(simple_build(lex2(lex1(prelex(open(arg[0]).read())))), "app")
case "build":
for i in arg:
before = datetime.datetime.now()
filename = f"{i.replace(os.path.splitext(i)[1], "")}.json"
try:
open(filename, "x").close()
except:
pass
open(filename, "w").write(simple_build(lex2(lex1(prelex(open(i).read())))))
got = datetime.datetime.now() - before
print(f"\x1b[1;38;5;148mBUILT SUCCESSFULLY IN {got.microseconds}ms\x1b[0m")
case "combine":
for i in arg:
filename = f"{i.replace(os.path.splitext(i)[1], "")}.json"
try:
open(filename, "x").close()
except:
pass
built = simple_build(lex2(lex1(prelex(open(i).read()))))
open(filename, "w").write(built)
execute(built, "app")
case "link":
try:
root = json.loads(open(arg[0]).read())
for b in range(1, arg.__len__()):
i = arg[b]
sector_name = i.replace(os.path.splitext(i)[1], "")
sector = dict(json.loads(open(i).read()))
root[sector_name] = sector["app"]
open(arg[0], "w").write(json.dumps(root))
for b in range(1, arg.__len__()):
os.remove(arg[b])
print(f"\x1b[1;38;5;148mLINKED SUCCESSFULLY\x1b[0m")
except:
print(args)
print("\x1b[1;38;5;196mError Occured:\x1b[0m\x1b[1m Invalid arguments\x1b[0m")
quit(-1)