Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semicolon in fixed-form comment makes part of the comment being parsed as code #411

Open
albertziegenhagel opened this issue Jun 10, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@albertziegenhagel
Copy link
Contributor

albertziegenhagel commented Jun 10, 2024

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
image

Setup information (please complete the following information):

  • OS: Windows
  • Python Version 3.11
  • fortls Version 3.1.1
  • VS Code
@albertziegenhagel albertziegenhagel added the bug Something isn't working label Jun 10, 2024
@gnikit
Copy link
Member

gnikit commented Jun 10, 2024

Thanks @albertziegenhagel I will look into it.

@gnikit
Copy link
Member

gnikit commented Jun 23, 2024

I think I have located the problem, however it interferes with the spaghetti code for parsing Doxygen-like and FORD-like docstrings. I might have to rewrite those 2 parsers first, before I fix this.
I

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants