Skip to content

Commit 2671023

Browse files
authored
Add attribute support (via 'annotation' directive) (#97)
This PR adds an 'annotation' directive to our Sphinx integration which enables documenting attributes. In Sphinx, attributes are an existing concepts, which refer to what Chapel would call fields. As a result, the `attr` directive was taken, and `attribute` on top of that seemed confusing. @lydia-duncan suggested 'annotation' (perhaps in jest), but I think it's a pretty decent fallback. Another PR to chpldoc will be necessary to actually emit 'annotation' directives; it will not be part of this. Reviewed by @lydia-duncan -- thanks!
2 parents 519f422 + c9f0795 commit 2671023

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: sphinxcontrib/chapeldomain/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
chpl_sig_pattern = re.compile(
4343
r"""^ ((?:\w+\s+)* # opt: prefixes
4444
(?:
45-
proc|iter|class|record|interface|operator # must end with keyword
45+
proc|iter|class|record|
46+
interface|operator|attribute # must end with keyword
4647
)\s+
4748
(?:type\s+|param\s+|ref\s+)? # opt: 'this' intent
4849
# (type, param, ref)
@@ -51,6 +52,7 @@
5152
\s*?
5253
(
5354
(?:[\w$][\w$=]*)| # function or method name
55+
(?:@[\w$][\w$=\.]*)| # or @attribute name
5456
(?:[+*/!~%<>=&^|\-:]+) # or operator name
5557
) \s*
5658
(?:\((.*?)\))? # opt: arguments
@@ -277,7 +279,8 @@ def _is_proc_like(self):
277279
return (self.objtype in
278280
('function', 'iterfunction',
279281
'method', 'itermethod',
280-
'opfunction', 'opmethod'))
282+
'opfunction', 'opmethod',
283+
'annotation'))
281284

282285
def _get_sig_prefix(self, sig):
283286
"""Return signature prefix text. For attribute, data, and proc/iter
@@ -815,6 +818,7 @@ class ChapelDomain(Domain):
815818
'module': ObjType(_('module'), 'mod'),
816819
'opmethod': ObjType(_('opmethod'), 'op'),
817820
'opfunction': ObjType(_('opfunction'), 'op'),
821+
'annotation': ObjType(_('annotation'), 'annotation'),
818822
}
819823

820824
directives = {
@@ -823,6 +827,7 @@ class ChapelDomain(Domain):
823827
'function': ChapelModuleLevel,
824828
'iterfunction': ChapelModuleLevel,
825829
'opfunction': ChapelModuleLevel,
830+
'annotation': ChapelModuleLevel,
826831

827832
'class': ChapelClassObject,
828833
'record': ChapelClassObject,
@@ -838,6 +843,7 @@ class ChapelDomain(Domain):
838843
}
839844

840845
roles = {
846+
'annotation': ChapelXRefRole(),
841847
'data': ChapelXRefRole(),
842848
'const': ChapelXRefRole(),
843849
'var': ChapelXRefRole(),

Diff for: test/test_chapeldomain.py

+4
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ def test_get_proc_like_prefix__proc(self):
477477
('iter foo() ref', 'iter '),
478478
('inline iter foo(x, y): int(32)', 'inline iter '),
479479
('proc proc proc proc proc proc', 'proc proc proc proc proc '),
480+
('attribute @foo', 'attribute '),
481+
('attribute @foo()', 'attribute '),
482+
('attribute @namespace.foo', 'attribute '),
483+
('attribute @namespace.foo()', 'attribute '),
480484
]
481485
for objtype in ('function', 'method'):
482486
obj = self.new_obj(objtype)

0 commit comments

Comments
 (0)