1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00
vimr/bin/generate_source.py

39 lines
1.1 KiB
Python
Raw Normal View History

2018-01-21 16:16:07 +03:00
#!/usr/bin/env python3
import os
import io
import re
from string import Template
2017-12-03 11:59:15 +03:00
print(os.getcwd())
if 'CONFIGURATION' in os.environ and os.environ['CONFIGURATION'] == 'Debug':
2018-01-21 16:16:07 +03:00
if os.path.isfile('./NvimView/NvimAutoCommandEvent.generated.swift'):
print("Files already there, exiting...")
exit(0)
with io.open('./neovim/build/include/auevents_enum.generated.h', 'r') as auto_cmds_file:
raw_auto_cmds = [line.strip() for line in auto_cmds_file.readlines() if re.match(r'^EVENT_', line.strip())]
def convert(line):
result = re.match(r'^EVENT_(.*) = (.*)', line.replace(',', ''))
return result.group(1), result.group(2)
auto_cmds = [convert(line) for line in raw_auto_cmds]
2018-01-21 16:16:07 +03:00
auto_cmds_template = Template(
'''
2018-01-21 16:16:07 +03:00
enum NvimAutoCommandEvent: Int {
${event_cases}
}
'''
2018-01-21 16:16:07 +03:00
)
2018-01-21 16:16:07 +03:00
header = auto_cmds_template.substitute(
event_cases='\n'.join(
2018-01-21 16:16:07 +03:00
[' case {} = {}'.format(event[0].lower(), event[1]) for event in auto_cmds]
),
)
2018-01-21 16:16:07 +03:00
with io.open('./NvimView/NvimAutoCommandEvent.generated.swift', 'w') as auto_cmds_header_file:
auto_cmds_header_file.write(header)