Skip to content

Commit 5788f1e

Browse files
committed
Don't strip multiline comments from docs
1 parent ba9a212 commit 5788f1e

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

generate_docs.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,19 @@ def split_header_to_chunks(path: Path) -> List[Chunk]:
331331
# Make sure no line starts with @, which is used as a marker.
332332
assert not re.search(r'^\s*@', code, flags=re.MULTILINE)
333333

334-
# Remove block comments.
335-
code = re.sub(r'/\*.*?\*/', lambda x: re.sub(r'[^\n]', '', x.group(0)), code, flags=re.DOTALL)
334+
# Remove block comments at the top of the file.
335+
code = re.sub(r'^/\*.*?\*/', lambda x: re.sub(r'[^\n]', '', x.group(0)), code, flags=re.DOTALL)
336+
337+
# Turn block comments into single-line comments with markers for easier parsing.
338+
assert '//@' not in code # Used as a marker.
339+
code = re.sub(
340+
r'/\*.*?\*/ *$',
341+
lambda x: '\n'.join([f'//@{line}' for line in x.group(0).split('\n')]),
342+
code,
343+
flags=re.DOTALL | re.MULTILINE,
344+
)
345+
assert '/*' not in re.sub(r'//.*', '', code)
346+
assert '*/' not in re.sub(r'//.*', '', code)
336347

337348
# Remove extern "C" declarations.
338349
code = code.replace('\n#ifdef __cplusplus\nextern "C" {\n#endif\n', '\n\n\n\n')
@@ -431,7 +442,18 @@ def split_header_to_chunks(path: Path) -> List[Chunk]:
431442
if len(idents) == 0:
432443
continue
433444

434-
result.append(Chunk(path.name, line_number, idents, before.copy(), intro, body, after.copy()))
445+
def remove_markers(code: str):
446+
return re.sub(r'//@', '', code)
447+
448+
result.append(Chunk(
449+
path.name,
450+
line_number,
451+
idents,
452+
[(remove_markers(x), remove_markers(y)) for x, y in before],
453+
remove_markers(intro),
454+
remove_markers(body),
455+
[remove_markers(x) for x in after],
456+
))
435457

436458
assert len(before) == 0, before
437459
assert len(after) == 0, after

0 commit comments

Comments
 (0)