-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbetter_binder.py
More file actions
44 lines (41 loc) · 915 Bytes
/
better_binder.py
File metadata and controls
44 lines (41 loc) · 915 Bytes
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
#adding .bind(this) always if this.function does not have ( or . after it
def find_word_end_after(s, start_id):
for id in range(start_id, len(s)):
ch=s[id]
if not (ch.isalnum() or ch=="_"):
break
return id-1
def has_function_call_after(s, start_id):
res=False
for id in range(start_id, len(s)):
ch=s[id]
if ch=="." or ch=="(":
return True
if ch in " \n":
id+=1
else:
return False
def better_binds(s, list_of_func):
res=""
while s!="":
thid=s.find("this.")
if thid!=-1:
ch=s[thid-1]
if not (ch.isalpha() or ch=="_"):
endid=find_word_end_after(s, thid+5)
wrd=s[thid+5:endid+1]
if wrd in list_of_func:
if not has_function_call_after(s, endid+1):
res+=s[0:endid+1]+".bind(this)"
else:
res+=s[0:endid+1]
else:
res+=s[0:endid+1]
s=s[endid+1:]
else:
res+=s[0:thid+5]
s=s[thid+5:]
else:
res+=s;
break
return res