Skip to content

Commit 5a2bc62

Browse files
authored
Add support for interfaces (#95)
Adds support for `interface`, which will be outputed by chpldoc after chapel-lang/chapel#25825 [Reviewed by @lydia-duncan]
2 parents 7412e59 + 555fd94 commit 5a2bc62

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

Diff for: doc-test/classes.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Chapel classes
1313

1414
.. class:: ChplVector
1515

16-
See also :chpl:record:`ChplBigNum`. The :chpl:iter:`these` iterator can be
16+
See also :chpl:record:`ChplBigNum` and :chpl:interface:`ChplInterface`. The :chpl:iter:`these` iterator can be
1717
used to iterate over the elements of the vector.
1818

1919
.. attribute:: type eltType
@@ -102,6 +102,14 @@ Chapel classes
102102
:returns: True if read was successful.
103103

104104

105+
.. interface:: ChplInterface
106+
107+
Some text goes here
108+
109+
.. method:: proc Self.foo()
110+
111+
Some method that does something.
112+
105113
Python classes
106114
--------------
107115

Diff for: docs/reference.rst

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ For example, this would document a module with a ``proc`` and an ``iter``::
157157

158158
Records work the same as :rst:dir:`chpl:class`.
159159

160+
161+
.. directive:: .. chpl:interface:: signature
162+
163+
Interfaces work the same as :rst:dir:`chpl:class`.
164+
160165
.. directive:: .. chpl:attribute:: signature
161166

162167
Describes an object data attribute. This can be a ``param``, ``const``,

Diff for: sphinxcontrib/chapeldomain/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
# regex for parsing proc, iter, class, record, etc.
4242
chpl_sig_pattern = re.compile(
4343
r"""^ ((?:\w+\s+)* # opt: prefixes
44-
(?:proc|iter|class|record|operator)\s+ # must end with keyword
44+
(?:
45+
proc|iter|class|record|interface|operator # must end with keyword
46+
)\s+
4547
(?:type\s+|param\s+|ref\s+)? # opt: 'this' intent
4648
# (type, param, ref)
4749
)?
@@ -570,7 +572,7 @@ def get_signature_prefix(self, sig):
570572

571573
def get_index_text(self, modname, name_cls):
572574
"""Return index entry text based on object type."""
573-
if self.objtype in ('class', 'record', 'enum'):
575+
if self.objtype in ('class', 'record', 'interface', 'enum'):
574576
if not modname:
575577
return _('%s (built-in %s)') % (name_cls[0], self.objtype)
576578
return _('%s (%s in %s)') % (name_cls[0], self.objtype, modname)
@@ -806,6 +808,7 @@ class ChapelDomain(Domain):
806808
'enumconstant': ObjType(_('enumconstant'), 'enumconstant'),
807809
'class': ObjType(_('class'), 'class'),
808810
'record': ObjType(_('record'), 'record'),
811+
'interface': ObjType(_('interface'), 'interface'),
809812
'method': ObjType(_('method'), 'meth', 'proc'),
810813
'itermethod': ObjType(_('itermethod'), 'meth', 'iter'),
811814
'attribute': ObjType(_('attribute'), 'attr'),
@@ -823,6 +826,7 @@ class ChapelDomain(Domain):
823826

824827
'class': ChapelClassObject,
825828
'record': ChapelClassObject,
829+
'interface': ChapelClassObject,
826830
'enum': ChapelClassObject,
827831
'enumconstant': ChapelClassMember,
828832
'method': ChapelClassMember,
@@ -844,6 +848,7 @@ class ChapelDomain(Domain):
844848
'iter': ChapelXRefRole(),
845849
'class': ChapelXRefRole(),
846850
'record': ChapelXRefRole(),
851+
'interface': ChapelXRefRole(),
847852
'enum': ChapelXRefRole(),
848853
'enumconstant': ChapelXRefRole(),
849854
'meth': ChapelXRefRole(),

Diff for: test/test_chapeldomain.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def test_is_attr_like__false(self):
377377
'itermethod',
378378
'class',
379379
'record',
380+
'interface',
380381
'module',
381382
'random',
382383
'opmethod',
@@ -407,6 +408,7 @@ def test_is_proc_like__false(self):
407408
'type',
408409
'class',
409410
'record',
411+
'interface',
410412
'module',
411413
'random',
412414
'enum',
@@ -799,7 +801,7 @@ def test_with_where_clause(self):
799801
def test_with_all(self):
800802
"""Verify fully specified signatures parse correctly."""
801803
test_cases = [
802-
('proc foo where a > b', 'proc ', None, 'foo', None, None, ' where a > b'),
804+
('proc foo where a > b', 'proc ', None, 'foo', None, None, ' where a > b'),
803805
('proc foo() where a > b', 'proc ', None, 'foo', '', None, ' where a > b'),
804806
('proc foo:int where a > b', 'proc ', None, 'foo', None, ':int', ' where a > b'),
805807
('proc foo():int where a > b', 'proc ', None, 'foo', '', ':int', ' where a > b'),
@@ -829,6 +831,7 @@ def test_with_all(self):
829831
('record R', 'record ', None, 'R', None, None, None),
830832
('record MyRec:SuRec', 'record ', None, 'MyRec', None, ':SuRec', None),
831833
('record N.R : X, Y, Z', 'record ', 'N.', 'R', None, ': X, Y, Z', None),
834+
('interface I', 'interface ', None, 'I', None, None, None),
832835
('proc rcRemote(replicatedVar: [?D] ?MYTYPE, remoteLoc: locale) ref: MYTYPE',
833836
'proc ', None, 'rcRemote', 'replicatedVar: [?D] ?MYTYPE, remoteLoc: locale', ' ref: MYTYPE', None),
834837
('proc rcLocal(replicatedVar: [?D] ?MYTYPE) ref: MYTYPE',

0 commit comments

Comments
 (0)