2018-01-21 16:16:07 +03:00
|
|
|
#!/usr/bin/env python3
|
2017-05-27 12:07:26 +03:00
|
|
|
|
|
|
|
import os
|
|
|
|
import io
|
|
|
|
import re
|
|
|
|
from string import Template
|
|
|
|
|
2019-12-26 12:47:09 +03:00
|
|
|
# Assume that we're in $REPO_ROOT/NvimView
|
2017-05-27 12:07:26 +03:00
|
|
|
|
2020-12-20 17:53:11 +03:00
|
|
|
NVIM_AUEVENTS_ENUM_FILE = "./build/include/auevents_enum.generated.h"
|
2019-12-22 23:45:42 +03:00
|
|
|
SWIFT_TEMPLATE_FILE = "../resources/autocmds.template.swift"
|
|
|
|
|
|
|
|
|
|
|
|
def convert(line: str) -> (str, str):
|
2017-05-27 12:07:26 +03:00
|
|
|
result = re.match(r'^EVENT_(.*) = (.*)', line.replace(',', ''))
|
|
|
|
return result.group(1), result.group(2)
|
|
|
|
|
|
|
|
|
2019-12-22 23:45:42 +03:00
|
|
|
def swift_autocmds(version: str, template_string: str) -> str:
|
|
|
|
with io.open(NVIM_AUEVENTS_ENUM_FILE, "r") as auto_cmds_file:
|
2018-01-23 11:48:36 +03:00
|
|
|
raw_auto_cmds = [line.strip() for line in auto_cmds_file.readlines() if re.match(r'^EVENT_', line.strip())]
|
|
|
|
|
2019-12-22 23:45:42 +03:00
|
|
|
autocmds = [convert(line) for line in raw_auto_cmds]
|
|
|
|
template = Template(template_string)
|
2018-01-23 11:48:36 +03:00
|
|
|
|
2019-12-22 23:45:42 +03:00
|
|
|
return template.substitute(
|
|
|
|
event_cases="\n".join(
|
|
|
|
[f" case {event[0].lower()} = {event[1]}" for event in autocmds]
|
2018-01-23 11:48:36 +03:00
|
|
|
),
|
2018-01-27 14:29:49 +03:00
|
|
|
version=version
|
2018-01-23 11:48:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-12-22 23:45:42 +03:00
|
|
|
version = os.environ['version']
|
2019-12-26 12:47:09 +03:00
|
|
|
with io.open(SWIFT_TEMPLATE_FILE, "r") as template:
|
|
|
|
print(swift_autocmds(version, template.read()))
|