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 attribute support (via 'annotation' directive) #97

Merged
merged 2 commits into from
Sep 5, 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: 8 additions & 2 deletions sphinxcontrib/chapeldomain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
chpl_sig_pattern = re.compile(
r"""^ ((?:\w+\s+)* # opt: prefixes
(?:
proc|iter|class|record|interface|operator # must end with keyword
proc|iter|class|record|
interface|operator|attribute # must end with keyword
)\s+
(?:type\s+|param\s+|ref\s+)? # opt: 'this' intent
# (type, param, ref)
Expand All @@ -51,6 +52,7 @@
\s*?
(
(?:[\w$][\w$=]*)| # function or method name
(?:@[\w$][\w$=\.]*)| # or @attribute name
(?:[+*/!~%<>=&^|\-:]+) # or operator name
) \s*
(?:\((.*?)\))? # opt: arguments
Expand Down Expand Up @@ -277,7 +279,8 @@ def _is_proc_like(self):
return (self.objtype in
('function', 'iterfunction',
'method', 'itermethod',
'opfunction', 'opmethod'))
'opfunction', 'opmethod',
'annotation'))

def _get_sig_prefix(self, sig):
"""Return signature prefix text. For attribute, data, and proc/iter
Expand Down Expand Up @@ -815,6 +818,7 @@ class ChapelDomain(Domain):
'module': ObjType(_('module'), 'mod'),
'opmethod': ObjType(_('opmethod'), 'op'),
'opfunction': ObjType(_('opfunction'), 'op'),
'annotation': ObjType(_('annotation'), 'annotation'),
}

directives = {
Expand All @@ -823,6 +827,7 @@ class ChapelDomain(Domain):
'function': ChapelModuleLevel,
'iterfunction': ChapelModuleLevel,
'opfunction': ChapelModuleLevel,
'annotation': ChapelModuleLevel,

'class': ChapelClassObject,
'record': ChapelClassObject,
Expand All @@ -838,6 +843,7 @@ class ChapelDomain(Domain):
}

roles = {
'annotation': ChapelXRefRole(),
'data': ChapelXRefRole(),
'const': ChapelXRefRole(),
'var': ChapelXRefRole(),
Expand Down
4 changes: 4 additions & 0 deletions test/test_chapeldomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ def test_get_proc_like_prefix__proc(self):
('iter foo() ref', 'iter '),
('inline iter foo(x, y): int(32)', 'inline iter '),
('proc proc proc proc proc proc', 'proc proc proc proc proc '),
('attribute @foo', 'attribute '),
('attribute @foo()', 'attribute '),
('attribute @namespace.foo', 'attribute '),
('attribute @namespace.foo()', 'attribute '),
]
for objtype in ('function', 'method'):
obj = self.new_obj(objtype)
Expand Down
Loading