Created
October 18, 2017 08:18
-
-
Save adiog/4d76a6fe05149d960ce21b8be36f1040 to your computer and use it in GitHub Desktop.
forced doxygen crap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
def split_last_space(text): | |
text = re.sub(r'^ *', '', text) | |
text = re.sub(r' *$', '', text) | |
text_split = text.split(' ') | |
first = ' '.join(text_split[:-1]) | |
second = text_split[-1] | |
return first, second | |
def insert_doxygen(filename): | |
with open(filename) as file: | |
lines = [] | |
for line in file: | |
lines.append(line) | |
for i, line in enumerate(lines): | |
if '/// INSERT_DOXYGEN' in line: | |
json_doxy = {} | |
index = i+1 | |
while not ')' in lines[index]: | |
index += 1 | |
merged_line = re.sub(r'\n', ' ', ''.join(lines[i+1:index+1])) | |
merged_line = merged_line.split(')')[0] | |
split_sig = merged_line.split('(') | |
return_type, function_name = split_last_space(split_sig[0]) | |
json_doxy['return_type'] = return_type | |
json_doxy['function_name'] = function_name | |
arguments = {} | |
if split_sig[1]: | |
split_args = split_sig[1].split(',') | |
for arg in split_args: | |
arg_type, arg_name = split_last_space(arg) | |
arguments[arg_name] = arg_type | |
json_doxy['arguments'] = arguments | |
print(f'/// {json_doxy}') | |
else: | |
print(re.sub(r'\n', '', line)) | |
if __name__ == '__main__': | |
insert_doxygen(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment