3
3
import os
4
4
from pathlib import Path
5
5
6
- from fortls .constants import KEYWORD_ID_DICT , KEYWORD_LIST , log , sort_keywords
7
- from fortls .regex_patterns import (
8
- DQ_STRING_REGEX ,
9
- FIXED_COMMENT_LINE_MATCH ,
10
- FREE_FORMAT_TEST ,
11
- LINE_LABEL_REGEX ,
12
- LOGICAL_REGEX ,
13
- NAT_VAR_REGEX ,
14
- NUMBER_REGEX ,
15
- OBJBREAK_REGEX ,
16
- SQ_STRING_REGEX ,
17
- WORD_REGEX ,
18
- )
6
+ from fortls .constants import KEYWORD_ID_DICT , KEYWORD_LIST , FRegex , log , sort_keywords
19
7
20
8
21
9
def expand_name (line : str , char_poss : int ) -> str :
@@ -35,7 +23,13 @@ def expand_name(line: str, char_poss: int) -> str:
35
23
"""
36
24
# The order here is important.
37
25
# WORD will capture substrings in logical and strings
38
- regexs = [LOGICAL_REGEX , SQ_STRING_REGEX , DQ_STRING_REGEX , WORD_REGEX , NUMBER_REGEX ]
26
+ regexs = [
27
+ FRegex .LOGICAL ,
28
+ FRegex .SQ_STRING ,
29
+ FRegex .DQ_STRING ,
30
+ FRegex .WORD ,
31
+ FRegex .NUMBER ,
32
+ ]
39
33
for r in regexs :
40
34
for num_match in r .finditer (line ):
41
35
if num_match .start (0 ) <= char_poss <= num_match .end (0 ):
@@ -59,13 +53,13 @@ def detect_fixed_format(file_lines: list[str]) -> bool:
59
53
True if file_lines are of Fixed Fortran style
60
54
"""
61
55
for line in file_lines :
62
- if FREE_FORMAT_TEST .match (line ):
56
+ if FRegex . FREE_FORMAT_TEST .match (line ):
63
57
return False
64
- tmp_match = NAT_VAR_REGEX .match (line )
58
+ tmp_match = FRegex . VAR .match (line )
65
59
if tmp_match and tmp_match .start (1 ) < 6 :
66
60
return False
67
61
# Trailing ampersand indicates free or intersection format
68
- if not FIXED_COMMENT_LINE_MATCH .match (line ):
62
+ if not FRegex . FIXED_COMMENT .match (line ):
69
63
line_end = line .split ("!" )[0 ].strip ()
70
64
if len (line_end ) > 0 and line_end [- 1 ] == "&" :
71
65
return False
@@ -86,7 +80,7 @@ def strip_line_label(line: str) -> tuple[str, str | None]:
86
80
Output string, Line label returns None if no line label present
87
81
"""
88
82
89
- match = LINE_LABEL_REGEX .match (line )
83
+ match = FRegex . LINE_LABEL .match (line )
90
84
if match is None :
91
85
return line , None
92
86
else :
@@ -118,11 +112,11 @@ def repl_dq(m):
118
112
return '"{0}"' .format (" " * (len (m .group ()) - 2 ))
119
113
120
114
if maintain_len :
121
- out_line = SQ_STRING_REGEX .sub (repl_sq , in_line )
122
- out_line = DQ_STRING_REGEX .sub (repl_dq , out_line )
115
+ out_line = FRegex . SQ_STRING .sub (repl_sq , in_line )
116
+ out_line = FRegex . DQ_STRING .sub (repl_dq , out_line )
123
117
else :
124
- out_line = SQ_STRING_REGEX .sub ("" , in_line )
125
- out_line = DQ_STRING_REGEX .sub ("" , out_line )
118
+ out_line = FRegex . SQ_STRING .sub ("" , in_line )
119
+ out_line = FRegex . DQ_STRING .sub ("" , out_line )
126
120
return out_line
127
121
128
122
@@ -183,7 +177,7 @@ def find_word_in_line(line: str, word: str) -> tuple[int, int]:
183
177
start and end positions (indices) of the word if not found it returns
184
178
-1, len(word) -1"""
185
179
i0 = - 1
186
- for poss_name in WORD_REGEX .finditer (line ):
180
+ for poss_name in FRegex . WORD .finditer (line ):
187
181
if poss_name .group () == word :
188
182
i0 = poss_name .start ()
189
183
break
@@ -417,7 +411,7 @@ def get_var_stack(line):
417
411
final_var += line [section [0 ] : section [1 ]]
418
412
#
419
413
if final_var is not None :
420
- final_op_split = OBJBREAK_REGEX .split (final_var )
414
+ final_op_split = FRegex . OBJBREAK .split (final_var )
421
415
return final_op_split [- 1 ].split ("%" )
422
416
else :
423
417
return None
0 commit comments