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

Fortran syntax: types recognized as functions #11281

Open
Jellby opened this issue Oct 4, 2022 · 1 comment
Open

Fortran syntax: types recognized as functions #11281

Jellby opened this issue Oct 4, 2022 · 1 comment

Comments

@Jellby
Copy link

Jellby commented Oct 4, 2022

Steps to reproduce

  1. Open a new file a.f90 (syntax highlighting enabled, Fortran free source)
  2. Enter some variable declaration (with explicit kind):
real(kind=wp) :: foo
integer(kind=iwp) :: bar

Expected behaviour

Both type keywords (real and integer) should be highlighted with the same color, but they appear different (blue and green, respectively, in my system).

It seems real is recognized as the function instead of the type. Writing implicit real(kind=wp) fixes it.

Version of Vim

8.2 (2019 Dec 12, compiled Sep 13 2022 09:35:02)

Environment

Ubuntu 22.04, on Konsole

Logs and stack traces

No response

@Jellby Jellby added the bug label Oct 4, 2022
@lacygoill
Copy link

lacygoill commented Oct 5, 2022

I don't know Fortran, but it seems that the language supports a real data type, and a real() function. And when the real data type is written in a variable declaration, it might be followed by a parenthesis, making real ambiguous. If so, the syntax plugin might need a more accurate rule to avoid matching real as a function name, when it's actually a data type. It seems that declarations usually contain the token ::. Maybe we need to disallow its presence:

diff --git a/runtime/syntax/fortran.vim b/runtime/syntax/fortran.vim
index b5c9b1ef8..31a0c5ca8 100644
--- a/runtime/syntax/fortran.vim
+++ b/runtime/syntax/fortran.vim
@@ -149,7 +149,7 @@ syn keyword fortranExtraIntrinsic	algama cdabs cdcos cdexp cdlog cdsin cdsqrt cq
 
 syn keyword fortranIntrinsic	abs acos aimag aint anint asin atan atan2 char cmplx conjg cos cosh exp ichar index int log log10 max min nint sign sin sinh sqrt tan tanh
 syn match fortranIntrinsic	"\<len\s*[(,]"me=s+3
-syn match fortranIntrinsic	"\<real\s*("me=s+4
+syn match fortranIntrinsic	"\<real\s*(\%(.*::\)\@!"me=s+4
 syn match fortranIntrinsic	"\<logical\s*("me=s+7
 syn match fortranType           "\<implicit\s\+real\>"
 syn match fortranType           "\<implicit\s\+logical\>"

In any case, I suggest you discuss this issue with the maintainer of the Fortran syntax plugin whose contact information is given at the top of the script:

" Maintainer:	Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>

They will decide how the issue should be fixed (if at all), then send their changes to the Vim devs to be merged in the next update of the runtime files (the last one occurred a few days ago).

@dkearns dkearns added the runtime label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants