hansec / fortran-language-server

Fortran Language Server for the Language Server Protocol
MIT License
295 stars 57 forks source link

Comment in middle of if statement creates "unexpected end of scope" error #155

Open jrwrigh opened 4 years ago

jrwrigh commented 4 years ago

If I have the following if statement:

       if ((longVariableX .neq. longVariableY) .and. ! ensure X != Y
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

I get an error for it's respective subroutine saying there's an "Unexpected end of scope" error.

Removing the first comment eliminates the error. ie:

       if ((longVariableX .neq. longVariableY) .and.
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

will not cause an error.

hansec commented 4 years ago

Thanks for the report. However, I think this is technically invalid? As far as I know, trailing line comments are only allowed in free-form Fortran.

There is an "intersection" style that places ampersands at the start and end of files as below, but other than that I don't think this is technically allowed.

       if ((longVariableX .neq. longVariableY) .and.  & ! ensure X != Y
      &    (longVariableZ .eq. longVariableX)) ! ensure Z == X

I can certainly add support for trailing line comments in fixed-form code, but I prefer to limit extensions like that to widely supported ones. Do you know if most compliers (ie. GNU, Intel, Cray, etc.) support this style without complaining?

jrwrigh commented 4 years ago

trailing line comments are only allowed in free-form Fortran.

Does this only support fixed-form? My code base is a weird mix of "interpreted as free-form but written in fixed-form (sort of)" so being able to do both would be quite nice.

Do you know if most compliers (ie. GNU, Intel, Cray, etc.) support this style without complaining?

The offending code has been compiled on several dozen HPC machines, so I'd imagine that it would work with all of them. That said, I can only vouch for Intel and GNU compilers.