Folding a REBOL function with two blocks

Folding a REBOL function with two blocks

4

    Feb 14, 2019#1

    Hi,

    I have a REBOL wordfile provided by another user. In this language, many structures, like functions, are expressed like:

    myfunctionname: function [some arguments] [some data]
    Or
    myfunctionname: function [some arguments]
    [some data]
    Or
    myfunctionname: function
    [some arguments]
    [some data]

    Actually I see two [+] signs on the left of each block, but I want one that open/closes all blocks.

    rebol_gui1.png (6KiB)

    Note: REBOL could have 

    myfunctionname: function [some arguments] data-container
    or
    myfunctionname: function arguments-container [some data]
    and
    myfunctionname: function arguments-container data-container

    So, the assumption "functions" are always followed by two blocks takes no place here.

    Also, I have the following problem: If the alternate opening/close comment {} (which are also string delimiters), then code folding of a nested block ends just before it.

    rebol_gui2.png (4.97KiB)

    Attached is the actual wordfile and one example REBOL file with an introduction to language structure and all the problems we have.

    Regards,
    Giuseppe Chillemi
    Try-me-rebol.r (4.66 KiB)   11
    Rebol example file
    rebol.uew (9.08 KiB)   12
    Rebol syntax highlighting wordfile

    6,684587
    Grand MasterGrand Master
    6,684587

      Feb 17, 2019#2

      Thank you for the good example file explaining also REBOL syntax. That was a great help.

      I redefined first the first line just to have the standard order and the file extensions listed in alphabetical order.

      Next I removed all color and font style settings using the macro SettingsDelAll from the ultimate syntax highlighting tools package because of color and font style settings for a syntax highlighting language are defined since UltraEdit for Windows in theme settings and no longer read from wordfile.

      Then I executed the macros SortLanguage, TestForDuplicate and TestForInvalid also from the ultimate syntax highlighting tools package The first macro is enhanced by me in the meantime locally for sorting also the delimiters with special algorithm for space and horizontal tab although the delimiters can be specified in any order.

      TestForDuplicate found pi and zero being defined in /C5 and /C9. So I removed them from /C9.

      TestForInvalid found // and <> which I also removed because /<> are word delimiters and so these three characters are highlighted in any case with color group 6 which I renamed from Ops to Operators.

      /C9 was now an empty group and I missed syntax highlighting for ():[]{}. So I renamed color group 9 to Brackets/colon and added those characters to this color group.

      A syntax highlighting language can be defined with no string highlighting at all using keyword Noquote in first line or with single line or multi-line string highlighting with one or two characters marking begin and end of a string. DisableMLS in first line disables multi-line string highlighting while the default EnableMLS enables explicitly multi-line string highlighting. On language having two characters for strings like JavaScript with " and with ' it is possible to specify one of these two string starting/ending characters like a word in a color group to highlight those strings with the color assigned to this color group and the other strings with the color assigned for strings, i.e. "double quoted string" versus 'single quoted string'.

      However, it is not possible to specify that a string starts with character X and ends with character Y. For that reason { and } are defined as alternate block comments which is by default always a multi-line highlighting. Of course an alternate block comment can be folded which means here on { and } being used for a multi-line string that this multi-line string can be also folded. As REBOL interprets { and } also as multi-line comment depending on what is before { makes the alternate block comment definition even right for some cases. It is of course impossible at the moment with UltraEdit for Windows v25.20 that UltraEdit recognizes in which context { and } is used and so highlights everything between those two characters always with the color defined for alternate block comments.


      Code folding

      It is not necessary to define open/close fold strings like open/close brace strings in matching pairs. There can be more open than close fold strings and vice versa. The open/close fold strings can be specified in any order. It is also possible to specify a string as open and as close fold string. Open/close fold strings can contain also word delimiters, even one or more spaces and tabs.

      So I suggest following for coding folding:

      /Open Fold Strings = ": function"
      /Close Fold Strings = ": function"

      Code folding is from one function definition line to next function definition line. The last function in file cannot be folded as there is no more : function.
      A function with name and colon on line X and the keyword function on next line like function f-HIDDEN in example file is ignored by this definition of open/close fold strings. And of course a tab instead of a space or two or more spaces instead of a single space results also in ignoring the function for code folding. So this definition makes sense only when not using all freedoms of REBOL syntax and use strictly : function on the line after function name.

      More flexible is:

      /Open Fold Strings = "function"
      /Close Fold Strings = "function"

      Here is just the keyword function used to define where to start and where to end code folding. So it does not matter anymore where is the colon and how much horizontal or vertical whitespace characters are between colon and keyword function. But if somebody uses the string function with a different meaning in a REBOL file, the code folding would be wrong. However, I suppose that using the string function for something else is in general a bad idea even if it would be possible because of REBOL interpreter takes context into account.

      This is the variant used in rebol.uew inside the attached ZIP file.

      Also possible would be using:

      /Open Fold Strings = ":"
      /Close Fold Strings = ":"

      This results in offering code folding not only for functions, but also for string and block assignments, i.e. everything from one block/function/string assignment to next block/function/string can be folded. I honestly liked this very simple one most as I tested the various open/close folding strings. Why not using code folding for folding also strings and blocks?

      On all three variations of open/close fold strings definitions it is additionally possible to add "[" as open and "]" as close fold strings to be able to fold also everything between square brackets for a two level code folding.


      Function list

      First, there are characters escaped in UltraEdit regular expression strings with ^ which don't need to be escaped. So I removed the unnecessary ^ to get the expressions better readable.

      Second, I could see a space in all character class definitions between a-z and 0-9. I don't think this is right and removed this space from all character class definitions.

      Third, there were too much TGFindBStart and TGFindBEnd. The most outer groups should not have them. So I removed those lines where they were wrong.

      Fourth, the strings assigned to TGFindBStart and TGFindBEnd are interpreted also as regular expression search strings which means [ and ] must be escaped to be interpreted as literal characters in Perl syntax with \ and in UltraEdit syntax with ^.

      Fifth, there are many similarities on the used UltraEdit regular expression search strings and so I decided to switch to more powerful Perl regular expression to reduce the number of regular expression search strings which results in faster processing a file for strings to display in function list view.

      The last problem was your wish to show a hierarchical object/method definition also hierarchical in function list view. REBOL supports obviously a recursive definition of objects inside objects with each object having its own methods. The function list feature of UltraEdit does not support recursion. That would require parsing the file like REBOL interpreter obviously does with real language parsing knowledge instead of using regular expression searches on file without language parsing knowledge.

      I have nevertheless tried to fulfill your wish for two levels by taking indentation level into account. I assumed either one horizontal tab or four spaces are used for indentation by one level. This indentation rule defined by me is not valid for fobj2: function which is indented by three tabs instead of two tabs which is the reason for fobj2 method not shown in function list for Subobject obj2.

      An object and a function on first level must be defined at beginning of a line without any leading tabs/spaces. A subobject or a method being part of an object must be on a line with either one tab or four spaces. And a method of a subobject must be on a line with two tabs or 8 spaces.

      Something better is not possible because of recursion is not supported for searching for strings to list hierarchical in function list view. It is the first time that I see a language which uses recursion in source code file itself for definition of hierarchical objects with their methods.

      In case of a hierarchical function list for hierarchical objects with their methods is not so important for you as added to attached wordfile, here are the function strings for a non-hierarchical display of objects and their methods in function list view whereby fobj2 is listed twice, once for object obj1 which of course is not right and once more for obj2 which is right. I don't have an idea how to exclude fobj2 in methods list of obj1 without taking indentation into account.

      Code: Select all

      /TGBegin "Does"
      /TGFindStr = "^(?:%|[\t ]*do)[\t ]+(?:%"?|to-file[!\s]+|to-rebol-file["\s]+)([0-9a-z!&'*+\-.=?_~]+)"
      /TGEnd
      /TGBegin "Dynamic Includes"
      /TGFindStr = "^[\t ]*include[ /]+([0-9a-z!%&'*+\-./=?_~]+)"
      /TGEnd
      /TGBegin "Static Includes"
      /TGFindStr = "^[\t ]*#include[ \-]+([0-9a-z!%&'*+\-./=?_~]+)"
      /TGEnd
      /TGBegin "Objects"
      /TGFindStr = "^[\t ]*([0-9a-z!&'*+\-.=?_~]+):\s+(?:construct\>|context\>|make object!)"
      /TGFindStr = "^set[\t ]+'([0-9a-z!&'*+\-.=?_~]+)\s+(?:construct\>|context\>|func\>|does\>|make object!)"
      /TGBegin "Methods"
      /TGFindStr = "^[\t ]*([0-9a-z!&'*+\-.=?_~]+):\s+(?:function|func|does)\>"
      /TGFindBStart = "\["
      /TGFindBEnd = "\]"
      /TGEnd
      /TGEnd
      /TGBegin "Functions"
      /TGFindStr = "^[\t ]*([0-9a-z!&'*+\-.=?_~]+):\s+(?:function\>|func\>|does\>|make function!|has\>)"
      /TGFindStr = "^set[\t ]+'([0-9a-z!&'*+\-.=?_~]+\s+(?:{function\>|make function!|\has\>)"
      /TGEnd
      
      It could be possible to use just one Perl regular expression search string for objects and for functions, but I would need examples for objects and methods defined with set ' at beginning of a line to define and validate the regular expression and avoid false positive matches. Well, false positive matches could occur already with the reduced number of search strings because of they find most likely some very special constructs which are not valid for REBOL interpreter. But I think a faster search for strings to list in function list is for REBOL code writers more important than using multiple regular expression search strings to avoid false positive matches on constructs which a REBOL code writer never uses in REBOL code files and so are only theoretically but not practically relevant.


      Please let me know if you detect an issue on which I could help to fix it or if you have more REBOL syntax highlighting wishes on which I could help to implement them.
      rebol_v1.zip (3.13 KiB)   16
      Updated wordfile for REBOL with the described modifications.
      Best regards from an UC/UE/UES for Windows user from Austria

      4

        Feb 17, 2019#3

        What a great reply !
        It will take time to read and test carefully everything but here is my big thank you for your support !

        Regards,
           Giuseppe Chillemi

        1
        NewbieNewbie
        1

          Feb 20, 2019#4

          @Mofi, fantastic support indeed! Thanks so much. I also need to take time to digest it, and then see about updating my local wordfile for Red and Rebol.

          4

            Oct 13, 2019#5

            Hi,

             I have found a glitch I am not able to solve:

            Functions listing is working outside object creation but inside an object, where they are see as method, the syntax stop listing when encounter this construct:

            Code: Select all

            b: func [any-arg] [
            ]
            
            While this works:

            Code: Select all

            b: func [any-arg] 
            [
            ]
            
            Here is an example:

            SG-Stop.red (248 Bytes)   0

            Here is its output. As you can see, 'C' inside objects is not listed.

            MissingC.png (6KiB)

            When used outside a method both works.

            I have included the wordfile which generates errors.

            Could you please help?

            A last request:

            I would like to have {} enclosed string of the same color of "" enclosed strings. Is there any way? (Comments in RED/REBOL are defined as "comment {}" with no double quotes and I need they remain of a different color than strings.)

            Regards, Giuseppe Chillemi
            rebol_wrong_sh.uew (7.12 KiB)   0

            6,684587
            Grand MasterGrand Master
            6,684587

              Oct 14, 2019#6

              The issue with not finding all methods of an object was forwarded by me with an issue report sent by email to IDM support. I could not find a working solution. The attached RAR archive file contains the issue report and the wordfile and the example file sent by me to IDM support.

              For syntax highlighting of strings starting with { and ending with } highlighted as alternate block comments select ribbon tab Layout. The second item Themes in first group Look and feel has a down arrow. Click on this arrow to open a pop-up menu to see the pre-installed themes and at top Manage themes.

              Clicking on the item Themes or the first menu item Manage themes in the pop-up menu opens Manage Themes dialog. Select tab Syntax. Select next the language REBOL. Configure the colors for Alternate Block Comments to the same colors as configured for Strings. The chosen colors are immediately applied on text in active file below the dialog window on having the magnifying glass symbol activated at bottom left edge as by default without saving the modification. The modifications are saved on clicking on button Apply (save and keep dialog window open) or button OK (save and close dialog window).

              The same command is available on using toolbar/menu mode with contemporary menus by clicking in menu Layout on submenu Themes.

              The submenu Themes is in menu View on using toolbar/menu mode with traditional menus.

              The user interface mode can be changed at any time by right clicking on ribbon, menu or toolbar and clicking in context menu on appropriate command to change the mode.
              rebol_function_list_issue.zip (4.65 KiB)   0
              REBOL function list issue report sent to IDM support.
              Best regards from an UC/UE/UES for Windows user from Austria

              4

                Nov 01, 2019#7

                Thanks, I hope IDM Team will find a solution.