Comment line behaviour in Fortran90

Comment line behaviour in Fortran90

5
NewbieNewbie
5

    Nov 07, 2009#1

    Hi!
    The comment lines on Fortran90 and upper is made using the character "!" and in my wordfile fortran90.uew is defined that it be showed in green color. I would like to change this behaviour because I'm using OpenMP implementation on my programs that use "!$" or "!$OMP" directives to pass the information and therefore ultraedit show them as comment lines.
    So I would like that these lines be showed as normal lines or maybe with special color.

    I did some tentative in my fortran90.uew and I cannot see any effects on my fortran codes. Someone can help me how can I do it?

    Thanks in advance

    Javier

    6,686585
    Grand MasterGrand Master
    6,686585

      Re: Comment line behavior in Fortran90

      Nov 08, 2009#2

      I don't know who created the wordfile fortran90.uew originally, but it contained some errors.

      FORTRAN_LANG was twice in the first line. The second occurrence is deleted now.

      The definition of the line comment was also not correct. Line Comment = !space$space was an invalid definition of a line comment.

      Some keywords were present in color group 1 as well as in color group 4.


      Because I don't know anything about Fortran90 I used the information from Fortran90 for Fortran77 Programmers to be able to help you with your syntax highlighting problem of Fortran90 comments.

      In chapter 2.1  Basic Rules for both free and fixed-format there is the sentence:
      End-of-line comments start with an exclamation mark (but must not be in column 6 of fixed-format code).
      In chapter 2.2  Free-format layout there is the sentence:
      Comments start with an exclamation mark "!'' (so C or * in column 1 have to be changed to "!'').
      In UltraEdit help about syntax highlighting you can read:
      FORTRAN is quite different from other languages regarding comments, and to better facilitate the use of UltraEdit for editing FORTRAN files the "FORTRAN_LANG" keyword was added. When this keyword is present, UltraEdit treats a 'C', 'c' or '*' in the first column as a line comment indicator and the rest of the line is highlighted as if it were commented out.

      Note: Any of the normal comment indications may also be used (line comments, block comments).
      That means that Fortran90 is different than Fortran77 regarding comments and the keyword FORTRAN_LANG should be removed from the first line of the syntax highlighting wordfile for Fortran90 completely to not enable the special comment behavior of Fortran77 for Fortran90.

      Furthermore it would be good to use Line Comment Num = 2!  Line Comment Valid Columns = [1-5,7-4095]

      This means that only an exclamation mark followed by a space character is interpreted as line comment, but only when the exclamation mark does not exist in column 6. I hope the author of the referenced webpage starts counting the columns with 1 and not with 0.


      Next I looked on the /Delimiters = line and missed the space and tab character which are usually also word delimiting characters.

      The 2 UltraEdit regular expression strings for finding strings of interest for the function list contained useless expressions. I removed them. I hope the following are still correct and find the strings of interest. And I missed the module names in the function list.

      /Function String = "%[ ^t]+^(SUBROUTINE[ ^t]+[A-Z0-9_]+^)"
      /Function String 1 = "%*^(FUNCTION[ ^t]+[A-Z0-9_]+^)("
      /Function String 2 = "%[ ^t]++^(^{MODULE^}^{PROGRAM^}[ ^t]+[A-Z0-9_]+^)[ ^t]++^{!^}^{$^}"


      But I think the function strings could be further improved to display in the function list either only the function names, or the function names with the arguments, or the type of function, the function name and the arguments.

      First for showing only the function names in the function list:

      /Function String = "%[ ^t]+SUBROUTINE[ ^t]+^([A-Z0-9_]+^)"
      /Function String 1 = "%*FUNCTION[ ^t]+^([A-Z0-9_]+^)("
      /Function String 2 = "%[ ^t]++^{MODULE^}^{PROGRAM^}[ ^t]+^([A-Z0-9_]+^)[ ^t]++^{!^}^{$^}"


      Second for showing function names with arguments in the function list:

      /Function String = "%[ ^t]+SUBROUTINE[ ^t]+^([A-Z0-9_][~^p!]++^)"
      /Function String 1 = "%*FUNCTION[ ^t]+^([A-Z0-9_]+([~^p!]++^)"
      /Function String 2 = "%[ ^t]++^{MODULE^}^{PROGRAM^}[ ^t]+^([A-Z0-9_]+^)[ ^t]++^{!^}^{$^}"


      Third for showing type of function, function name and their arguments in the function list:

      /Function String = "%[ ^t]+^(SUBROUTINE[ ^t]+[A-Z0-9_][~^p!]++^)"
      /Function String 1 = "%*^(FUNCTION[ ^t]+[A-Z0-9_]+([~^p!]++^)"
      /Function String 2 = "%[ ^t]++^(^{MODULE^}^{PROGRAM^}[ ^t]+[A-Z0-9_]+^)[ ^t]++^{!^}^{$^}"


      You can make other combinations by just moving ^( and ^) inside the function strings to define what should be displayed in the function list view.

      I could not try excessive any of these regular expressions because I don't have Fortran90 files for evaluating them.


      Next I thought the lines

      /Open Brace Strings =  "("
      /Close Brace Strings = ")"


      for highlighting matching parenthesis would be useful too.


      Then I added "ELSE" to the /Unindent Strings = because the line with this keyword must be unindented and the next line is again indented. This is useful when using the auto-indent feature of UltraEdit.


      I thought code folding can be also very useful for Fortran90 files and added following two lines:

      /Open Fold Strings = "FUNCTION" "MODULE" "PROGRAM" "SUBROUTINE" "THEN" "ELSE" "DO"
      /Close Fold Strings = "END FUNCTION" "END MODULE" "END PROGRAM" "END SUBROUTINE" "ELSE" "END IF" "END DO"


      Note: According to the referenced page "ENDIF" and "ENDDO" would be also valid which is the reason why the unindent strings contain both. If you use "ENDIF" and "ENDDO" instead of "END IF" and "END DO" you have to remove the space in the last 2 close fold strings.


      Last I used my 3 wordfile syntax checking macros to sort the keywords and remove duplicate keywords.


      Added on 2010-01-10:
      According to last post of javiergp and the contribution of another user the final wordfile fortran90.uew contains only 1 simple function string:

      /Function String = "^(^{SUBROUTINE^}^{FUNCTION^}[ ^t]+[A-Z0-9_]+^)("

      And Line Comment Valid Columns = [1-5,7-4095] was replaced by Line Comment Alt = !! in the first line.

      The main wordfile fortran90.uew with the single function string is on IDM's server and can be downloaded from Extra Downloads - Wordfiles.

      5
      NewbieNewbie
      5

        Re: Comment line behaviour in Fortran

        Nov 08, 2009#3

        Your considerations are rights but only that in your wordfiles for syntax highlighting in fortran have some mistake under
        my opinion.

        I'm sending the view for the same part of code in the old fortran90.uew and using your fortran90.uew
        fortran_new.png (21.21KiB)
        New color version
        fortran_old.png (19.05KiB)
        Old color version

          Nov 08, 2009#4

          I'm trying this:

          /L20"Fortran 90" Line Comment Num = 2!  Line Comment Valid Columns = [1-5,7-4095] Nocase String Chars = "' DisableMLS File Extensions = F90 FOR FTN F

          Some considerations for above line:
          1. Line Comment Num =2!  make that lines as !!--- not be considered as comment lines.
          2. For free format writing Fortran code I think that Line Comment Valid Columns haven't sense.
          My opinion is that Line Comment = ! is OK.
          And then I was trying to use Line Comment Preceding Chars = [~$] in the line /L20"Fortran 90" ...

          I want that only the especial !$OMP or !$ not be considered as comment lines... and also in Fortran77 C$OMP C$ or *$OMP or *$.

          Can you help me?

          I have revised the fortran90.uew and I modified it according to standard Fortran90/95. In Fortran some words can be applied on statements or functions. Some reserved words is double as DOUBLE PRECISION. So for this reason I think that you found words in several parts of previous fortran90.uew.

          When I resolve this (I hope with your help) then I'll send the new fortran90.uew to IDM team.

          Thanks, Javier

          6,686585
          Grand MasterGrand Master
          6,686585

            Nov 09, 2009#5

            javiergp wrote:Line Comment Num =2!  make that lines as !!--- not be considered as comment lines.
            That's correct. Is !!--- a standard for Fortran90 or just your standard? If it is just your standard, add to the first line Line Comment Alt = !! as second type of line comments also highlighted with the line comment color, but don't use this definition in file fortran90.uew for IDM.

            javiergp wrote:For free format writing Fortran code I think that Line Comment Valid Columns haven't sense.
            That's also correct. For free format Fortran90 this definition can be removed. It only excludes column 6 as line comment starting column. So it is not really necessary.

            javiergp wrote:My opinion is that Line Comment = ! is OK.
            And then I was trying to use Line Comment Preceding Chars = [~$] in the line /L20"Fortran 90" ...
            Well, Preceding means left the line comment string and not right the line comment string. Everything right the comment string is always handled already as comment. So there is no chance to define that an exclamation mark is the start of a line comment except a dollar sign follows. To exclude !$ as line comment it is necessary to specify !space and always use a space after the exclamation mark. Up to 3 additional line comments like !! can be also defined. But if you use a commenting style like:

            ! standard comment
            !comment without space
            !other comment without space
            !a further comment without space
            !!-- next comment style

            You are out of luck with the UltraEdit syntax highlighting engine to highlight the comments correct when !$ should not be highlighted as comment.

            javiergp wrote:... and also in Fortran77 C$OMP C$ or *$OMP or *$.
            That should be no problem in Fortran77 because 'C', 'c' or '*' are handled as line comment starting character only when found in column 1 and therefore just a indenting space must be inserted on left side and it will be ignored.

            javiergp wrote:In Fortran some words can be applied on statements or functions.
            The Fortran90 syntax highlighting definition is defined as being not case sensitive. Therefore "double" and "DOUBLE" is the same word, internally both are "double". UltraEdit uses always the color group where a word is found first. So it is of no sense to specify a word twice. It just makes the list of words larger resulting in a longer time on checking a determined string from the file to highlight against the word list. UltraEdit can't evaluate if the word to highlight applies to a statement or a function and use then the word from color group X or Y. UltraEdit is not an interpreter for Fortran90 code.

            I hope this helps you now. Are the function strings working fine? Which version do you think is best for others coding in Fortran90?
            Best regards from an UC/UE/UES for Windows user from Austria

            5
            NewbieNewbie
            5

              Nov 09, 2009#6

              Thanks for your answer.
              In Fortran90 all that you write on right side from "!" is considered as comment information (of course except on a literal variable).
              Therefore write !!---- or !!!!!! is always comment and only is a question of programmer's style.

              From your comment I have to ask to IDM team that introduce exception rules on this part. In order to include situation as using OpenMP directives that start as !$OMP or !S.

              For me, the best option from your fortran90.uew is that in the function list window be showed the procedure name and also arguments but not units parts as Program, Module.

              Thanks for all

              Javier