Merge pull request #88 from robotpy/more-using
Retain doxygen comments for using declarations and type aliases
This commit is contained in:
commit
04ba4bffae
@ -992,7 +992,9 @@ class CxxParser:
|
||||
|
||||
self.visitor.on_using_namespace(state, names)
|
||||
|
||||
def _parse_using_declaration(self, tok: LexToken) -> None:
|
||||
def _parse_using_declaration(
|
||||
self, tok: LexToken, doxygen: typing.Optional[str]
|
||||
) -> None:
|
||||
"""
|
||||
using_declaration: "using" ["typename"] ["::"] nested_name_specifier unqualified_id ";"
|
||||
| "using" "::" unqualified_id ";"
|
||||
@ -1004,12 +1006,15 @@ class CxxParser:
|
||||
typename, _ = self._parse_pqname(
|
||||
tok, fn_ok=True, compound_ok=True, fund_ok=True
|
||||
)
|
||||
decl = UsingDecl(typename, self._current_access)
|
||||
decl = UsingDecl(typename, self._current_access, doxygen)
|
||||
|
||||
self.visitor.on_using_declaration(self.state, decl)
|
||||
|
||||
def _parse_using_typealias(
|
||||
self, id_tok: LexToken, template: typing.Optional[TemplateDecl]
|
||||
self,
|
||||
id_tok: LexToken,
|
||||
template: typing.Optional[TemplateDecl],
|
||||
doxygen: typing.Optional[str],
|
||||
) -> None:
|
||||
"""
|
||||
alias_declaration: "using" IDENTIFIER "=" type_id ";"
|
||||
@ -1023,7 +1028,7 @@ class CxxParser:
|
||||
|
||||
dtype = self._parse_cv_ptr(parsed_type)
|
||||
|
||||
alias = UsingAlias(id_tok.value, dtype, template, self._current_access)
|
||||
alias = UsingAlias(id_tok.value, dtype, template, self._current_access, doxygen)
|
||||
|
||||
self.visitor.on_using_alias(self.state, alias)
|
||||
|
||||
@ -1052,9 +1057,9 @@ class CxxParser:
|
||||
raise CxxParseError(
|
||||
"unexpected using-declaration when parsing alias-declaration", tok
|
||||
)
|
||||
self._parse_using_declaration(tok)
|
||||
self._parse_using_declaration(tok, doxygen)
|
||||
else:
|
||||
self._parse_using_typealias(tok, template)
|
||||
self._parse_using_typealias(tok, template, doxygen)
|
||||
|
||||
# All using things end with a semicolon
|
||||
self._next_token_must_be(";")
|
||||
|
@ -866,6 +866,9 @@ class UsingDecl:
|
||||
#: If within a class, the access level for this decl
|
||||
access: typing.Optional[str] = None
|
||||
|
||||
#: Documentation if present
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class UsingAlias:
|
||||
@ -886,3 +889,6 @@ class UsingAlias:
|
||||
|
||||
#: If within a class, the access level for this decl
|
||||
access: typing.Optional[str] = None
|
||||
|
||||
#: Documentation if present
|
||||
doxygen: typing.Optional[str] = None
|
||||
|
@ -26,6 +26,7 @@ from cxxheaderparser.types import (
|
||||
Type,
|
||||
Typedef,
|
||||
UsingDecl,
|
||||
UsingAlias,
|
||||
Value,
|
||||
Variable,
|
||||
)
|
||||
@ -436,3 +437,53 @@ def test_doxygen_attribute() -> None:
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_doxygen_using_decl() -> None:
|
||||
content = """
|
||||
// clang-format off
|
||||
|
||||
/// Comment
|
||||
using ns::ClassName;
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
using=[
|
||||
UsingDecl(
|
||||
typename=PQName(
|
||||
segments=[
|
||||
NameSpecifier(name="ns"),
|
||||
NameSpecifier(name="ClassName"),
|
||||
]
|
||||
),
|
||||
doxygen="/// Comment",
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_doxygen_using_alias() -> None:
|
||||
content = """
|
||||
// clang-format off
|
||||
|
||||
/// Comment
|
||||
using alias = sometype;
|
||||
"""
|
||||
data = parse_string(content, cleandoc=True)
|
||||
|
||||
assert data == ParsedData(
|
||||
namespace=NamespaceScope(
|
||||
using_alias=[
|
||||
UsingAlias(
|
||||
alias="alias",
|
||||
type=Type(
|
||||
typename=PQName(segments=[NameSpecifier(name="sometype")])
|
||||
),
|
||||
doxygen="/// Comment",
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user