-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloops.py
66 lines (48 loc) · 1.83 KB
/
loops.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
def special_detect(line):
if(line[0:6]=='print '):
count=line.count("var ")
if("var " not in line):
return("print(\""+line[6:len(line)]+"\")")
else:
return("print("+line[6:len(line)]+")")
else:
if(line[0:5]=="while"):
line+=" :"
elif(line[0:3]=='for'):
line+=" :"
elif(line=="else"):
line+=" :"
elif(line[0:6]=="define"):
nline=""
if(" of " in line):
pos=line.index(" of ")
nline=("def"+line[6:pos])
params=line[pos+4:len(line)].split()
nline+="("
for i in range(len(params)-1):
nline+=(params[i]+",")
nline+=(params[-1]+"):")
return nline
elif(line[0:5]=="class"):
line+=" :"
if ("square bracket open" in line):
count=line.count("square bracket open")
line=line.replace("square bracket open","[",count)
if ("square bracket close" in line):
count=line.count("square bracket close")
line=line.replace("square bracket close","]",count)
if ("bracket open " in line):
count=line.count("bracket open")
line=line.replace("bracket open","(",count)
if("bracket close" in line):
count=line.count("bracket close")
line=line.replace("bracket close",")",count)
dots=line.count(" dot ")
commas=line.count("comma ")
#print(commas)
if(dots>0):
line=line.replace("dot",".",dots)
if(commas>0):
line=line.replace("comma ",",",commas)
return line
#print(special_detect("print var wejf a plus asjdjnd"))