2017-05-27 12:07:26 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import io
|
|
|
|
import re
|
|
|
|
from string import Template
|
|
|
|
|
2017-12-03 11:59:15 +03:00
|
|
|
print(os.getcwd())
|
2017-05-27 12:07:26 +03:00
|
|
|
if 'CONFIGURATION' in os.environ and os.environ['CONFIGURATION'] == 'Debug':
|
2017-12-03 19:37:02 +03:00
|
|
|
if os.path.isfile('./NvimView/NvimAutoCommandEvent.generated.h') and os.path.isfile('./NvimView/NvimAutoCommandEvent.generated.m'):
|
2017-05-27 12:07:26 +03:00
|
|
|
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]
|
|
|
|
auto_cmds_impl_template = Template(
|
|
|
|
'''
|
|
|
|
@import Foundation;
|
2017-12-03 19:37:02 +03:00
|
|
|
#import "NvimAutoCommandEvent.generated.h"
|
2017-05-27 12:07:26 +03:00
|
|
|
|
2017-12-03 19:37:02 +03:00
|
|
|
NSString *nvimAutoCommandEventName(NvimAutoCommandEvent event) {
|
2017-05-27 12:07:26 +03:00
|
|
|
switch (event) {
|
|
|
|
${event_cases}
|
|
|
|
default: return @"NON_EXISTING_EVENT";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
impl = auto_cmds_impl_template.substitute(
|
|
|
|
event_cases='\n'.join(
|
2017-12-03 19:37:02 +03:00
|
|
|
[' case NvimAutoCommandEvent{}: return @"{}";'.format(event[0], event[0]) for event in auto_cmds])
|
2017-05-27 12:07:26 +03:00
|
|
|
)
|
2017-12-03 19:37:02 +03:00
|
|
|
with io.open('./NvimView/NvimAutoCommandEvent.generated.m', 'w') as auto_cmds_impl_file:
|
2017-05-27 12:07:26 +03:00
|
|
|
auto_cmds_impl_file.write(unicode(impl))
|
|
|
|
|
|
|
|
auto_cmds_header_template = Template(
|
|
|
|
'''
|
|
|
|
@import Foundation;
|
|
|
|
|
2017-12-03 19:37:02 +03:00
|
|
|
typedef NS_ENUM(NSUInteger, NvimAutoCommandEvent) {
|
2017-05-27 12:07:26 +03:00
|
|
|
${event_cases}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NumberOfAutoCommandEvents ${count}
|
2017-12-03 19:37:02 +03:00
|
|
|
extern NSString * __nonnull nvimAutoCommandEventName(NvimAutoCommandEvent event);
|
2017-05-27 12:07:26 +03:00
|
|
|
''')
|
|
|
|
|
|
|
|
header = auto_cmds_header_template.substitute(
|
|
|
|
event_cases='\n'.join(
|
2017-12-03 19:37:02 +03:00
|
|
|
[' NvimAutoCommandEvent{} = {},'.format(event[0], event[1]) for event in auto_cmds]
|
2017-05-27 12:07:26 +03:00
|
|
|
),
|
|
|
|
count=str(len(auto_cmds))
|
|
|
|
)
|
2017-12-03 19:37:02 +03:00
|
|
|
with io.open('./NvimView/NvimAutoCommandEvent.generated.h', 'w') as auto_cmds_header_file:
|
2017-05-27 12:07:26 +03:00
|
|
|
auto_cmds_header_file.write(unicode(header))
|