Tapatalk

Code folding issue with my BASIC files

Code folding issue with my BASIC files

18
Basic UserBasic User
18

    Apr 12, 2007#1

    Long time user, first time poster. Greetings and salutations!

    I'm using a fairly obscure language that bears a lot of resemblance to C and BASIC. I've been working on getting the code folding to work correctly for this language and having mixed results.

    An example of the code:

    Code: Select all

    SUB DELFILES(INFILE$)
       STRING  INFILE$
    
       WRITE #1; TAB$ + TAB$ + "Deleting " + INFILE$
       ERROR.OCCURRED = -1
       FILE.OPEN = 0
       WHILE ERROR.OCCURRED
          ERROR.OCCURRED = 0
          IF NOT FILE.OPEN THEN BEGIN
             WRITE #1; TAB$ + TAB$ + TAB$ + "Opening file " + INFILE$
             OPEN INFILE$ AS 4
          ENDIF
          IF ERROR.OCCURRED THEN BEGIN
             IF CHAR.STRING$ <> "80204010" THEN BEGIN
                GOSUB DELFILES.LOG.ERROR
             ENDIF ELSE BEGIN
                ERROR.OCCURRED = 0
             ENDIF
          ENDIF ELSE BEGIN
             FILE.OPEN = -1
             WRITE #1; TAB$ + TAB$ + TAB$ + "Deleting file " + INFILE$
             DELETE 4
             IF ERROR.OCCURRED THEN BEGIN
                GOSUB DELFILES.LOG.ERROR
             ENDIF
          ENDIF
       WEND
       EXIT SUB
    
    DELFILES.LOG.ERROR:
       WRITE #1; TAB$ + TAB$ +                                      \
                 "ERROR LOGGED = "  +                               \
                 "HT" +                                             \
                 RIGHT$("00" + STR$(HT.ERRF%),2) +                  \
                 HT.ERR$ +                                          \
                 CHAR.STRING$
       I% = ADXERROR(0,ASC("H"),004,1,9,ERR.MESSAGE$)
       WAIT;300000
       RETURN
    
    END SUB
    Using the following options in the wordfile allows the Function, Sub and While code to fold perfectly.
    /Open Fold Strings = "Function" "Sub" "While"
    /Close Fold Strings = "End Function" "End Sub" "Wend"
    /Ignore Fold Strings = "Exit Sub" "Exit Function"

    My problem comes in when I try to set it up to fold If/Endif code. I tried the following, but got strange results:
    /Open Fold Strings = "Function" "Sub" "While" "If" "Endif Else"
    /Close Fold Strings = "End Function" "End Sub" "Wend" "Endif"
    /Ignore Fold Strings = "Exit Sub" "Exit Function"

    Fold marks are missing from some If statements... Folding for previously working code now ends the folds in the wrong spots... Any help would be appreciated.

    6,685587
    Grand MasterGrand Master
    6,685587

      Apr 12, 2007#2

      Use /Close Fold Strings = "End Function" "End Sub" "Wend" "Endif Else" "Endif"

      ENDIF ELSE is at the same time a close and an open fold string and so must be specified on both fold definition lines.
      Best regards from an UC/UE/UES for Windows user from Austria

      18
      Basic UserBasic User
      18

        Apr 12, 2007#3

        Thank you for the response Mofi, but still not quite right.

        Using the following:
        /Open Fold Strings = "Function" "Sub" "While" "If" "Endif Else"
        /Close Fold Strings = "End Function" "End Sub" "Wend" "Endif Else" "Endif"
        /Ignore Fold Strings = "Exit Sub" "Exit Function"

        Here is what I get:

        Code: Select all

        [-] SUB DELFILES(INFILE$)
               STRING  INFILE$
            
               WRITE #1; TAB$ + TAB$ + "Deleting " + INFILE$
               ERROR.OCCURRED = -1
               FILE.OPEN = 0
        [-]    WHILE ERROR.OCCURRED
                  ERROR.OCCURRED = 0
                  IF NOT FILE.OPEN THEN BEGIN
                     WRITE #1; TAB$ + TAB$ + TAB$ + "Opening file " + INFILE$
                     OPEN INFILE$ AS 4
                  ENDIF
                  IF ERROR.OCCURRED THEN BEGIN
                     IF CHAR.STRING$ <> "80204010" THEN BEGIN
                        GOSUB DELFILES.LOG.ERROR
        [-]          ENDIF ELSE BEGIN
                        ERROR.OCCURRED = 0
                     ENDIF
        [-]       ENDIF ELSE BEGIN
                     FILE.OPEN = -1
                     WRITE #1; TAB$ + TAB$ + TAB$ + "Deleting file " + INFILE$
                     DELETE 4
                     IF ERROR.OCCURRED THEN BEGIN
                        GOSUB DELFILES.LOG.ERROR
                     ENDIF
                  ENDIF
               WEND
               EXIT SUB
            
            DELFILES.LOG.ERROR:
               WRITE #1; TAB$ + TAB$ +                                      \
                         "ERROR LOGGED = "  +                               \
                         "HT" +                                             \
                         RIGHT$("00" + STR$(HT.ERRF%),2) +                  \
                         HT.ERR$ +                                          \
                         CHAR.STRING$
               I% = ADXERROR(0,ASC("H"),004,1,9,ERR.MESSAGE$)
               WAIT;300000
               RETURN
            
            END SUB
        The folding for the Sub and While loop are messed up.  Fold ends in the wrong spots.

        Edit:
        By the way I am using UltraEdit for Windows version 13.00+8.

        6,685587
        Grand MasterGrand Master
        6,685587

          Apr 12, 2007#4

          Have you restarted UE after that modification?

          I have tried it also with UE v13.00+8 on your example and got the correct code folding.
          Best regards from an UC/UE/UES for Windows user from Austria

          18
          Basic UserBasic User
          18

            Apr 12, 2007#5

            I did.  If it will help, here is the entire section for this language.

            Code: Select all

            /L14"4690" Line Comment = ! \ Nocase File Extensions = BAS J86 INC
            /Function String = "%*^{Sub^}^{Function^}*(*"
            /Delimiters = ~!@%^&*()-+=|\/{}[]:;"'<> , .?
            /Open Brace Strings =  "("
            /Close Brace Strings = ")"
            /Open Fold Strings = "Function" "Sub" "While" "If" "Endif Else"
            /Close Fold Strings = "End Function" "End Sub" "Wend" "Endif Else" "Endif"
            /Ignore Fold Strings = "Exit Sub" "Exit Function"
            /C1"Functions"
            ABS ASC
            CHR$ COMMAND$ CONCHAR% CONSTAT%
            DATE$ DISABLE
            ENABLE ERR ERRF% ERRL ERRN EVENT%
            FLOAT FRE
            GET GETLONG
            INKEY INT INT%
            LEFT$ LEN LOCK
            MATCH MFRE MID$ MOD
            PACK$ PEEK POS PTRRTN
            RENAME RIGHT$ ROUND RND
            SADD SGN SHIFT SIZE STR$ STRING$
            TAB TIME$ TRANSLATE$
            UCASE$ UNLOCK UNPACK$
            VAL VARPTR
            
            /C2"Statements"
            ACCESS ASSIGNKEY ASYNC
            CALL CHAIN CHDIR CLEARS CLOSE COMMON CONSOLE CREATE
            DATA DEF DELETE DELREC DIM
            END END END FUNCTION END SUB ERROR EXIT
            FEND FOR FUNCTIONKEY
            GOSUB GOTO
            IF IF END INPUT INTEGER
            KEYED
            LET LINE LPRINTER LOAD LOCATE LOCKDEV LOGO
            MKDIR
            NEXT
            ON OPEN OPEN LINK OPEN SESSION OPTION
            POKE PRINT POINT POSFILE PUT PUTLONG
            RANDOM RANDOMIZE READ READ FORM REAL REMARK RESTORE RESUME RETURN RMDIR
            SERIAL STOP STRING SUB
            TCLOSE
            UNLOCKDEV USE USING
            WAIT WEND WHILE WRITE WRITE MATRIX
            
            /C3"Operators"
            (
            )
            +
            -
            *
            /
            ^
            =
            < <= <>
            > >=
            AND
            EQ
            GT GE
            LT LE
            NE NOT
            OR
            XOR

            6,685587
            Grand MasterGrand Master
            6,685587

              Apr 13, 2007#6

              Okay, something mysterious happens here. The fold strings work perfect, when I modified my "C" language definition with your 3 fold string lines and saved your example code as file Test.c.

              Yesterday at the evening in Austria I tried it with your language definition and renamed the file to Test.bas and get the same result as you. I selected in View - Views/Lists my "C" language definition which has still your fold strings and surprise, the code folding engine worked perfect on Test.bas. Back to "4690" language definition and Test.bas was again wrong interpreted by the code folding engine.

              So I looked on your language definition, corrected all the mistakes, sorted the groups with my macro SortLanguage which can be downloaded from the ultimate syntax highlighting tools and tried it again. But the code folding engine does not stop to sometimes work and sometimes not. After 40 minutes of experimenting with language "4690", I found what causes the problems.

              If you remove the extension BAS from the file extensions lists, then the code folding engine will always work perfect automatically on files with the extension J86 and INC and also BAS after manually selecting the language "4690" in the view menu for the file with extension BAS.

              But with BAS specified as file extension for language "4690" the code folding engine seems to ignore the fold string definitions and uses internal defaults or simply does not work correct.

              You have to ask IDM per email to look into this and fix that problem. Attach in a zip archive
              • your example code as file "Test4690.bas",
              • the corrected syntax highlighting word file below,
              • a PNG screenshot how the code folding works for the example code with that word file,
              • a PNG screenshot how the code folding should work for the example code with that word file.
                (Remove temporarily BAS at line 1 of the word file and specify the language "4690" via the view menu to get a screenshot (Alt+PrintScreen) of a correct working code folding engine.)
              By the way: You don't need to restart UE after making changes to the word file, if you edit the word file in the same UE instance.


              Here is your corrected and resorted word file. I'm not sure what is the real line comment. The string "! \" or only the character '!' or alternatively '\'. I used the second one (! or \) in the word file. If it is the string with a space between ! and \, then replace Line Comment = ! Line Comment Alt = \ with Line Comment Num = 3! \

              Please note: tab on the second line must be replaced by a real tab character after copying the language definition from the browser window to your word file.

              /L14"4690" Nocase Line Comment = ! Line Comment Alt = \ String Chars = " DisableMLS File Extensions = BAS INC J86
              /Delimiters = ~!@^&*()-+=|\/{}[]:;"'<> ,tab.?
              /Function String = "%*^{Sub^}^{Function^}^(*(*^)$"
              /Open Brace Strings = "("
              /Close Brace Strings = ")"
              /Open Fold Strings = "FUNCTION" "SUB" "WHILE" "IF" "ENDIF ELSE"
              /Close Fold Strings = "END FUNCTION" "END SUB" "WEND" "ENDIF ELSE" "ENDIF"
              /Ignore Fold Strings = "EXIT SUB" "EXIT FUNCTION"
              /C1"Functions"
              ABS ASC
              CHR$ COMMAND$ CONCHAR% CONSTAT%
              DATE$ DISABLE
              ENABLE ERR ERRF% ERRL ERRN EVENT%
              FLOAT FRE
              GET GETLONG
              INKEY INT INT%
              LEFT$ LEN LOCK
              MATCH MFRE MID$ MOD
              PACK$ PEEK POS PTRRTN
              RENAME RIGHT$ RND ROUND
              SADD SGN SHIFT SIZE STR$ STRING$
              TAB TIME$ TRANSLATE$
              UCASE$ UNLOCK UNPACK$
              VAL VARPTR
              /C2"Statements"
              ACCESS ASSIGNKEY ASYNC
              CALL CHAIN CHDIR CLEARS CLOSE COMMON CONSOLE CREATE
              DATA DEF DELETE DELREC DIM
              END ENDIF ELSE ERROR EXIT
              FEND FOR FORM FUNCTION FUNCTIONKEY
              GOSUB GOTO
              IF INPUT INTEGER
              KEYED
              LET LINE LINK LOAD LOCATE LOCKDEV LOGO LPRINTER
              MATRIX MKDIR
              NEXT
              ON OPEN OPTION
              POINT POKE POSFILE PRINT PUT PUTLONG
              RANDOM RANDOMIZE READ REAL REMARK RESTORE RESUME RETURN RMDIR
              SERIAL SESSION STOP STRING SUB
              TCLOSE
              UNLOCKDEV USE USING
              WAIT WEND WHILE WRITE
              /C3"Operators"
              (
              )
              *
              +
              -
              // /
              <
              =
              >
              ^
              AND
              EQ
              GE GT
              LE LT
              NE NOT
              OR
              XOR
              Best regards from an UC/UE/UES for Windows user from Austria

              18
              Basic UserBasic User
              18

                Apr 13, 2007#7

                Interesting!  I wrote the wordfile a couple of years ago, and was learning about all the nuances at the same time.  As I was playing with it this time I noticed the errors in the Functions and Statements sections.  Thank you for correcting them.

                One thing I made sure to do was remove BAS from the File Extensions for the Visual Basic section (/L2 I believe) and added it to mine.

                Both ! and \ designate comments.  Typically \ is used at the end of a line to add comments AND the command on the line continues on the next line.  For example, the last WRITE in the sample code.

                6,685587
                Grand MasterGrand Master
                6,685587

                  Apr 13, 2007#8

                  Pebblecrusher wrote:One thing I made sure to do was remove BAS from the File Extensions for the Visual Basic section (/L2 I believe) and added it to mine.
                  My word file does not contain any language with BAS as file extension. I don't use the default wordfile.txt. Nevertheless, the code folding engine does not work correct when BAS is specified for "4690". The developers of IDM must look into this problem. I can't further help you on this issue.
                  Best regards from an UC/UE/UES for Windows user from Austria

                  18
                  Basic UserBasic User
                  18

                    Apr 13, 2007#9

                    I have just sent an email with all the things you suggested.  Thank you for your help!

                    6,685587
                    Grand MasterGrand Master
                    6,685587

                      Aug 04, 2007#10

                      Today I looked with UE v13.10a+1 into this issue again and could see, the problem still exists. Have you got an answer from IDM?

                      However, I have found a workaround for the code folding problem for files with the extension BAS.

                      While I have tried it again I thought, that extension BAS is normally used for Basic files as you have also written and maybe there is something specified in uedit32.exe for Basic files. So I unpacked uedit32.exe and searched for BAS. And indeed I found a block in uedit32.exe with several predefined file extensions for C/C++, Visual Basic, HTML, Cobol, ...

                      Next I thought, what happens when I add language marker keyword VB_LANG to your language definition? I can tell you what happens, also files with extension J86 and INC are not correct interpreted anymore by the code folding engine. Same bad handling as for *.BAS files.

                      So I modified VB_LANG to invalid because unknown language marker keyword BASIC_LANG. But this was enough. Now UltraEdit is not interpreting *.bas *.j86 and *.inc files anymore as Visual Basic files and the code folding engine works for all 3 type of files as specified in the language definition. Interesting is that using known language marker keyword PUREBASIC_LANG works too.

                      So do the same. Add either unknown keyword BASIC_LANG or valid language marker keyword PUREBASIC_LANG after /L14"4690" and the code folding engine will work as specified and you want.

                      PS: Information about PUREBASIC_LANG was added to this post on 2010-02-18.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      18
                      Basic UserBasic User
                      18

                        May 20, 2009#11

                        Sorry for dredging up this old topic, but the history could come in handy.
                        First, thanks again for the help previously!

                        Using v15 now, and still have to have the BASIC_LANG in my language definition. Oh well!
                        But still having some trouble with code folding. Basically it comes down to a problem related to the folding engine finding an open fold string with no corresponding close fold string.

                        This code does not fold correctly:

                        Code: Select all

                        FUNCTION ?DEL.ZEROES(INPUT$) PUBLIC
                          STRING ?DEL.ZEROES,INPUT$
                            FOR I% = 1 TO LEN(INPUT$) - 1
                              IF MID$(INPUT$,I%,1) NE "0" THEN GOTO NON.ZERO
                            NEXT I%
                        NON.ZERO:
                            IF I% > 1 THEN BEGIN
                              ?DEL.ZEROES =  MID$(INPUT$,I%,18)
                            ENDIF ELSE BEGIN
                              ?DEL.ZEROES = INPUT$
                            ENDIF
                        END FUNCTION
                        
                        This code folds correctly:

                        Code: Select all

                        FUNCTION ?DEL.ZEROES(INPUT$) PUBLIC
                          STRING ?DEL.ZEROES,INPUT$
                            FOR I% = 1 TO LEN(INPUT$) - 1
                             IF MID$(INPUT$,I%,1) NE "0" THEN BEGIN
                                 GOTO NON.ZERO
                              ENDIF
                            NEXT I%
                        NON.ZERO:
                            IF I% > 1 THEN BEGIN
                              ?DEL.ZEROES =  MID$(INPUT$,I%,18)
                            ENDIF ELSE BEGIN
                              ?DEL.ZEROES = INPUT$
                            ENDIF
                        END FUNCTION
                        
                        The difference is that in the first example the IF statement is a single line, versus an IF / ENDIF pair. In the first example the fold happens on the FOR statement, and folds everything to the END FUNCTION. Also the fold for the FUNCTION / END FUNCTION pair does not work either.

                        Any idea how to get around this? Below is the entire section from the wordfile, for reference.

                        Code: Select all

                        /L1"4690" BASIC_LANG Nocase Line Comment = ! Line Comment Alt = \ String Chars = " DisableMLS File Extensions = BAS INC J86 001 002 003 004 005 006 007 008 009 VAR FUN
                        /Colors = 0,8421376,8421376,8421504,255,
                        /Colors Back = 16777215,16777215,16777215,16777215,16777215,
                        /Colors Auto Back = 1,1,1,1,1,
                        /Font Style = 0,0,0,0,0,
                        /Delimiters = ~!@^&*()-+=|\/{}[]:;"'<> ,	?
                        /Function String = "%[ ^t]++^{sub^}^{function^}[ ^t]+^([a-zA-Z_.$?0-9]+^)"
                        /Open Brace Strings = "("
                        /Close Brace Strings = ")"
                        /Open Fold Strings = "FUNCTION" "SUB" "WHILE" "IF" "ENDIF ELSE" "FOR"
                        /Close Fold Strings = "END FUNCTION" "END SUB" "WEND" "ENDIF ELSE" "ENDIF" "NEXT"
                        /Ignore Fold Strings = "EXIT SUB" "EXIT FUNCTION"
                        /C1"Functions" STYLE_FUNCTION Colors = 16711680 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
                        ABS ASC
                        CHR$ COMMAND$ CONCHAR% CONSTAT%
                        DATE$ DISABLE
                        ENABLE ERR ERRF% ERRL ERRN EVENT%
                        FLOAT FRE
                        GET GETLONG
                        INKEY INT INT%
                        LEFT$ LEN LOCK
                        MATCH MFRE MID$ MOD
                        PACK$ PEEK POS PTRRTN
                        RENAME RIGHT$ RND ROUND
                        SADD SGN SHIFT SIZE STR$ STRING$
                        TAB TIME$ TRANSLATE$
                        UCASE$ UNLOCK UNPACK$
                        VAL VARPTR
                        /C2"Keywords" STYLE_KEYWORD Colors = 255 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
                        %INCLUDE
                        ACCESS ASSIGNKEY ASYNC
                        CALL CHAIN CHDIR CLEARS CLOSE COMMON CONSOLE CREATE
                        DATA DEF DELETE DELREC DIM
                        END ENDIF ELSE ERROR EXIT
                        FEND FOR FORM FUNCTION FUNCTIONKEY
                        GOSUB GOTO
                        IF INPUT INTEGER
                        KEYED
                        LET LINE LINK LOAD LOCATE LOCKDEV LOGO LPRINTER
                        MATRIX MKDIR
                        NEXT
                        ON OPEN OPTION
                        POINT POKE POSFILE PRINT PUT PUTLONG
                        RANDOM RANDOMIZE READ REAL REMARK RESTORE RESUME RETURN RMDIR
                        SERIAL SESSION STOP STRING SUB
                        TCLOSE
                        UNLOCKDEV USE USING
                        WAIT WEND WHILE WRITE
                        /C3"Operators" STYLE_OPERATOR Colors = 33023 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
                        (
                        )
                        *
                        +
                        -
                        // /
                        <
                        =
                        >
                        ^
                        AND
                        EQ
                        GE GT
                        LE LT
                        NE NOT
                        OR
                        XOR
                        

                        6,685587
                        Grand MasterGrand Master
                        6,685587

                          May 21, 2009#12

                          I don't now anything about BASIC. Does the keyword BEGIN only exist at end of a line with an IF condition with multiple instructions when the condition is TRUE?

                          /Open Fold Strings = "FUNCTION" "SUB" "WHILE" "BEGIN" "ENDIF ELSE" "FOR"
                          /Close Fold Strings = "END FUNCTION" "END SUB" "WEND" "ENDIF ELSE" "ENDIF" "NEXT"


                          or

                          /Open Fold Strings = "FUNCTION" "SUB" "WHILE" "THEN BEGIN" "ENDIF ELSE" "FOR"
                          /Close Fold Strings = "END FUNCTION" "END SUB" "WEND" "ENDIF ELSE" "ENDIF" "NEXT"


                          works for both examples, but maybe has a bad affect somewhere else.
                          Best regards from an UC/UE/UES for Windows user from Austria

                          18
                          Basic UserBasic User
                          18

                            May 21, 2009#13

                            Your second option seems to work better. I noticed some lingering trouble with the first. Thanks for the assistance! I'll keep tinkering with it and see if I find other problems, but I think it's pretty solid now.