@@ -18,11 +18,11 @@ def preprocess_output_doc_line(l):
18
18
if 'FIXED_SIZED_OUTPUT(' in l :
19
19
parts = [p .strip () for p in l [len ('FIXED_SIZED_OUTPUT(' ):- 1 ].split (',' )]
20
20
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 )
22
22
elif 'MAX_SIZED_OUTPUT(' in l :
23
23
parts = [p .strip () for p in l [len ('FIXED_SIZED_OUTPUT(' ):- 1 ].split (',' )]
24
24
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 )
26
26
return '* ' + l if l else None , text
27
27
28
28
def output_func (docs , func ):
@@ -60,20 +60,39 @@ def extract_docs(infile, outfile):
60
60
61
61
lines = [l .strip () for l in open (infile ).readlines ()]
62
62
if DUMP_INTERNAL :
63
- title = 'unused'
63
+ title , constant_title = 'unused' , 'unused'
64
64
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 )
67
68
output , current , func , state = [title , title_markup , '' ], [], '' , SCANNING
69
+ constants , last_one_liner = [' ' , constant_title , constant_markup , '' ], ''
68
70
69
71
for l in lines :
70
72
# Allow one-liner internal functions with no doc comments
71
73
if DUMP_INTERNAL and state == SCANNING and l .startswith ('WALLY_CORE_API' ):
72
74
state = FUNC
73
75
74
76
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 = ''
77
96
elif state == DOCS :
78
97
if l == '*/' :
79
98
state = FUNC
@@ -94,6 +113,8 @@ def extract_docs(infile, outfile):
94
113
current , func = '' , ''
95
114
state = SCANNING
96
115
116
+ if len (constants ) > 4 :
117
+ output .extend (constants )
97
118
with open (outfile , 'w' ) as f :
98
119
f .write ('\n ' .join (output ))
99
120
0 commit comments