Skip to content

Commit 1732757

Browse files
author
Mike Solomon
committed
Create apply-backend-es-annotations.py
1 parent 1fce934 commit 1732757

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

apply-backend-es-annotations.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
3+
for root, dirs, files in os.walk("src", topdown=False):
4+
for name in files:
5+
p = os.path.join(root, name)
6+
if 'RequiredAndOptional' in p: continue
7+
with open(p, "r") as f:
8+
content = f.read()
9+
content = content.splitlines()
10+
content = [x for x in content if '-- @inline export' not in x]
11+
# find functions candidates
12+
candidates = []
13+
for x in range(len(content)):
14+
l = content[x]
15+
if l[:4] == ' ::': candidates.append(content[x-1])
16+
elif '::' in l and '->' in l: candidates.append(content[x])
17+
candidates = [x.replace('foreign import','').split('::')[0].strip() for x in candidates]
18+
candidates = [x for x in candidates if '--' not in x]
19+
arity = {}
20+
for candidate in candidates:
21+
for x in range(len(content)):
22+
l = content[x]
23+
fi = 'foreign import '
24+
if (l[:len(candidate)] == candidate)| (l[:len(fi+candidate)] == fi+candidate):
25+
if '::' in l:
26+
arity[candidate] = l.split('::')[1].count('->')
27+
elif ('::' in content[x+1]) & ('->' in content[x+1]):
28+
arity[candidate] = content[x+1].split('::')[1].count('->')
29+
else:
30+
a = 0
31+
y = x + 2
32+
while True:
33+
if ' ->' in content[y]:
34+
a += 1
35+
y += 1
36+
else: break
37+
arity[candidate] = a
38+
break
39+
content = [f'-- @inline export {k} arity={v}' for k,v in arity.items() if v != 0] + content
40+
content = '\n'.join(content)
41+
with open(p, "w") as f:
42+
f.write(content)

0 commit comments

Comments
 (0)