Skip to content

Commit

Permalink
fix(parser): trailing semicolons triggering end of scope diagnostics
Browse files Browse the repository at this point in the history
Fixes #265
  • Loading branch information
gnikit committed May 10, 2024
1 parent bf1a0bc commit dece46a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

### Fixed

- Fixed end of scope errors raised by trailing semicolon in native parser
([#265](https://github.com/fortran-lang/fortls/issues/265))
- Fixed bug where parent scope for includes in AST could be `None`
([#329](https://github.com/fortran-lang/fortls/issues/329))
- Fixed preprocessor bug with `if` and `elif` conditionals
Expand Down
1 change: 1 addition & 0 deletions fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ def parse(
multi_lines.extendleft(line_stripped.split(";"))
line = multi_lines.pop()
line_stripped = line
line_no_comment = line
# Test for scope end
if file_ast.end_scope_regex is not None:
match = FRegex.END_WORD.match(line_no_comment)
Expand Down
9 changes: 9 additions & 0 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ def test_private_visibility_interfaces():
err_str, _ = file.load_from_disk()
file.parse()
assert err_str is None


def test_end_scopes_semicolon():
file_path = test_dir / "parse" / "trailing_semicolon.f90"
file = FortranFile(str(file_path))
err_str, _ = file.load_from_disk()
ast = file.parse()
assert err_str is None
assert not ast.end_errors
6 changes: 6 additions & 0 deletions test/test_source/parse/trailing_semicolon.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program trailing_semicolon_in_end_scope
integer :: i
do i=1, 3
print *, "Hello World!"
end do;
end program trailing_semicolon_in_end_scope

0 comments on commit dece46a

Please sign in to comment.