Skip to content

Commit 2b8c5cb

Browse files
committed
add missing docstring and remove some unnecessary comments
1 parent c834d5d commit 2b8c5cb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

loki/ir/pragma_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from loki.ir.find import FindNodes
1515
from loki.ir.transformer import Transformer
1616
from loki.ir.visitor import Visitor
17-
# from loki.expression.parser import parse_expr
1817
from loki.tools.util import as_tuple, replace_windowed
1918
from loki.logging import debug, warning
2019

@@ -51,13 +50,26 @@ def is_loki_pragma(pragma, starts_with=None):
5150

5251

5352
class PragmaParameters:
53+
"""
54+
Utility class to parse strings for parameters in the form ``<command>[(<arg>)]`` and
55+
return them as a map ``{<command>: <arg> or None}``.
56+
"""
5457

5558
_pattern_opening_parenthesis = re.compile(r'\(')
5659
_pattern_closing_parenthesis = re.compile(r'\)')
5760
_pattern_quoted_string = re.compile(r'(?:\'.*?\')|(?:".*?")')
5861

5962
@classmethod
6063
def find(cls, string):
64+
"""
65+
Find parameters in the form ``<command>[(<arg>)]`` and
66+
return them as a map ``{<command>: <arg> or None}``.
67+
68+
.. note::
69+
This allows nested parenthesis by matching pairs of
70+
parantheses starting at the end by pushing and popping
71+
from a stack.
72+
"""
6173
string = cls._pattern_quoted_string.sub('', string)
6274
p_open = [match.start() for match in cls._pattern_opening_parenthesis.finditer(string)]
6375
p_close = [match.start() for match in cls._pattern_closing_parenthesis.finditer(string)]
@@ -91,7 +103,7 @@ def _match_spans(open_, close_):
91103
spans += p_spans[::-1]
92104
parameters = defaultdict(list)
93105
if not spans and string.strip():
94-
for key in string.strip().split(' '): # keys[:-1]:
106+
for key in string.strip().split(' '):
95107
if key != '':
96108
parameters[key].append(None)
97109
for i, span in enumerate(spans):
@@ -134,7 +146,6 @@ def get_pragma_parameters(pragma, starts_with=None, only_loki_pragmas=True):
134146
pragma = as_tuple(pragma)
135147
parameters = defaultdict(list)
136148
for p in pragma:
137-
parameter = None
138149
if only_loki_pragmas and p.keyword.lower() != 'loki':
139150
continue
140151
content = p.content or ''

0 commit comments

Comments
 (0)