Skip to content

Commit c31b1b0

Browse files
authored
Merge pull request #256 from fortran-lang/gnikit/issue255
bug: fixes `CRITICAL` "Unexpected end of scope"
2 parents 5b004fd + 1d9bb46 commit c31b1b0

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
### Fixed
2828

29+
- Fixed end of scope for `CRITICAL` keyword blocks
30+
([#255](https://github.com/fortran-lang/fortls/issues/255))
2931
- Fixed bug where completion of interfaces in USE ONLY would produce the snippet
3032
([#150](https://github.com/fortran-lang/fortls/issues/150))
3133
- Fixed bug where diagnostic messages were raised for non-existent variables

fortls/regex_patterns.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class FortranRegularExpressions:
4040
SUBMOD: Pattern = compile(r"[ ]*SUBMODULE[ ]*\(", I)
4141
END_SMOD: Pattern = compile(r"SUBMODULE", I)
4242
END_PRO: Pattern = compile(r"(MODULE)?[ ]*PROCEDURE", I)
43-
BLOCK: Pattern = compile(r"[ ]*([a-z_]\w*[ ]*:[ ]*)?BLOCK(?!\w)", I)
44-
END_BLOCK: Pattern = compile(r"BLOCK", I)
43+
BLOCK: Pattern = compile(r"[ ]*([a-z_]\w*[ ]*:[ ]*)?BLOCK|CRITICAL(?!\w)", I)
44+
END_BLOCK: Pattern = compile(r"BLOCK|CRITICAL", I)
4545
DO: Pattern = compile(r"[ ]*(?:[a-z_]\w*[ ]*:[ ]*)?DO([ ]+[0-9]*|$)", I)
4646
END_DO: Pattern = compile(r"DO", I)
4747
WHERE: Pattern = compile(r"[ ]*WHERE[ ]*\(", I)
@@ -64,7 +64,7 @@ class FortranRegularExpressions:
6464
INT: Pattern = compile(r"[ ]*(ABSTRACT)?[ ]*INTERFACE[ ]*(\w*)", I)
6565
END_INT: Pattern = compile(r"INTERFACE", I)
6666
END_WORD: Pattern = compile(
67-
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|ASSOCIATE|SELECT"
67+
r"[ ]*END[ ]*(DO|WHERE|IF|BLOCK|CRITICAL|ASSOCIATE|SELECT"
6868
r"|TYPE|ENUM|MODULE|SUBMODULE|PROGRAM|INTERFACE"
6969
r"|SUBROUTINE|FUNCTION|PROCEDURE|FORALL)?([ ]+(?!\W)|$)",
7070
I,

test/test_server_diagnostics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,15 @@ def test_attribute_and_variable_name_collision():
428428
errcode, results = run_request(string, ["-n", "1"])
429429
assert errcode == 0
430430
assert results[1]["diagnostics"] == []
431+
432+
433+
def test_critical_scope():
434+
"""Test that critical scopes are correctly parsed."""
435+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir / "diag")})
436+
file_path = str(test_dir / "diag" / "tst_critical.f90")
437+
string += write_rpc_notification(
438+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
439+
)
440+
errcode, results = run_request(string, ["-n", "1"])
441+
assert errcode == 0
442+
assert results[1]["diagnostics"] == []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
program test_critical
2+
implicit none
3+
if (.true.) then
4+
critical
5+
end critical
6+
end if
7+
end program test_critical

0 commit comments

Comments
 (0)