summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2022-04-17 17:17:19 +0200
committerJakob Lykke Andersen <Jakob@caput.dk>2022-04-17 17:17:19 +0200
commit991fe26fa5683bb76a925389024d375c6bb11dba (patch)
treece60b5bc9d132660e599b03b9f8a65bb7a4d233e /sphinx/util
parentd951e55bc3419dbda809ed0aca17addeed8e9e30 (diff)
downloadsphinx-git-991fe26fa5683bb76a925389024d375c6bb11dba.tar.gz
C and C++, refactor attribute lists
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/cfamily.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py
index e751ae9bb..027417dd6 100644
--- a/sphinx/util/cfamily.py
+++ b/sphinx/util/cfamily.py
@@ -192,6 +192,30 @@ class ASTParenAttribute(ASTAttribute):
signode.append(nodes.Text(txt, txt))
+class ASTAttributeList(ASTBaseBase):
+ def __init__(self, attrs: List[ASTAttribute]) -> None:
+ self.attrs = attrs
+
+ def __len__(self) -> int:
+ return len(self.attrs)
+
+ def __add__(self, other: "ASTAttributeList") -> "ASTAttributeList":
+ return ASTAttributeList(self.attrs + other.attrs)
+
+ def _stringify(self, transform: StringifyTransform) -> str:
+ return ' '.join(transform(attr) for attr in self.attrs)
+
+ def describe_signature(self, signode: TextElement) -> None:
+ if len(self.attrs) == 0:
+ return
+ self.attrs[0].describe_signature(signode)
+ if len(self.attrs) == 1:
+ return
+ for attr in self.attrs[1:]:
+ signode.append(addnodes.desc_sig_space())
+ attr.describe_signature(signode)
+
+
################################################################################
class ASTBaseParenExprList(ASTBaseBase):
@@ -423,5 +447,14 @@ class BaseParser:
return None
+ def _parse_attribute_list(self) -> ASTAttributeList:
+ res = []
+ while True:
+ attr = self._parse_attribute()
+ if attr is None:
+ break
+ res.append(attr)
+ return ASTAttributeList(res)
+
def _parse_paren_expression_list(self) -> ASTBaseParenExprList:
raise NotImplementedError