-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_scite_api_files_5.py
66 lines (43 loc) · 1.74 KB
/
make_scite_api_files_5.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
#!python3
'''Make scitestyler.api file from ScriptLexer.html.'''
import os, re, textwrap
import common
if __name__ == '__main__':
# Set output path.
output = common.settings['output']
if not os.path.isdir(output):
os.makedirs(output)
# Read ScriptLexer.html.
file = os.path.join('scite', 'doc', 'ScriptLexer.html')
if not os.path.isfile(file):
exit('"' + file + '" not found')
with open(file, encoding='utf-8') as r:
content = r.read()
content = content.replace('\u2192', ':')
# Get commands, return values and comments.
matches = re.findall(r'<table.+?>.*?</table>', content, re.I|re.S)
if matches:
matches = re.findall(r'<tr><td>(.*?)(?: : (\w+)){0,1}</td>\s*<td>(.*?)</td></tr>', matches[-1], re.I|re.S)
wrapper = textwrap.TextWrapper(width=75)
stylers = []
for item in matches:
signature, retval, comment = item
comment = re.sub('\r?\n|\t', ' ', comment)
comment = re.sub(' {2,}', ' ', comment)
if len(comment) > 75:
comment = '\\n'.join(wrapper.wrap(comment))
if ')' in signature:
pattern = 'styler:{0} {2}'
if retval:
pattern += '\\n Return: {1}'
else:
pattern = 'styler.{0} (-) [{1}]\\n {2}'
stylers.append(pattern.format(signature, retval, comment))
# Write to scitemenucommands.api.
if stylers:
stylers.sort()
print('output:\n scitestyler.api')
with open(os.path.join(output, 'scitestyler.api'), 'w', encoding='utf-8') as w:
for item in stylers:
w.write(item + '\n')
print('done')