-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
TypeError when parsing file that line-continues onto preprocessor directive (include) #236
Comments
Thanks for the report, this does not look like valid Fortran, did you make a mistake while posting the code?
This needs a more thorough look, I will get to it later this week. |
It's two separate files. The first ( subroutine hello2 &
#include "hellobody.inc" while the second ( (i)
integer :: i
print *, 'Hello world 2!', i
end subroutine After the preprocessor is applied (via The perversity tickled here is that line continuation has a lower precedence than preprocessor #include directives. In the legacy codebase that brought up this issue, these sorts of inclusions are used alongside other #defines to implement a rough and ready type of templated code. A workaround to avoid the crash just moves the I've also updated the initial comment in this issue to fully separate the three files in the minimum example. |
The mock-template code that uses the C preprocessor to define multiple versions of Interp/Extrap functions is incompatible with Fortran linting, crashing the linter (see fortran-lang/fortls#236) because it tries to process the Fortran syntax without invoking the preprocessor. This code adjusts the templates to hold just the subroutine body, leaving the `end subroutine` statement for the enclosing Fortran file. This change fixes the linter crash, although it still doesn't properly understand the subroutines.
The mock-template code that uses the C preprocessor to define multiple versions of Interp/Extrap functions is incompatible with Fortran linting, crashing the linter (see fortran-lang/fortls#236) because it tries to process the Fortran syntax without invoking the preprocessor. This code adjusts the templates to hold just the subroutine body, leaving the `end subroutine` statement for the enclosing Fortran file. This change fixes the linter crash, although it still doesn't properly understand the subroutines.
The problem here is that you are essentially trying to inject new AST nodes into a file during preprocessing. If the new content is injected in place, like in |
I don't know which of the 2 is a better strategy to address this.
|
This PR #399 should stop this from crashing. Still not preprocessor AST scope injection. |
Describe the bug
fortls
does not parse include directives when joining continued lines. This leads to incorrect parsing, including a TypeError when the line-joining – which ignores preprocessor directives and comments – reaches the end of the file.To Reproduce
hellomain.F90
:hellosub.F90
hellobody.inc
:Execution and error:
Expected behavior
Correct parsing of
hellosub.F90
, as per:fortls_test$ ifort -E ./hellosub.F90 > hellosub_pre.F90 fortls_test$ cat hellosub_pre.F90
Setup information (please complete the following information):
Configuration information (please complete the following information):
No configuration settings used to reproduce this error.
Additional context
The narrow crash is caused by the iteration in
parse_fortran.py
, where line 1090 performs an unconditional get_line that returns None at the end of the file, but line 1093 assumes that the returned line is a valid object (string) for regular expression parsing.The broad error is caused because the parser tries to assemble complete lines before any preprocessor shenanigans, whereas compilable Fortran (albeit with horrible style — the error originates from a legacy codebase) applies the preprocessor before line continuation. That means that a line can continue into (or out of!) an included file.
The text was updated successfully, but these errors were encountered: