Skip to content

Commit 0ecfac6

Browse files
committed
Move and organise the code
1 parent ac81470 commit 0ecfac6

File tree

5 files changed

+86
-60
lines changed

5 files changed

+86
-60
lines changed

fortls/constants.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@
22

33
PY3K = sys.version_info >= (3, 0)
44

5+
# Keyword identifiers
6+
KEYWORD_LIST = [
7+
"pointer",
8+
"allocatable",
9+
"optional",
10+
"public",
11+
"private",
12+
"nopass",
13+
"target",
14+
"save",
15+
"parameter",
16+
"contiguous",
17+
"deferred",
18+
"dimension",
19+
"intent",
20+
"pass",
21+
"pure",
22+
"impure",
23+
"elemental",
24+
"recursive",
25+
"abstract",
26+
]
27+
KEYWORD_ID_DICT = {keyword: ind for (ind, keyword) in enumerate(KEYWORD_LIST)}
28+
29+
# Type identifiers
30+
BASE_TYPE_ID = -1
31+
MODULE_TYPE_ID = 1
32+
SUBROUTINE_TYPE_ID = 2
33+
FUNCTION_TYPE_ID = 3
34+
CLASS_TYPE_ID = 4
35+
INTERFACE_TYPE_ID = 5
36+
VAR_TYPE_ID = 6
37+
METH_TYPE_ID = 7
38+
SUBMODULE_TYPE_ID = 8
39+
BLOCK_TYPE_ID = 9
40+
SELECT_TYPE_ID = 10
41+
DO_TYPE_ID = 11
42+
WHERE_TYPE_ID = 12
43+
IF_TYPE_ID = 13
44+
ASSOC_TYPE_ID = 14
45+
ENUM_TYPE_ID = 15
46+
547
# A string used to mark literals e.g. 10, 3.14, "words", etc.
648
# The description name chosen is non-ambiguous and cannot naturally
749
# occur in Fortran (with/out C preproc) code

fortls/langserver.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
from pathlib import Path
1313

1414
# Local modules
15-
from fortls.constants import FORTRAN_LITERAL
16-
from fortls.helper_functions import expand_name
17-
from fortls.intrinsics import (
18-
get_intrinsic_keywords,
19-
load_intrinsics,
20-
set_lowercase_intrinsics,
21-
)
22-
from fortls.jsonrpc import path_from_uri, path_to_uri
23-
from fortls.objects import (
15+
from fortls.constants import (
2416
CLASS_TYPE_ID,
17+
FORTRAN_LITERAL,
2518
FUNCTION_TYPE_ID,
2619
INTERFACE_TYPE_ID,
2720
METH_TYPE_ID,
2821
MODULE_TYPE_ID,
2922
SELECT_TYPE_ID,
3023
SUBROUTINE_TYPE_ID,
3124
VAR_TYPE_ID,
25+
)
26+
from fortls.helper_functions import expand_name
27+
from fortls.intrinsics import (
28+
get_intrinsic_keywords,
29+
load_intrinsics,
30+
set_lowercase_intrinsics,
31+
)
32+
from fortls.jsonrpc import path_from_uri, path_to_uri
33+
from fortls.objects import (
3234
climb_type_tree,
3335
find_in_scope,
3436
find_in_workspace,
@@ -42,6 +44,7 @@
4244
from fortls.parse_fortran import fortran_file, get_line_context, process_file
4345
from fortls.regex_patterns import (
4446
DQ_STRING_REGEX,
47+
INT_STMNT_REGEX,
4548
LOGICAL_REGEX,
4649
NUMBER_REGEX,
4750
SQ_STRING_REGEX,
@@ -50,8 +53,6 @@
5053
log = logging.getLogger(__name__)
5154
# Global regexes
5255
FORTRAN_EXT_REGEX = re.compile(r"\.F(77|90|95|03|08|OR|PP)?$", re.I)
53-
# TODO: I think this can be replaced by fortls.regex_patterns
54-
INT_STMNT_REGEX = re.compile(r"^[ ]*[a-z]*$", re.I)
5556
# TODO: I think this can be replaced by fortls.regex_patterns type & class
5657
TYPE_DEF_REGEX = re.compile(r"[ ]*(TYPE|CLASS)[ ]*\([a-z0-9_ ]*$", re.I)
5758
# TODO: I think this can be replaced by fortls.regex_patterns

fortls/objects.py

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,33 @@
33
import re
44
from collections import namedtuple
55

6+
from fortls.constants import (
7+
ASSOC_TYPE_ID,
8+
BASE_TYPE_ID,
9+
BLOCK_TYPE_ID,
10+
CLASS_TYPE_ID,
11+
DO_TYPE_ID,
12+
ENUM_TYPE_ID,
13+
FUNCTION_TYPE_ID,
14+
IF_TYPE_ID,
15+
INTERFACE_TYPE_ID,
16+
KEYWORD_ID_DICT,
17+
KEYWORD_LIST,
18+
METH_TYPE_ID,
19+
MODULE_TYPE_ID,
20+
SELECT_TYPE_ID,
21+
SUBMODULE_TYPE_ID,
22+
SUBROUTINE_TYPE_ID,
23+
VAR_TYPE_ID,
24+
WHERE_TYPE_ID,
25+
)
626
from fortls.jsonrpc import path_to_uri
27+
from fortls.regex_patterns import CLASS_VAR_REGEX, DEF_KIND_REGEX, OBJBREAK_REGEX
728

829
# Global variables
930
sort_keywords = True
10-
# Regexes
11-
CLASS_VAR_REGEX = re.compile(r"(TYPE|CLASS)[ ]*\(", re.I)
12-
DEF_KIND_REGEX = re.compile(r"([a-z]*)[ ]*\((?:KIND|LEN)?[ =]*([a-z_][a-z0-9_]*)", re.I)
13-
OBJBREAK_REGEX = re.compile(r"[\/\-(.,+*<>=$: ]", re.I)
1431
# Helper types
1532
USE_info = namedtuple("USE_info", ["only_list", "rename_map"])
16-
# Keyword identifiers
17-
KEYWORD_LIST = [
18-
"pointer",
19-
"allocatable",
20-
"optional",
21-
"public",
22-
"private",
23-
"nopass",
24-
"target",
25-
"save",
26-
"parameter",
27-
"contiguous",
28-
"deferred",
29-
"dimension",
30-
"intent",
31-
"pass",
32-
"pure",
33-
"impure",
34-
"elemental",
35-
"recursive",
36-
"abstract",
37-
]
38-
KEYWORD_ID_DICT = {keyword: ind for (ind, keyword) in enumerate(KEYWORD_LIST)}
39-
# Type identifiers
40-
BASE_TYPE_ID = -1
41-
MODULE_TYPE_ID = 1
42-
SUBROUTINE_TYPE_ID = 2
43-
FUNCTION_TYPE_ID = 3
44-
CLASS_TYPE_ID = 4
45-
INTERFACE_TYPE_ID = 5
46-
VAR_TYPE_ID = 6
47-
METH_TYPE_ID = 7
48-
SUBMODULE_TYPE_ID = 8
49-
BLOCK_TYPE_ID = 9
50-
SELECT_TYPE_ID = 10
51-
DO_TYPE_ID = 11
52-
WHERE_TYPE_ID = 12
53-
IF_TYPE_ID = 13
54-
ASSOC_TYPE_ID = 14
55-
ENUM_TYPE_ID = 15
5633

5734

5835
def set_keyword_ordering(sorted):

fortls/parse_fortran.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
import sys
88
from collections import namedtuple
99

10-
from fortls.constants import PY3K
10+
from fortls.constants import (
11+
DO_TYPE_ID,
12+
INTERFACE_TYPE_ID,
13+
PY3K,
14+
SELECT_TYPE_ID,
15+
SUBMODULE_TYPE_ID,
16+
)
1117
from fortls.helper_functions import (
1218
detect_fixed_format,
1319
find_paren_match,
@@ -17,10 +23,6 @@
1723
strip_strings,
1824
)
1925
from fortls.objects import (
20-
DO_TYPE_ID,
21-
INTERFACE_TYPE_ID,
22-
SELECT_TYPE_ID,
23-
SUBMODULE_TYPE_ID,
2426
fortran_associate,
2527
fortran_ast,
2628
fortran_block,

fortls/regex_patterns.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@
120120
r"[ ]*(END)( |MODULE|PROGRAM|SUBROUTINE|FUNCTION|PROCEDURE|TYPE|DO|IF|SELECT)?",
121121
re.I,
122122
)
123+
# Object regex patterns
124+
CLASS_VAR_REGEX = re.compile(r"(TYPE|CLASS)[ ]*\(", re.I)
125+
DEF_KIND_REGEX = re.compile(r"([a-z]*)[ ]*\((?:KIND|LEN)?[ =]*([a-z_]\w*)", re.I)
126+
OBJBREAK_REGEX = re.compile(r"[\/\-(.,+*<>=$: ]", re.I)

0 commit comments

Comments
 (0)