-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperty_format.py
executable file
·39 lines (36 loc) · 1.09 KB
/
property_format.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
#!/usr/bin/env python3
import collections
import sys
import pprint
def format_input(full_string):
starting = full_string.strip().rstrip()
lines = starting.split('\n')
props = collections.OrderedDict()
line_iter = iter(lines)
for line in line_iter:
line = line.strip().rstrip()
if ' ' in line:
continue
next_line = next(line_iter)
props[line] = next_line
return props
def print_props(props):
entries = []
for prop, doc in props.items():
sub_entry = []
sub_entry.append(f'/** {doc} */')
if 'boolean' in doc or 'Boolean' in doc:
data_type = 'boolean'
elif 'integer' in doc or 'Integer' in doc:
data_type = 'number'
elif 'number' in doc or 'Number' in doc:
data_type = 'number'
else:
data_type = 'any'
sub_entry.append(f'{prop}: {data_type}')
entries.append('\n'.join(sub_entry))
print('\n\n'.join(entries))
if __name__ == '__main__':
all_input = sys.stdin.read()
props = format_input(all_input)
print_props(props)