This repository has been archived by the owner on Nov 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
598 lines (534 loc) · 18.8 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
import time, os, sys, getpass, re, string
fp = input('FilePath: ')
if '.pys' in fp:#hmmmm
try:
f = open(f'{fp}')
except:
raise Exception("No Such File Exists!")
else:
raise Exception("The file isn't a '.pys' file!")
content = f.read()
colist = content.split("\n")
def check():
df = re.findall("(?<=[AZaz])?(?!\d*=)[0-9.+-]+", lines)
df = str(df)
def wait_until(somepredicate, timeout, period=0.25, *args, **kwargs):
mustend = time.time() + timeout
while time.time() < mustend:
if somepredicate(*args, **kwargs): return True
time.sleep(period)
return False
#all errors
class InvalidVariableError(Exception):
pass
class InvalidSyntaxError(Exception):
pass
class InvalidIndentationError(Exception):
pass
class InvalidModuleError(Exception):
pass
class InvalidStringIntError(Exception):
pass
class TemplateError(Exception):
pass
allvars = {}
line = 0
read_line=0
PASS = False
getChar1 = "none"
getChar2 = "none"
getChar3 = "none"
var1 = "Undefined variable"
input1 = "Undefined input"
input2 = "Undefined input"
input3 = "Undefined input"
functions = ["os.userinfo(","time.strftime(","window.alert(","console.print(","alert(","console.input(","window.prompt(","prompt("]
def timeTIME():
if time_module == 1:
wrd = "time.time("
res = lines.partition(wrd)[2]
res = res.replace(");","")
print(res)
if type(res) == str:
if res == " " or res == "":
time.time()#this won't do anything of course, unless you print it ;)
else:
raise InvalidStringIntError("'time.time' must be empty!")
else:
raise InvalidStringIntError("'time.time' must be empty!")
else:
raise InvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
def osSYSTEM():
if os_module == 1:
wrd = "os.system("
res = lines.partition(wrd)[2]
if res[-3] == "\"" and res[0] == "\'" or res[-3] == "'" and res[0] == "\"":
raise InvalidSyntaxError("The 'os.system' starting quotations and ending quotations are different!")
else:
if "\"" in res:
split_string = res.split("\");", -1)
elif "'" in res:
split_string = res.split("\');", -1)
else:
raise InvalidSyntaxError("The 'os.system' statement is missing quotations!")
res = res.replace("\"", "")
res = res.replace("'", "")
res = res.replace(");", "")
#print(res)
try:
os.system(str(res))
except:
raise InvalidModuleError(f"'{res}' command doesn't exist!")
else:
raise InvalidModuleError("The 'os' module isn't imported or it doesn't exist!")
def osUSERINFO():
if os_module == 1:
wrd = "os.userinfo("
global res
res = lines.partition(wrd)[2]
if " " in res:
raise InvalidSyntaxError("'os.userinfo' cannot include spaces!")
else:
if ");" in res:
res = res.replace(");","")
else:
raise InvalidSyntaxError("'os.userinfo' must have ');'!")
if res == "" or res == " ":
try:
print(os.environ["REPL_OWNER"])
except:
raise InvalidModuleError("This function does not exist on your device!")
else:
raise InvalidModuleError("'os.userinfo' must be empty!")
else:
raise InvalidModuleError("The 'os' module isn't imported or it doesn't exist!")
'''
Note that ascii characters are used like this in pyscript:
/1234 or /u1243
Of course, those are examples ;) Another thing I should mention is that not all characters have been made yet ;)
'''
def WINDOWalert():#add f'string
try:
if '");' in lines or "');" in lines or "`);" in lines:
wrd = "window.alert("
res = lines.partition(wrd)[2]
#print(res)
if res[-3] == "\"" and res[0] == "\'" or res[-3] == "\"" and res[0] == "`" or res[-3] == "'" and res[0] == "\"" or res[-3] == "'" and res[0] == "`" or res[-3] == "`" and res[0] == "\"" or res[-3] == "`" and res[0] == "'":
raise InvalidSyntaxError("The 'window.alert' starting quotations and ending quotations are different!")
else:
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
if "\"" in res:
split_string = res.split("\");", -1)
elif "'" in res:
split_string = res.split("\');", -1)
elif "`" in res:
split_string = res.split("`);", -1)
else:
raise InvalidSyntaxError("The 'window.alert' statement is missing quotations!")
res = split_string[0]
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
#colors: res = res.replace("{red}", red)
res = res.replace('"', "")
res = res.replace("'", "")
res = res.replace("`", "")
res = res.replace(");","")
if "{{" in res:
if "}}" in res:
start = "{{"
end = "}}"
check = res[res.find(start) + len(start):res.rfind(end)]
if check in allvars:
res = res.replace("{{", "")
res = res.replace("}}", "")
dffdfdfdf = allvars[check]
res = res.replace(check, str(dffdfdfdf))
else:
global PASS
PASS = False
if "time.time(" in check:
if check[-1] == "(":
print(time.time())
PASS = True
else:
raise InvalidSyntaxError("'time.time' must be empty!")
elif "time.strftime(" in check:
#print(timeSTRFTIME())
PASS = True
else:
#print(var)
#print(res)
raise InvalidVariableError(f"'{var}' variable does not exist!")
if PASS:
pass
else:
print(res, end="")
print()
else:
raise InvalidSyntaxError("The 'window.alert' statement must have a closing ');!")
except:
raise InvalidSyntaxError("The 'window.alert' statement must have a closing ');!")
def alert():
try:
if '");' in lines or "');" in lines or "`);" in lines:
wrd = "alert("
res = lines.partition(wrd)[2]
if res[-3] == "\"" and res[0] == "\'" or res[-3] == "\"" and res[0] == "`" or res[-3] == "'" and res[0] == "\"" or res[-3] == "'" and res[0] == "`" or res[-3] == "`" and res[0] == "\"" or res[-3] == "`" and res[0] == "'":
raise InvalidSyntaxError("The 'alert' starting quotations and ending quotations are different!")
else:
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
if "\"" in res:
split_string = res.split("\");", -1)
elif "'" in res:
split_string = res.split("\');", -1)
elif "`" in res:
split_string = res.split("`);", -1)
else:
raise InvalidSyntaxError("The 'alert' statement is missing quotations!")
res = split_string[0]
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
#colors: res = res.replace("{red}", red)
res = res.replace('"', "")
res = res.replace("'", "")
res = res.replace("`", "")
res = res.replace(");","")
if "{{" in res:
if "}}" in res:
start = "{{"
end = "}}"
check = res[res.find(start) + len(start):res.rfind(end)]
if check in allvars:
res = res.replace("{{", "")
res = res.replace("}}", "")
dffdfdfdf = allvars[check]
res = res.replace(check, str(dffdfdfdf))
else:
global PASS
PASS = False
if "time.time(" in check:
if check[-1] == "(":
print(time.time())
PASS = True
else:
raise InvalidSyntaxError("'time.time' must be empty!")
elif "time.strftime(" in check:
#print(timeSTRFTIME())
PASS = True
else:
raise InvalidVariableError(f"'{var}' variable does not exist!")
if PASS:
pass
else:
print(res, end="")
print()
else:
raise InvalidSyntaxError("The 'alert' statement must have a closing ');!")
except:
raise InvalidSyntaxError("The 'alert' statement must have a closing ');!")
def CONSOLEprint():
try:
if '");' in lines or "');" in lines or "`);" in lines:
wrd = "console.print("
res = lines.partition(wrd)[2]
if res[-3] == "\"" and res[0] == "\'" or res[-3] == "\"" and res[0] == "`" or res[-3] == "'" and res[0] == "\"" or res[-3] == "'" and res[0] == "`" or res[-3] == "`" and res[0] == "\"" or res[-3] == "`" and res[0] == "'":
raise InvalidSyntaxError("The 'console.print' starting quotations and ending quotations are different!")
else:
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
if "\"" in res:
split_string = res.split("\");", -1)
elif "'" in res:
split_string = res.split("\');", -1)
elif "`" in res:
split_string = res.split("`);", -1)
else:
raise InvalidSyntaxError("The 'console.print' statement is missing quotations!")
res = split_string[0]
res = res.replace("\");","")
res = res.replace('`);',"")
res = res.replace('\');',"")
res = res.replace("/n", "\n")
res = res.replace("/t", "\t")
#colors: res = res.replace("{red}", red)
res = res.replace('"', "")
res = res.replace("'", "")
res = res.replace("`", "")
res = res.replace(");","")
if "{{" in res:
if "}}" in res:
start = "{{"
end = "}}"
check = res[res.find(start) + len(start):res.rfind(end)]
if check in allvars:
res = res.replace("{{", "")
res = res.replace("}}", "")
dffdfdfdf = allvars[check]
res = res.replace(check, str(dffdfdfdf))
else:
global PASS
PASS = False
if "time.time(" in check:
if check[-1] == "(":
print(time.time())
PASS = True
else:
raise InvalidSyntaxError("'time.time' must be empty!")
elif "time.strftime(" in check:
#print(timeSTRFTIME())
PASS = True
else:
raise InvalidVariableError(f"'{var}' variable does not exist!")
if PASS:
pass
else:
print(res, end="")
print()
else:
raise InvalidSyntaxError("The 'console.print' statement must have a closing ');!")
except:
raise InvalidSyntaxError("The 'console.print' statement must have a closing ');!")
newvar = 0
time_module = 0
file = open(fp)
readline2 = 0
for lines in file.readlines():
#print(lines)
if "/#" in lines:
readline2=1
#print(wait_until("*/", 0))
wait_until("#/", 0)
if readline2 == 1:
readline2 = 0
continue
if "//" in lines:#maybe change to /#
readline2=1
line+=1
lines = lines.replace('\n','')
lines = lines.replace('\t','')
#print(lines)
if lines == '':
pass
elif lines in string.whitespace:
raise InvalidIndentationError("Your indentation does not fit the other statements!")
elif "/#" in lines:
wait_until("#/", 0)
readline2 = 1
elif "//" in lines:
pass
lines = lines.rstrip()
#print(lines[:2])
'''
elif " " in lines or "\t" in lines or " " in lines:
raise InvalidIndentationError(f"line {line}, the indentation does not fit the other statements!")
'''
'''
Note that `;`'s are strictly required in this language
'''
if lines[:2] == "//" or "//" in lines:
pass
read_line = 0
elif "import(\"time\");" in lines or "import('time');" in lines:#add semicolon error
time_module = 1
elif "import(\"os\");" in lines or "import('os');" in lines:
os_module = 1
elif "var " in lines:
wrd = "var "
newvar = lines.partition(wrd)[2]
split_string = newvar.split("\")", -1)
newvar.replace(")","")
newvar.replace('\"', '')
newvar = split_string[0]
#newvar = variable;
if newvar[-1] == ";":
if ";" in newvar[:-1]:
for i in newvar[:-1]:
if "'" == i or "\"" == i or "`" == i:
pass
else:
raise InvalidSyntaxError("You must only include one semi-colon!")
else:
newvarTEST = newvar[-1]
newvar = newvar.replace(";","")#make ; disappear into blank space
else:
raise InvalidSyntaxError("Variable statement is missing semi-colon!")
if " " in newvar:
if "=" in newvar:
idk = []
Continue = True
for i in newvar:
if Continue:
if i == "=":
idk.append(i)
Continue = False
else:
idk.append(i)
else:
if i == " ":
idk.append(i)
break
else:
break
idk = "".join(idk)
newvar = newvar.replace(idk, "")
if "'" in newvar or "\"" in newvar or "`" in newvar or "os.userinfo(" in newvar:
if newvar in functions:
if "console.print(" in newvar:
CONSOLEprint()
elif "window.alert(" in newvar:
WINDOWalert()
elif "alert(" in newvar:
alert()
elif "window.prompt(" in newvar:
e
elif "prompt(" in newvar:
e
elif "console.input(" in newvar:
e
elif "os.userinfo(" in newvar:
osUSERINFO()
allvars[res] = os.environ["REPL_OWNER"]
elif "time.strftime(" in newvar:
if time_module == 1:
timeSTRFTIME()
#allvars[] = time.strftime()
else:
raise InvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
else:
newvar = str(newvar) # makes sure its a string
if newvar[-1] == "'" and newvar[0] == "'" or newvar[-1] == "\"" and newvar[0] == "\"" or newvar[-1] == "`" and newvar[0] == "`":
newvar = newvar.replace(newvar[-1], "")
#newvar = newvar.replace(newvar[0], "")
elif "os.userinfo(" in newvar:
pass
else:
raise InvalidSyntaxError("Starting quotations and end quotations must be the same!")
allvars[newvar] = newvar
elif newvar == "true":
allvars[newvar] = True
elif newvar == "false":
allvars[newvar] = False
else:
raise InvalidSyntaxError("Variables must be named after there is a equal sign!")
else:
raise InvalidSyntaxError("Variables cannot include spaces!")
else:
allvars[newvar] = 0
elif "window.prompt(" in lines:
wrd = "window.prompt("
var = lines.partition(wrd)[2]
if var[-1] == ";":
split_string = var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var = split_string[0]
var.strip(");")
if var in allvars:
var = input()
allvars[newvar] = var
else:
if var not in allvars:
raise InvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raise InvalidSyntaxError("'window.prompt' statement is missing semi-colon!")
elif "prompt(" in lines:
wrd = "prompt("
var = lines.partition(wrd)[2]
if var[-1] == ";":
split_string = var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var = split_string[0]
var.strip(");")
if var in allvars:
var = input()
allvars[newvar] = var
else:
if var not in allvars:
raise InvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raise InvalidSyntaxError("'prompt' statement is missing semi-colon!")
elif "console.input(" in lines:
wrd = "console.input("
var = lines.partition(wrd)[2]
if var[-1] == ";":
split_string = var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var = split_string[0]
var.strip(");")
if var in allvars:
var = input()
allvars[newvar] = var
else:
if var not in allvars:
raise InvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raise InvalidSyntaxError("'console.input' statement is missing semi-colon!")
elif "window.alert(" in lines:
WINDOWalert()
elif "console.print(" in lines:
CONSOLEprint()
elif "alert(" in lines:
alert()
elif "if " in lines:
e
elif "time.sleep(" in lines:
if time_module == 1:
wrd = "time.sleep("
res = lines.partition(wrd)[2]
if res[-1] == ";":
try:
res = res.replace(");","")
for i in res:
if i in ["1","2","3","4","5","6","7","8","9","0"]:
time.sleep(int(res))
else:
raise InvalidStringIntError("Strings cannot be inside integer values!")
except:
raise InvalidSyntaxError("There must be only one semi-colon!")
else:
raise InvalidSyntaxError("'time.sleep' is missing semi-colon!")
else:
raise InvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
elif "time.time(" in lines:#remember to NOT print. It only prints when you do print
timeTIME()#this doesnt really do anything.
elif "time.strftime(" in lines:
timeSTRFTIME()
if time_module == 1:
wrd = "time.strftime("
elif "os.system(" in lines:
osSYSTEM()
elif "os.userinfo(" in lines:
osUSERINFO()
else:
pass