You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a much more interesting "bug" than what it seems. Its root is that the regex responsible for opening the scopes matches the end of the match with the name of the subroutine (function, submodule, etc.) so it expects that inner scopes are closed first, followed by outer scopes, e.g.
However, when preprocessor directives are used the order is upsetted and it no longer makes sense to close the scopes in the same order
subroutinescope_1()
#ifdef DEF
subroutinescope_2()
#elsesubroutinescope_3()
#endif
#ifdef DEF
end subroutine scope_2()
#else
end subroutine scope_3()
#endifendsubroutine scope_1
Now scope 2 and scope 3 are on the same level since they are guarded by a preproc conditional.
Solution
I think it is reasonable to expect our grammar not being responsible for catching coding errors such as using the wrong subroutine,function, etc. when closing a scope. I will edit the scopes to exit upon a C++ variable name (names can be preprocessor macros)
Previously nested scopes had to be closed in the reverse order than they
were opened e.g.
```f90
subroutine scope_1()
subroutine scope_2()
subroutine scope_3()
end subroutine scope_3
end subroutine scope_2
end subroutine scope_1
```
However with preprocessor conditionals that would be an issue since
```f90
subroutine scope_1()
#ifdef DEF
subroutine scope_2()
#else
subroutine scope_3()
#endif
#ifdef DEF
end subroutine scope_2()
#else
end subroutine scope_3()
#endif
end subroutine scope_1
```
`scope_2` and `scope_3` would be in the same level on the AST, so it is
no longer valid to expect `scope_3` to close before `scope_2`.
The solution to this is removing the strict requirement for scopes to
have matching begin-end names from the regex. The type of scopes
where this requirement is removed are:
- Functions
- Modules
- Programs
- Module Procedures
- Subroutines
- Submodules
Fixes Erroneous syntax highlighting with subroutine names and preprocessor conditionals #278
Describe the bug
end subroutine surrounded by preprocessor conditionals is erroneous
Screenshots
Code sample
Fortran Form
Free form (F90+)
Build info (please complete the following information):
The text was updated successfully, but these errors were encountered: