diff --git a/cxxheaderparser/parser.py b/cxxheaderparser/parser.py index b240b91..d0da4db 100644 --- a/cxxheaderparser/parser.py +++ b/cxxheaderparser/parser.py @@ -404,7 +404,7 @@ class CxxParser: # TODO: namespace_alias_definition - ns = NamespaceDecl(names, inline) + ns = NamespaceDecl(names, inline, doxygen) state = self._push_state(NamespaceBlockState, ns) state.location = location self.visitor.on_namespace_start(state) diff --git a/cxxheaderparser/simple.py b/cxxheaderparser/simple.py index c4ce156..262155a 100644 --- a/cxxheaderparser/simple.py +++ b/cxxheaderparser/simple.py @@ -92,6 +92,7 @@ class NamespaceScope: name: str = "" inline: bool = False + doxygen: typing.Optional[str] = None classes: typing.List["ClassScope"] = field(default_factory=list) enums: typing.List[EnumDecl] = field(default_factory=list) @@ -249,8 +250,9 @@ class SimpleCxxVisitor: assert ns is not None - # only set inline on inner namespace + # only set inline/doxygen on inner namespace ns.inline = state.namespace.inline + ns.doxygen = state.namespace.doxygen self.block = ns self.namespace = ns diff --git a/cxxheaderparser/types.py b/cxxheaderparser/types.py index 72382be..e13c958 100644 --- a/cxxheaderparser/types.py +++ b/cxxheaderparser/types.py @@ -56,6 +56,9 @@ class NamespaceDecl: names: typing.List[str] inline: bool = False + #: Documentation if present + doxygen: typing.Optional[str] = None + @dataclass class DecltypeSpecifier: diff --git a/tests/test_doxygen.py b/tests/test_doxygen.py index 97cbd07..f82e615 100644 --- a/tests/test_doxygen.py +++ b/tests/test_doxygen.py @@ -290,3 +290,42 @@ def test_doxygen_var_after() -> None: ] ) ) + + +def test_doxygen_namespace() -> None: + content = """ + /** + * x is a mysterious namespace + */ + namespace x {} + + /** + * c is also a mysterious namespace + */ + namespace a::b::c {} + """ + data = parse_string(content, cleandoc=True) + + assert data == ParsedData( + namespace=NamespaceScope( + namespaces={ + "x": NamespaceScope( + name="x", doxygen="/**\n* x is a mysterious namespace\n*/" + ), + "a": NamespaceScope( + name="a", + namespaces={ + "b": NamespaceScope( + name="b", + namespaces={ + "c": NamespaceScope( + name="c", + doxygen="/**\n* c is also a mysterious namespace\n*/", + ) + }, + ) + }, + ), + } + ) + )