Skip to content

Commit 2f84c3a

Browse files
authored
Merge pull request #351 from emanspeaks/dollar-symbol-names
Allow dollar in symbol names
2 parents 8466034 + 7a31879 commit 2f84c3a

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

fortls/parsers/internal/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,9 +2045,9 @@ def replace_defined(line: str):
20452045
out_line = ""
20462046
for match in FRegex.DEFINED.finditer(line):
20472047
if match.group(1) in defs:
2048-
out_line += line[i0 : match.start(0)] + "($@)"
2048+
out_line += line[i0 : match.start(0)] + "(@$@)"
20492049
else:
2050-
out_line += line[i0 : match.start(0)] + "($%)"
2050+
out_line += line[i0 : match.start(0)] + "(%$%)"
20512051
i0 = match.end(0)
20522052
if i0 < len(line):
20532053
out_line += line[i0:]
@@ -2064,8 +2064,8 @@ def replace_vars(line: str):
20642064
i0 = match.end(0)
20652065
if i0 < len(line):
20662066
out_line += line[i0:]
2067-
out_line = out_line.replace("$@", "True")
2068-
out_line = out_line.replace("$%", "False")
2067+
out_line = out_line.replace("@$@", "True")
2068+
out_line = out_line.replace("%$%", "False")
20692069
return out_line
20702070

20712071
if defs is None:

fortls/regex_patterns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class FortranRegularExpressions:
9898
r"[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\(\w*\))", I
9999
)
100100
VIS: Pattern = compile(r"[ ]*\b(PUBLIC|PRIVATE)\b", I)
101-
WORD: Pattern = compile(r"[a-z_]\w*", I)
101+
WORD: Pattern = compile(r"[a-z_][\w\$]*", I)
102102
NUMBER: Pattern = compile(
103103
r"[\+\-]?(\b\d+\.?\d*|\.\d+)(_\w+|d[\+\-]?\d+|e[\+\-]?\d+(_\w+)?)?(?!\w)",
104104
I,
@@ -146,7 +146,7 @@ class FortranRegularExpressions:
146146
# Object regex patterns
147147
CLASS_VAR: Pattern = compile(r"(TYPE|CLASS)[ ]*\(", I)
148148
DEF_KIND: Pattern = compile(r"(\w*)[ ]*\((?:KIND|LEN)?[ =]*(\w*)", I)
149-
OBJBREAK: Pattern = compile(r"[\/\-(.,+*<>=$: ]", I)
149+
OBJBREAK: Pattern = compile(r"[\/\-(.,+*<>=: ]", I)
150150

151151

152152
# TODO: use this in the main code

test/test_server_hover.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ def test_hover_parameter():
7070
validate_hover(results, ref_results)
7171

7272

73+
def test_hover_parameter_dollar():
74+
"""Test that hover parameters with dollar in name are recognized correctly"""
75+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
76+
file_path = test_dir / "hover" / "parameters.f90"
77+
string += hover_req(file_path, 20, 31)
78+
errcode, results = run_request(string, fortls_args=["--sort_keywords"])
79+
assert errcode == 0
80+
ref_results = ["```fortran90\nINTEGER(4), PARAMETER :: SIG$ERR = -1\n```"]
81+
validate_hover(results, ref_results)
82+
83+
7384
def test_hover_parameter_eqnospace():
7485
"""Test that hover parameters display value correctly"""
7586
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})

test/test_source/hover/parameters.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ program params
1818
INTEGER, PARAMETER :: var_multi2 = 1 * &
1919
23 + &
2020
2 /1 ! comment
21+
INTEGER(4), PARAMETER :: SIG$ERR = -1
2122
end program params

0 commit comments

Comments
 (0)