Tapatalk

Fortran90 code folding, (ELSE IF)

Fortran90 code folding, (ELSE IF)

2

    Apr 27, 2010#1

    I'm using UE version 13.00a+2.

    I have noticed some difficulties with code folding for IF THEN ELSE IF constructs with the fortran90.euw file.
    I have tried a variety of ways of changing /Open Fold Strings and /Close Fold Strings but none that I have tried seem to work

    Several IF...END IF constructs are not folding correctly.

    ----------

    Fortran90 allows arbitrary mixing of "END IF" and "ENDIF" as well as "ELSE IF" and "ELSEIF". Is there a way to facilitate code folding for these?

    -------------
    +IF (something) THEN
    +ELSE IF (something) THEN
    +ELSE
    END IF

    The "ELSE IF" is terminating at an "END SUBROUTINE" line.

    -------------------
    +IF (something) THEN
    +ELSE IF (something) THEN
    END IF

    The "ELSE IF" is terminating at an "END SUBROUTINE" line.

    ==========================================
    The following work fine and need to continue to work....

    +IF (something) THEN
    ENDIF

    +IF (something) THEN
    +ELSE
    ENDIF


    Thanks.

    --Jeff Brown

    6,685587
    Grand MasterGrand Master
    6,685587

      Apr 27, 2010#2

      Mixing of "END IF" and "ENDIF" as well as "ELSE IF" and "ELSEIF" is no problem. The problem here is

      ELSE IF (something) THEN

      ELSE is set as open and close fold string which is correct set and correct interpreted by UltraEdit. THEN is set as an open fold string (for IF and perhaps other). So when the code folding parser reaches that line it interprets it as
      1. ELSE found - closing fold string for previous open fold found.
      2. ELSE found - new open fold string found.
      3. THEN found - a second new open fold string found.
      And THEN as second open fold string here is the problem. The code folding engine internally now thinks there are 2 folding levels open, the first one is closed with the following ELSE, but the second one is open up to END SUBROUTINE.

      This situation can't be solved with the current implementation of the code folding engine of UltraEdit. I suggest to use additionally

      /Ignore Fold Strings = "ELSE IF"

      to get best out of the code folding engine.
      Best regards from an UC/UE/UES for Windows user from Austria

      901
      MasterMaster
      901

        Apr 27, 2010#3

        Jeff,

        While it might not be immediately evident in the existing word file, there is no need to define a one-to-one match of Open and Close Fold Strings. What is important is that you list all of the syntax on which you want a new fold to open and list all of the syntax on which you want an existing fold to close. For what you describe, that would look something like this:

        /Open Fold Strings = "FUNCTION" "MODULE" "PROGRAM" "SUBROUTINE" "IF" "ELSEIF" "ELSE IF" "ELSE" "DO" "SELECT"
        /Close Fold Strings = "END FUNCTION" "END MODULE" "END PROGRAM" "ELSEIF" "ELSE IF" "ELSE" "ENDIF" "END IF" "END DO" "END SELECT"

        Notice that:
        • the initial "IF" is only in the Open Fold Strings list
        • the final "ENDIF" and "END IF" are only in the Close Fold Strings
        • All variations of "ELSE" need to be in both lists so that they always close the previous fold and start a new one

        2

          Apr 27, 2010#4

          The following seems to be the best solution, a combination of both of the previous replies:

          /Open Fold Strings = "FUNCTION" "MODULE" "PROGRAM" "SUBROUTINE" "SELECT" "DO" "IF" "ELSE" "ELSEIF"
          /Close Fold Strings = "END FUNCTION" "END MODULE" "END PROGRAM" "END SUBROUTINE" "END SELECT" "END DO" "ELSE" "ELSEIF" "END IF" "ENDIF"
          /Ignore Fold Strings = "ELSE IF"


          Using "ELSE IF" as part of the /Open Fold Strings and /Close Fold Strings, but the above combination works reasonably well.

          Thanks!

          --Jeff Brown

          901
          MasterMaster
          901

            Apr 28, 2010#5

            There is no need to ignore "ELSE IF". The folding rules I provided should work best.
            The real issue with the original wordfile was the use of "THEN". My solution doesn't fold on "THEN".

            6,685587
            Grand MasterGrand Master
            6,685587

              Apr 28, 2010#6

              Bulgrien, just using

              /Open Fold Strings = "FUNCTION" "MODULE" "PROGRAM" "SUBROUTINE" "IF" "ELSEIF" "ELSE IF" "ELSE" "DO" "SELECT"
              /Close Fold Strings = "END FUNCTION" "END MODULE" "END PROGRAM" "END SUBROUTINE" "ELSEIF" "ELSE IF" "ELSE" "ENDIF" "END IF" "END DO" "END SELECT"

              without using additionally /Ignore Fold Strings = "ELSE IF" does not produce correct code folding for

              SUBROUTINE
              !!Some code lines
              IF (something) THEN
              !!Some code lines
              ELSE IF (something) THEN
              !!Some code lines
              ELSE
              !!Some code lines
              END IF
              !!Some code lines
              END SUBROUTINE

              because now there are the open fold strings IF and ELSE in the same line. Of course there is also "ELSE IF" in the open fold strings definition line, but UltraEdit does not search for the fold strings from longest to shortest or in the order as specified. I don't know how the code folding parser internally works, but it looks like "ELSE" and "IF" are preferred over "ELSE IF". Interesting is that "ELSEIF" works because "ELSE" and "IF" are not applied to "ELSEIF".
              Best regards from an UC/UE/UES for Windows user from Austria

              901
              MasterMaster
              901

                Apr 28, 2010#7

                Thanks Mofi... Somehow I must have dropped the "END SUBROUTINE" from the wordfile which caused the whole IF structure to fold correctly but did not allow for folding the subroutine. Ignoring "ELSE IF" statements is not ideal, but it appears to be the lesser of two evils. Perhaps we'll see some improvements in the folding logic in the future, but for now... I stand corrected. ;)