21
21
log = logging .getLogger (__name__ )
22
22
23
23
24
- def expand_name (line , char_poss ):
25
- """Get full word containing given cursor position"""
24
+ def expand_name (line : str , char_poss : int ) -> str :
25
+ """Get full word containing given cursor position
26
+
27
+ Parameters
28
+ ----------
29
+ line : str
30
+ Text line
31
+ char_poss : int
32
+ Column position along the line
33
+
34
+ Returns
35
+ -------
36
+ str
37
+ Word regex match for the input column
38
+ """
26
39
# The order here is important.
27
40
# WORD will capture substrings in logical and strings
28
41
regexs = [LOGICAL_REGEX , SQ_STRING_REGEX , DQ_STRING_REGEX , WORD_REGEX , NUMBER_REGEX ]
@@ -33,10 +46,21 @@ def expand_name(line, char_poss):
33
46
return ""
34
47
35
48
36
- def detect_fixed_format (file_lines ) :
49
+ def detect_fixed_format (file_lines : list [ str ]) -> bool :
37
50
"""Detect fixed/free format by looking for characters in label columns
38
51
and variable declarations before column 6. Treat intersection format
39
- files as free format."""
52
+ files as free format.
53
+
54
+ Parameters
55
+ ----------
56
+ file_lines : list[str]
57
+ List of consecutive file lines
58
+
59
+ Returns
60
+ -------
61
+ bool
62
+ True if file_lines are of Fixed Fortran style
63
+ """
40
64
for line in file_lines :
41
65
if FREE_FORMAT_TEST .match (line ):
42
66
return False
@@ -51,8 +75,20 @@ def detect_fixed_format(file_lines):
51
75
return True
52
76
53
77
54
- def strip_line_label (line ):
55
- """Strip leading numeric line label"""
78
+ def strip_line_label (line : str ) -> tuple [str , str | None ]:
79
+ """Strip leading numeric line label
80
+
81
+ Parameters
82
+ ----------
83
+ line : str
84
+ Text line
85
+
86
+ Returns
87
+ -------
88
+ tuple[str, str | None]
89
+ Output string, Line label returns None if no line label present
90
+ """
91
+
56
92
match = LINE_LABEL_REGEX .match (line )
57
93
if match is None :
58
94
return line , None
@@ -62,8 +98,21 @@ def strip_line_label(line):
62
98
return out_str , line_label
63
99
64
100
65
- def strip_strings (in_line , maintain_len = False ):
66
- """String string literals from code line"""
101
+ def strip_strings (in_line : str , maintain_len : bool = False ) -> str :
102
+ """Strips string literals from code line
103
+
104
+ Parameters
105
+ ----------
106
+ in_line : str
107
+ Text string
108
+ maintain_len : bool, optional
109
+ Maintain the len(in_line) in the output string, by default False
110
+
111
+ Returns
112
+ -------
113
+ str
114
+ Stripped string
115
+ """
67
116
68
117
def repl_sq (m ):
69
118
return "'{0}'" .format (" " * (len (m .group ()) - 2 ))
@@ -80,12 +129,22 @@ def repl_dq(m):
80
129
return out_line
81
130
82
131
83
- def separate_def_list (test_str ) :
132
+ def separate_def_list (test_str : str ) -> list [ str ] | None :
84
133
"""Separate definition lists, skipping parenthesis and bracket groups
85
134
86
135
Examples:
87
136
"var1, var2, var3" -> ["var1", "var2", "var3"]
88
137
"var, init_var(3) = [1,2,3], array(3,3)" -> ["var", "init_var", "array"]
138
+
139
+ Parameters
140
+ ----------
141
+ test_str : str
142
+ Text string
143
+
144
+ Returns
145
+ -------
146
+ list[str] | None
147
+ [description]
89
148
"""
90
149
stripped_str = strip_strings (test_str )
91
150
paren_count = 0
@@ -111,8 +170,21 @@ def separate_def_list(test_str):
111
170
return def_list
112
171
113
172
114
- def find_word_in_line (line , word ):
115
- """Find Fortran word in line"""
173
+ def find_word_in_line (line : str , word : str ) -> tuple [int , int ]:
174
+ """Find Fortran word in line
175
+
176
+ Parameters
177
+ ----------
178
+ line : str
179
+ Text line
180
+ word : str
181
+ word to find in line
182
+
183
+ Returns
184
+ -------
185
+ tuple[int, int]
186
+ start and end positions (indices) of the word if not found it returns
187
+ -1, len(word) -1"""
116
188
i0 = - 1
117
189
for poss_name in WORD_REGEX .finditer (line ):
118
190
if poss_name .group () == word :
@@ -121,9 +193,20 @@ def find_word_in_line(line, word):
121
193
return i0 , i0 + len (word )
122
194
123
195
124
- def find_paren_match (test_str ) :
196
+ def find_paren_match (test_str : str ) -> int :
125
197
"""Find matching closing parenthesis by searching forward,
126
- returns -1 if no match is found"""
198
+ returns -1 if no match is found
199
+
200
+ Parameters
201
+ ----------
202
+ test_str : str
203
+ Input string
204
+
205
+ Returns
206
+ -------
207
+ int
208
+ The index of the matching `)` character in the string
209
+ """
127
210
paren_count = 1
128
211
ind = - 1
129
212
for (i , char ) in enumerate (test_str ):
0 commit comments