Skip to content

Commit

Permalink
Merge pull request #351 from emanspeaks/dollar-symbol-names
Browse files Browse the repository at this point in the history
Allow dollar in symbol names
  • Loading branch information
gnikit authored Jan 24, 2024
2 parents 8466034 + 7a31879 commit 2f84c3a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2045,9 +2045,9 @@ def replace_defined(line: str):
out_line = ""
for match in FRegex.DEFINED.finditer(line):
if match.group(1) in defs:
out_line += line[i0 : match.start(0)] + "($@)"
out_line += line[i0 : match.start(0)] + "(@$@)"
else:
out_line += line[i0 : match.start(0)] + "($%)"
out_line += line[i0 : match.start(0)] + "(%$%)"
i0 = match.end(0)
if i0 < len(line):
out_line += line[i0:]
Expand All @@ -2064,8 +2064,8 @@ def replace_vars(line: str):
i0 = match.end(0)
if i0 < len(line):
out_line += line[i0:]
out_line = out_line.replace("$@", "True")
out_line = out_line.replace("$%", "False")
out_line = out_line.replace("@$@", "True")
out_line = out_line.replace("%$%", "False")
return out_line

if defs is None:
Expand Down
4 changes: 2 additions & 2 deletions fortls/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class FortranRegularExpressions:
r"[ ]*,[ ]*(PUBLIC|PRIVATE|ABSTRACT|EXTENDS\(\w*\))", I
)
VIS: Pattern = compile(r"[ ]*\b(PUBLIC|PRIVATE)\b", I)
WORD: Pattern = compile(r"[a-z_]\w*", I)
WORD: Pattern = compile(r"[a-z_][\w\$]*", I)
NUMBER: Pattern = compile(
r"[\+\-]?(\b\d+\.?\d*|\.\d+)(_\w+|d[\+\-]?\d+|e[\+\-]?\d+(_\w+)?)?(?!\w)",
I,
Expand Down Expand Up @@ -146,7 +146,7 @@ class FortranRegularExpressions:
# Object regex patterns
CLASS_VAR: Pattern = compile(r"(TYPE|CLASS)[ ]*\(", I)
DEF_KIND: Pattern = compile(r"(\w*)[ ]*\((?:KIND|LEN)?[ =]*(\w*)", I)
OBJBREAK: Pattern = compile(r"[\/\-(.,+*<>=$: ]", I)
OBJBREAK: Pattern = compile(r"[\/\-(.,+*<>=: ]", I)


# TODO: use this in the main code
Expand Down
11 changes: 11 additions & 0 deletions test/test_server_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def test_hover_parameter():
validate_hover(results, ref_results)


def test_hover_parameter_dollar():
"""Test that hover parameters with dollar in name are recognized correctly"""
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
file_path = test_dir / "hover" / "parameters.f90"
string += hover_req(file_path, 20, 31)
errcode, results = run_request(string, fortls_args=["--sort_keywords"])
assert errcode == 0
ref_results = ["```fortran90\nINTEGER(4), PARAMETER :: SIG$ERR = -1\n```"]
validate_hover(results, ref_results)


def test_hover_parameter_eqnospace():
"""Test that hover parameters display value correctly"""
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
Expand Down
1 change: 1 addition & 0 deletions test/test_source/hover/parameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ program params
INTEGER, PARAMETER :: var_multi2 = 1 * &
23 + &
2 /1 ! comment
INTEGER(4), PARAMETER :: SIG$ERR = -1
end program params

0 comments on commit 2f84c3a

Please sign in to comment.