eirik-kjonstad / modern-fortran-syntax

Modern Fortran syntax highlighting for Sublime Text 3/4
MIT License
10 stars 2 forks source link

Add highlighting for arguments in function and subroutine declarations #23

Closed jwortmann closed 3 years ago

jwortmann commented 3 years ago

... and proper punctuation scopes for the parentheses.

Note:

eirik-kjonstad commented 3 years ago
  • I'm not really familiar with the syntax Cee%Dee in MODULE SUBROUTINE MY_SUBROUTINE(A, B, Cee%Dee). The Cee part was scoped storage.type.class before, so I kept this scope here via the "class-accessing" context. Not sure whether the whole Cee%Dee expression should better be variable.parameter here?

This seems to be a mistake. Must have gotten in because it was confused with CALL MY_SUBROUTINE(A, B, Cee%Dee). You can remove it from the tests and only highlight the variables in function/subroutine declaration as variable.parameter.

jwortmann commented 3 years ago

This seems to be a mistake. Must have gotten in because it was confused with CALL MY_SUBROUTINE(A, B, Cee%Dee).

Oh, this resolved some confusion 😄 . It's fixed now.

jwortmann commented 3 years ago

I'm not sure whether or how much if any of it can be re-used between functions and subroutines, because only functions need to highlight the result(x) part. Keep in mind that Fortran doesn't have any reserved words, so it's probably advantageous to highlight keywords only where they make sense, and not in all arbitrary places of the code.

Btw there is one lookahead I used for functions, that might look like nonsense, but seems to be required because of a bug in the syntax highlighting engine with set and meta_content_scope (https://www.sublimetext.com/docs/syntax.html#compatibility). This was fixed in syntax version 2, but of course we can't use it because there is no backward compatibility to Sublime Text 3.

                - match: (?=\()
                  set:
                    - clear_scopes: 1
                    - match: \(
eirik-kjonstad commented 3 years ago

I agree that result should be understood in the context of the function declaration here. I thought perhaps the argument-parsing could be re-used, but it seems a bit difficult to separate out this part because of the behavior when ) is reached.

More generally, we have often opted not to interpret where keywords appear in the code. Mainly, this is because it can be easy to overlook alternative contexts in which keywords appear, and to forget to account for all valid syntax within a given context. I do of course agree that it is preferable if syntax is highlighted only when appropriate - but it has to be done with care.