fortls
fortls copied to clipboard
Semicolon in fixed-form comment makes part of the comment being parsed as code
Describe the bug Given a fixed-form Fortran file that has a comment line which includes a semicolon, all text after the semicolon in the comment line is parsed as regular code. This can confuse the parser if the comment includes text that makes up Fortran keywords.
To Reproduce
Given the following code in a file called invalid_comment.f
:
c ; do not treat this as code
subroutine foo
end subroutine foo
Then, calling fortls --debug_filepath invalid_comment.f --debug_parser
gives
=== Parsing Pass ===
do not treat this as code !!! DO - Ln:1
subroutine foo !!! SUBROUTINE - Ln:2
end subroutine foo !!! END SUBROUTINE Scope - Ln:3
which shows that the do
in the first comment line is parsed as a do-statement.
This can lead to many follow up errors, e.g. in the code above we will get an "Invalid parent for "SUBROUTINE" declaration" diagnostic being generated in line 2, since for the parser it seems that the subroutine is defined within a "do" loop.
Expected behavior Comments should never be parsed as code.
Screenshots & Animations
Setup information (please complete the following information):
- OS: Windows
- Python Version 3.11
- fortls Version 3.1.1
- VS Code