forked from jmzkChain/jmzk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_ex_trans.py
33 lines (25 loc) · 855 Bytes
/
gen_ex_trans.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
#!/usr/bin/env python3
import json
import re
import click
@click.command()
@click.argument('input', type=click.Path(exists=True))
@click.argument('output', type=click.Path())
def gen(input, output):
exs = []
with open(input, 'r') as reader:
for line in reader:
if not line.startswith('FC_DECLARE_DERIVED_EXCEPTION'):
continue
result = re.match(
r'FC_DECLARE_DERIVED_EXCEPTION\(\s+(\w+),\s+(\w+),\s+(\d+),\s+\"(.+)\"\s?\)', line)
if result:
exs.append({
'name': result.group(1),
'code': result.group(3),
'en': result.group(4)
})
with open(output, 'w') as writer:
writer.write(json.dumps(exs, ensure_ascii=False, indent=2))
if __name__ == '__main__':
gen()