Uh oh!
There was an error while loading. Please reload this page.
This repository was 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
Expand file tree
/
Copy pathmain.py
More file actions
Latest commit
598 lines (534 loc) · 18.8 KB
/
Copy pathmain.py
File metadata and controls
598 lines (534 loc) · 18.8 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
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
importtime, os, sys, getpass, re, string
fp=input('FilePath: ')
if'.pys'infp:#hmmmm
try:
f=open(f'{fp}')
except:
raiseException("No Such File Exists!")
else:
raiseException("The file isn't a '.pys' file!")
content=f.read()
colist=content.split("\n")
defcheck():
df=re.findall("(?<=[AZaz])?(?!\d*=)[0-9.+-]+", lines)
df=str(df)
defwait_until(somepredicate, timeout, period=0.25, *args, **kwargs):
mustend=time.time() +timeout
whiletime.time() <mustend:
ifsomepredicate(*args, **kwargs): returnTrue
time.sleep(period)
returnFalse
#all errors
classInvalidVariableError(Exception):
pass
classInvalidSyntaxError(Exception):
pass
classInvalidIndentationError(Exception):
pass
classInvalidModuleError(Exception):
pass
classInvalidStringIntError(Exception):
pass
classTemplateError(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("]
deftimeTIME():
iftime_module==1:
wrd="time.time("
res=lines.partition(wrd)[2]
res=res.replace(");","")
print(res)
iftype(res) ==str:
ifres==" "orres=="":
time.time()#this won't do anything of course, unless you print it ;)
else:
raiseInvalidStringIntError("'time.time' must be empty!")
else:
raiseInvalidStringIntError("'time.time' must be empty!")
else:
raiseInvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
defosSYSTEM():
ifos_module==1:
wrd="os.system("
res=lines.partition(wrd)[2]
ifres[-3] =="\""andres[0] =="\'"orres[-3] =="'"andres[0] =="\"":
raiseInvalidSyntaxError("The 'os.system' starting quotations and ending quotations are different!")
else:
if"\""inres:
split_string=res.split("\");", -1)
elif"'"inres:
split_string=res.split("\');", -1)
else:
raiseInvalidSyntaxError("The 'os.system' statement is missing quotations!")
res=res.replace("\"", "")
res=res.replace("'", "")
res=res.replace(");", "")
#print(res)
try:
os.system(str(res))
except:
raiseInvalidModuleError(f"'{res}' command doesn't exist!")
else:
raiseInvalidModuleError("The 'os' module isn't imported or it doesn't exist!")
defosUSERINFO():
ifos_module==1:
wrd="os.userinfo("
globalres
res=lines.partition(wrd)[2]
if" "inres:
raiseInvalidSyntaxError("'os.userinfo' cannot include spaces!")
else:
if");"inres:
res=res.replace(");","")
else:
raiseInvalidSyntaxError("'os.userinfo' must have ');'!")
ifres==""orres==" ":
try:
print(os.environ["REPL_OWNER"])
except:
raiseInvalidModuleError("This function does not exist on your device!")
else:
raiseInvalidModuleError("'os.userinfo' must be empty!")
else:
raiseInvalidModuleError("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 ;)
'''
defWINDOWalert():#add f'string
try:
if'");'inlinesor"');"inlinesor"`);"inlines:
wrd="window.alert("
res=lines.partition(wrd)[2]
#print(res)
ifres[-3] =="\""andres[0] =="\'"orres[-3] =="\""andres[0] =="`"orres[-3] =="'"andres[0] =="\""orres[-3] =="'"andres[0] =="`"orres[-3] =="`"andres[0] =="\""orres[-3] =="`"andres[0] =="'":
raiseInvalidSyntaxError("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"\""inres:
split_string=res.split("\");", -1)
elif"'"inres:
split_string=res.split("\');", -1)
elif"`"inres:
split_string=res.split("`);", -1)
else:
raiseInvalidSyntaxError("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"{{"inres:
if"}}"inres:
start="{{"
end="}}"
check=res[res.find(start) +len(start):res.rfind(end)]
ifcheckinallvars:
res=res.replace("{{", "")
res=res.replace("}}", "")
dffdfdfdf=allvars[check]
res=res.replace(check, str(dffdfdfdf))
else:
globalPASS
PASS=False
if"time.time("incheck:
ifcheck[-1] =="(":
print(time.time())
PASS=True
else:
raiseInvalidSyntaxError("'time.time' must be empty!")
elif"time.strftime("incheck:
#print(timeSTRFTIME())
PASS=True
else:
#print(var)
#print(res)
raiseInvalidVariableError(f"'{var}' variable does not exist!")
ifPASS:
pass
else:
print(res, end="")
print()
else:
raiseInvalidSyntaxError("The 'window.alert' statement must have a closing ');!")
except:
raiseInvalidSyntaxError("The 'window.alert' statement must have a closing ');!")
defalert():
try:
if'");'inlinesor"');"inlinesor"`);"inlines:
wrd="alert("
res=lines.partition(wrd)[2]
ifres[-3] =="\""andres[0] =="\'"orres[-3] =="\""andres[0] =="`"orres[-3] =="'"andres[0] =="\""orres[-3] =="'"andres[0] =="`"orres[-3] =="`"andres[0] =="\""orres[-3] =="`"andres[0] =="'":
raiseInvalidSyntaxError("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"\""inres:
split_string=res.split("\");", -1)
elif"'"inres:
split_string=res.split("\');", -1)
elif"`"inres:
split_string=res.split("`);", -1)
else:
raiseInvalidSyntaxError("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"{{"inres:
if"}}"inres:
start="{{"
end="}}"
check=res[res.find(start) +len(start):res.rfind(end)]
ifcheckinallvars:
res=res.replace("{{", "")
res=res.replace("}}", "")
dffdfdfdf=allvars[check]
res=res.replace(check, str(dffdfdfdf))
else:
globalPASS
PASS=False
if"time.time("incheck:
ifcheck[-1] =="(":
print(time.time())
PASS=True
else:
raiseInvalidSyntaxError("'time.time' must be empty!")
elif"time.strftime("incheck:
#print(timeSTRFTIME())
PASS=True
else:
raiseInvalidVariableError(f"'{var}' variable does not exist!")
ifPASS:
pass
else:
print(res, end="")
print()
else:
raiseInvalidSyntaxError("The 'alert' statement must have a closing ');!")
except:
raiseInvalidSyntaxError("The 'alert' statement must have a closing ');!")
defCONSOLEprint():
try:
if'");'inlinesor"');"inlinesor"`);"inlines:
wrd="console.print("
res=lines.partition(wrd)[2]
ifres[-3] =="\""andres[0] =="\'"orres[-3] =="\""andres[0] =="`"orres[-3] =="'"andres[0] =="\""orres[-3] =="'"andres[0] =="`"orres[-3] =="`"andres[0] =="\""orres[-3] =="`"andres[0] =="'":
raiseInvalidSyntaxError("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"\""inres:
split_string=res.split("\");", -1)
elif"'"inres:
split_string=res.split("\');", -1)
elif"`"inres:
split_string=res.split("`);", -1)
else:
raiseInvalidSyntaxError("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"{{"inres:
if"}}"inres:
start="{{"
end="}}"
check=res[res.find(start) +len(start):res.rfind(end)]
ifcheckinallvars:
res=res.replace("{{", "")
res=res.replace("}}", "")
dffdfdfdf=allvars[check]
res=res.replace(check, str(dffdfdfdf))
else:
globalPASS
PASS=False
if"time.time("incheck:
ifcheck[-1] =="(":
print(time.time())
PASS=True
else:
raiseInvalidSyntaxError("'time.time' must be empty!")
elif"time.strftime("incheck:
#print(timeSTRFTIME())
PASS=True
else:
raiseInvalidVariableError(f"'{var}' variable does not exist!")
ifPASS:
pass
else:
print(res, end="")
print()
else:
raiseInvalidSyntaxError("The 'console.print' statement must have a closing ');!")
except:
raiseInvalidSyntaxError("The 'console.print' statement must have a closing ');!")
newvar=0
time_module=0
file=open(fp)
readline2=0
forlinesinfile.readlines():
#print(lines)
if"/#"inlines:
readline2=1
#print(wait_until("*/", 0))
wait_until("#/", 0)
ifreadline2==1:
readline2=0
continue
if"//"inlines:#maybe change to /#
readline2=1
line+=1
lines=lines.replace('\n','')
lines=lines.replace('\t','')
#print(lines)
iflines=='':
pass
eliflinesinstring.whitespace:
raiseInvalidIndentationError("Your indentation does not fit the other statements!")
elif"/#"inlines:
wait_until("#/", 0)
readline2=1
elif"//"inlines:
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
'''
iflines[:2] =="//"or"//"inlines:
pass
read_line=0
elif"import(\"time\");"inlinesor"import('time');"inlines:#add semicolon error
time_module=1
elif"import(\"os\");"inlinesor"import('os');"inlines:
os_module=1
elif"var "inlines:
wrd="var "
newvar=lines.partition(wrd)[2]
split_string=newvar.split("\")", -1)
newvar.replace(")","")
newvar.replace('\"', '')
newvar=split_string[0]
#newvar = variable;
ifnewvar[-1] ==";":
if";"innewvar[:-1]:
foriinnewvar[:-1]:
if"'"==ior"\""==ior"`"==i:
pass
else:
raiseInvalidSyntaxError("You must only include one semi-colon!")
else:
newvarTEST=newvar[-1]
newvar=newvar.replace(";","")#make ; disappear into blank space
else:
raiseInvalidSyntaxError("Variable statement is missing semi-colon!")
if" "innewvar:
if"="innewvar:
idk= []
Continue=True
foriinnewvar:
ifContinue:
ifi=="=":
idk.append(i)
Continue=False
else:
idk.append(i)
else:
ifi==" ":
idk.append(i)
break
else:
break
idk="".join(idk)
newvar=newvar.replace(idk, "")
if"'"innewvaror"\""innewvaror"`"innewvaror"os.userinfo("innewvar:
ifnewvarinfunctions:
if"console.print("innewvar:
CONSOLEprint()
elif"window.alert("innewvar:
WINDOWalert()
elif"alert("innewvar:
alert()
elif"window.prompt("innewvar:
e
elif"prompt("innewvar:
e
elif"console.input("innewvar:
e
elif"os.userinfo("innewvar:
osUSERINFO()
allvars[res] =os.environ["REPL_OWNER"]
elif"time.strftime("innewvar:
iftime_module==1:
timeSTRFTIME()
#allvars[] = time.strftime()
else:
raiseInvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
else:
newvar=str(newvar) # makes sure its a string
ifnewvar[-1] =="'"andnewvar[0] =="'"ornewvar[-1] =="\""andnewvar[0] =="\""ornewvar[-1] =="`"andnewvar[0] =="`":
newvar=newvar.replace(newvar[-1], "")
#newvar = newvar.replace(newvar[0], "")
elif"os.userinfo("innewvar:
pass
else:
raiseInvalidSyntaxError("Starting quotations and end quotations must be the same!")
allvars[newvar] =newvar
elifnewvar=="true":
allvars[newvar] =True
elifnewvar=="false":
allvars[newvar] =False
else:
raiseInvalidSyntaxError("Variables must be named after there is a equal sign!")
else:
raiseInvalidSyntaxError("Variables cannot include spaces!")
else:
allvars[newvar] =0
elif"window.prompt("inlines:
wrd="window.prompt("
var=lines.partition(wrd)[2]
ifvar[-1] ==";":
split_string=var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var=split_string[0]
var.strip(");")
ifvarinallvars:
var=input()
allvars[newvar] =var
else:
ifvarnotinallvars:
raiseInvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raiseInvalidSyntaxError("'window.prompt' statement is missing semi-colon!")
elif"prompt("inlines:
wrd="prompt("
var=lines.partition(wrd)[2]
ifvar[-1] ==";":
split_string=var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var=split_string[0]
var.strip(");")
ifvarinallvars:
var=input()
allvars[newvar] =var
else:
ifvarnotinallvars:
raiseInvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raiseInvalidSyntaxError("'prompt' statement is missing semi-colon!")
elif"console.input("inlines:
wrd="console.input("
var=lines.partition(wrd)[2]
ifvar[-1] ==";":
split_string=var.split(");", -1)
var.replace(');','')
var.replace('\"',"")
var.replace('\'',"")
var.replace('`',"")
var=split_string[0]
var.strip(");")
ifvarinallvars:
var=input()
allvars[newvar] =var
else:
ifvarnotinallvars:
raiseInvalidVariableError(f"'{var}' variable does not exist!")
else:
pass
else:
raiseInvalidSyntaxError("'console.input' statement is missing semi-colon!")
elif"window.alert("inlines:
WINDOWalert()
elif"console.print("inlines:
CONSOLEprint()
elif"alert("inlines:
alert()
elif"if "inlines:
e
elif"time.sleep("inlines:
iftime_module==1:
wrd="time.sleep("
res=lines.partition(wrd)[2]
ifres[-1] ==";":
try:
res=res.replace(");","")
foriinres:
ifiin ["1","2","3","4","5","6","7","8","9","0"]:
time.sleep(int(res))
else:
raiseInvalidStringIntError("Strings cannot be inside integer values!")
except:
raiseInvalidSyntaxError("There must be only one semi-colon!")
else:
raiseInvalidSyntaxError("'time.sleep' is missing semi-colon!")
else:
raiseInvalidModuleError("The 'time' module isn't imported or it doesn't exist!")
elif"time.time("inlines:#remember to NOT print. It only prints when you do print
timeTIME()#this doesnt really do anything.
elif"time.strftime("inlines:
timeSTRFTIME()
iftime_module==1:
wrd="time.strftime("
elif"os.system("inlines:
osSYSTEM()
elif"os.userinfo("inlines:
osUSERINFO()
else:
pass