Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for interfaces #95

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc-test/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Chapel classes

.. class:: ChplVector

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

.. attribute:: type eltType
Expand Down Expand Up @@ -102,6 +102,14 @@ Chapel classes
:returns: True if read was successful.


.. interface:: ChplInterface

Some text goes here

.. method:: proc Self.foo()

Some method that does something.

Python classes
--------------

Expand Down
5 changes: 5 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ For example, this would document a module with a ``proc`` and an ``iter``::

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


.. directive:: .. chpl:interface:: signature

Interfaces work the same as :rst:dir:`chpl:class`.

.. directive:: .. chpl:attribute:: signature

Describes an object data attribute. This can be a ``param``, ``const``,
Expand Down
9 changes: 7 additions & 2 deletions sphinxcontrib/chapeldomain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
# regex for parsing proc, iter, class, record, etc.
chpl_sig_pattern = re.compile(
r"""^ ((?:\w+\s+)* # opt: prefixes
(?:proc|iter|class|record|operator)\s+ # must end with keyword
(?:
proc|iter|class|record|interface|operator # must end with keyword
)\s+
(?:type\s+|param\s+|ref\s+)? # opt: 'this' intent
# (type, param, ref)
)?
Expand Down Expand Up @@ -570,7 +572,7 @@ def get_signature_prefix(self, sig):

def get_index_text(self, modname, name_cls):
"""Return index entry text based on object type."""
if self.objtype in ('class', 'record', 'enum'):
if self.objtype in ('class', 'record', 'interface', 'enum'):
if not modname:
return _('%s (built-in %s)') % (name_cls[0], self.objtype)
return _('%s (%s in %s)') % (name_cls[0], self.objtype, modname)
Expand Down Expand Up @@ -806,6 +808,7 @@ class ChapelDomain(Domain):
'enumconstant': ObjType(_('enumconstant'), 'enumconstant'),
'class': ObjType(_('class'), 'class'),
'record': ObjType(_('record'), 'record'),
'interface': ObjType(_('interface'), 'interface'),
'method': ObjType(_('method'), 'meth', 'proc'),
'itermethod': ObjType(_('itermethod'), 'meth', 'iter'),
'attribute': ObjType(_('attribute'), 'attr'),
Expand All @@ -823,6 +826,7 @@ class ChapelDomain(Domain):

'class': ChapelClassObject,
'record': ChapelClassObject,
'interface': ChapelClassObject,
'enum': ChapelClassObject,
'enumconstant': ChapelClassMember,
'method': ChapelClassMember,
Expand All @@ -844,6 +848,7 @@ class ChapelDomain(Domain):
'iter': ChapelXRefRole(),
'class': ChapelXRefRole(),
'record': ChapelXRefRole(),
'interface': ChapelXRefRole(),
'enum': ChapelXRefRole(),
'enumconstant': ChapelXRefRole(),
'meth': ChapelXRefRole(),
Expand Down
5 changes: 4 additions & 1 deletion test/test_chapeldomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def test_is_attr_like__false(self):
'itermethod',
'class',
'record',
'interface',
'module',
'random',
'opmethod',
Expand Down Expand Up @@ -407,6 +408,7 @@ def test_is_proc_like__false(self):
'type',
'class',
'record',
'interface',
'module',
'random',
'enum',
Expand Down Expand Up @@ -799,7 +801,7 @@ def test_with_where_clause(self):
def test_with_all(self):
"""Verify fully specified signatures parse correctly."""
test_cases = [
('proc foo where a > b', 'proc ', None, 'foo', None, None, ' where a > b'),
('proc foo where a > b', 'proc ', None, 'foo', None, None, ' where a > b'),
('proc foo() where a > b', 'proc ', None, 'foo', '', None, ' where a > b'),
('proc foo:int where a > b', 'proc ', None, 'foo', None, ':int', ' where a > b'),
('proc foo():int where a > b', 'proc ', None, 'foo', '', ':int', ' where a > b'),
Expand Down Expand Up @@ -829,6 +831,7 @@ def test_with_all(self):
('record R', 'record ', None, 'R', None, None, None),
('record MyRec:SuRec', 'record ', None, 'MyRec', None, ':SuRec', None),
('record N.R : X, Y, Z', 'record ', 'N.', 'R', None, ': X, Y, Z', None),
('interface I', 'interface ', None, 'I', None, None, None),
('proc rcRemote(replicatedVar: [?D] ?MYTYPE, remoteLoc: locale) ref: MYTYPE',
'proc ', None, 'rcRemote', 'replicatedVar: [?D] ?MYTYPE, remoteLoc: locale', ' ref: MYTYPE', None),
('proc rcLocal(replicatedVar: [?D] ?MYTYPE) ref: MYTYPE',
Expand Down
Loading