Skip to content

Commit d5d7508

Browse files
committed
docs: generate documentation for library constants/flags
1 parent f17e57a commit d5d7508

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

docs/source/conf.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def preprocess_output_doc_line(l):
1818
if 'FIXED_SIZED_OUTPUT(' in l:
1919
parts = [p.strip() for p in l[len('FIXED_SIZED_OUTPUT('):-1].split(',')]
2020
len_param, param, size = parts
21-
text = ':param {}: Size of ``{}``. Must be ``{}``.'.format(len_param, param, size)
21+
text = ':param {}: Size of ``{}``. Must be `{}`.'.format(len_param, param, size)
2222
elif 'MAX_SIZED_OUTPUT(' in l:
2323
parts = [p.strip() for p in l[len('FIXED_SIZED_OUTPUT('):-1].split(',')]
2424
len_param, param, max_size = parts
25-
text = ':param {}: Size of ``{}``. Passing ``{}`` will ensure the buffer is large enough.'.format(len_param, param, max_size)
25+
text = ':param {}: Size of ``{}``. Passing `{}` will ensure the buffer is large enough.'.format(len_param, param, max_size)
2626
return '* ' + l if l else None, text
2727

2828
def output_func(docs, func):
@@ -60,20 +60,39 @@ def extract_docs(infile, outfile):
6060

6161
lines = [l.strip() for l in open(infile).readlines()]
6262
if DUMP_INTERNAL:
63-
title = 'unused'
63+
title, constant_title = 'unused', 'unused'
6464
else:
65-
title = infile.split('wally_')[1][:-2].title().replace('_', '-') + ' Functions'
66-
title_markup = '=' * len(title)
65+
base_title = infile.split('wally_')[1][:-2].title().replace('_', '-')
66+
title, constant_title = base_title + ' Functions', base_title + ' Constants'
67+
title_markup, constant_markup = '=' * len(title), '-' * len(constant_title)
6768
output, current, func, state = [title, title_markup, ''], [], '', SCANNING
69+
constants, last_one_liner = [' ', constant_title, constant_markup, ''], ''
6870

6971
for l in lines:
7072
# Allow one-liner internal functions with no doc comments
7173
if DUMP_INTERNAL and state == SCANNING and l.startswith('WALLY_CORE_API'):
7274
state = FUNC
7375

7476
if state == SCANNING:
75-
if l.startswith('/**') and '*/' not in l:
76-
current, func, state = [l[3:]], '', DOCS
77+
if l.startswith('/***'):
78+
mark, details = l[4:-2].strip().split(' ', 1)
79+
constants.extend([f'.. _{mark}:', '', details, '^' *len(details)])
80+
elif l.startswith('/**'):
81+
if '*/' in l:
82+
last_one_liner = l[3:-2].strip()
83+
else:
84+
current, func, state = [l[3:]], '', DOCS
85+
elif l.startswith('#define ') and ' ' in l[len('#define '):]: # and '/*' not in l:
86+
c, remainder = l[len('#define '):].strip().split(' ', 1)
87+
if '/* ' in remainder:
88+
remainder = remainder.split('/* ')[0].strip()
89+
if '/**' in remainder:
90+
last_one_liner = remainder.split('/**')[1][:-2]
91+
constants.extend(['.. c:macro:: ' + c.strip(), ' ',
92+
' ' + last_one_liner.strip(), ''])
93+
last_one_liner = ''
94+
else:
95+
last_one_liner = ''
7796
elif state == DOCS:
7897
if l == '*/':
7998
state = FUNC
@@ -94,6 +113,8 @@ def extract_docs(infile, outfile):
94113
current, func = '', ''
95114
state = SCANNING
96115

116+
if len(constants) > 4:
117+
output.extend(constants)
97118
with open(outfile, 'w') as f:
98119
f.write('\n'.join(output))
99120

0 commit comments

Comments
 (0)