Community
    • Login

    FunctionList Confused

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    82 Posts 5 Posters 20.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Lycan ThropeL
      Lycan Thrope @Lycan Thrope
      last edited by

      @lycan-thrope
      Okay, it’s a New Year. Back to the regex stuff. :-)

      I’m trying to remove the Parens from around the this naming that shows the objects in our FunctionList, and am trying to pick off the end name or any combination to display without the this. I came up with this regex, that seems to do the job of isolating the last word in the parens and capture it in it’s own capture group, but I seem to be having trouble making it work in side of the functionList regex.

      ([.](\w+)\))

      As this screenshot of Regex101.com shows:
      FLRegexminusparens.PNG

      This is what comes up with your regex:
      FLTreeWithoutTryingCaptureGroupassign.PNG

      And what it shows when I try just assigning capture group 2 for the id with this ([.](\w+)\)) \2 in place of your \( *.? \) regex:
      FLTreeTryingCaptureGroupassign.PNG

      The problem seems to come when I try anything other than the original regex you developed Peter. I tried a couple of things to try and give an option of either this last word or this…kind of like (this | ([.](\w+)\)) and most often it comes up with the first (this) object and nothing else, or nothing at all, only functions. Is there a way to isolate the names without the this and the parens like a look-behind thing or am I way off base here?

      Lee

      Lycan ThropeL 1 Reply Last reply Reply Quote 0
      • Lycan ThropeL
        Lycan Thrope @Lycan Thrope
        last edited by

        @lycan-thrope
        By the way, the only thing that really changed, was that I got rid of the \K and allowed the Function or Procedure to be included with it’s name. One of the users who has a lot of old dBASE code that he’s porting over to the dBASEPlus has the differentiations, and this helps him quickly identify renaming or recoding the differently named identifiers. We found and he liked this quirk that the Functions inside comments was doing as he was able to identify them by doing that, but until you showed me how to fix it, he was going to wait until I was able to change it, and once I got the Autocompletion done, it was a matter of minutes before I figured out what to do to return that functionality for him and he’s really grateful for the ability to discern them now. :-) You’ve a big help already to our community, so thanks.

        Lee

        Lycan ThropeL 1 Reply Last reply Reply Quote 0
        • Lycan ThropeL
          Lycan Thrope @Lycan Thrope
          last edited by

          @lycan-thrope
          Never mind, just saw this section of the FunctionList explanation.
          The parser can only search for function names, it will not do regular expression replacement or modification (so you cannot add text to the matching names)

          I guess the question becomes, is there a way to isolate those sections that I do want with regex, and then pose a selection choice this| (foundtext) depending on if there are other names are not.

          Lee

          Lycan ThropeL 1 Reply Last reply Reply Quote 0
          • Lycan ThropeL
            Lycan Thrope @Lycan Thrope
            last edited by

            @lycan-thrope
            Well, I have hope I’m on to something here. Tried a different site to explain some of the look ahead/behind stuff and managed to come up with something that half works. :-)

            The first half works in that it changes (this) to this in the functionList panel for the first object which is the Form itself. I used this regex, probably improperly or need to phrase it differently\(\Kthis(?=\))|[.]\K\w+(?=\)) but the OR condition didn’t take, or it did but since the other objects have this with a dot in it, it disqualifed the condition and threw out the final objects instead. So now this:
             So now this:

            Looks like this:
            ARegexthis.PNG

            I need to figure out how to make the regex choose between supplying the captured group of either this by it’s self, OR if a match works that ends with a dotWordclosingparen, it displays just the word for that Object.

            If the above screenshot, the (this.TESTCONTAINER.VSCROLLBAR1) is a child object of the TESTCONTAINER, but…the VSCROLLBAR1 is an obect in it’s self. If I can capture the whole thing after this without the parens, but the dot between the two objects that would be considered a success since it at least cleans it up, but I am tryig to just pick off the last object name so the list would just include the objects themselves for navigation purposes when using the FunctionList panel…so I’m still working on it, trying to see how to make it work.

            Lee

            Lycan ThropeL 1 Reply Last reply Reply Quote 0
            • Lycan ThropeL
              Lycan Thrope @Lycan Thrope
              last edited by

              @lycan-thrope
              Interesting, reversing a different, but similar regex gets me the VSCROLLBAR1 but nothing else. Hmm… I guess the or operator is not going to get this job done. Hmm.

              Lycan ThropeL 1 Reply Last reply Reply Quote 0
              • Lycan ThropeL
                Lycan Thrope @Lycan Thrope
                last edited by

                @lycan-thrope

                Okay, now we’re cooking with gas. :-)

                I figured out how to exclude the parens with \K(.*?)(?=\)) and here’s what it looks like:
                FLRegexminusparensAccomplished.PNG

                I fear, however, keeping the this for the first object, and removing it from the rest is going to be a bit harder…but maybe not if I can figure out how to make the or work and figure out how to keep the this keyword if followed by the closing paren, but not if it’s follow by a dot operator, and use the rest of the object description instead. This is kind of fun…and kind of frustrating at the same time. :-)

                Lee

                Lycan ThropeL 1 Reply Last reply Reply Quote 0
                • Lycan ThropeL
                  Lycan Thrope @Lycan Thrope
                  last edited by

                  @lycan-thrope
                  Any chance that there is an IF/ELSE kind of Regex construction that the FunctionList parser will accept, instead of selecting a capture group, or using OR(|)?

                  Lee

                  Lycan ThropeL 1 Reply Last reply Reply Quote 0
                  • Lycan ThropeL
                    Lycan Thrope @Lycan Thrope
                    last edited by

                    @lycan-thrope
                    Well, success for the most part for the original goals. :-)

                    Of course, as usual, goals shift. :-)

                    I used Peter’s or break down and added additional ones that started with the longest number (in this case, and unfortunately only this case) 3, and had two more or’s with the whole regex up to the point of the opening parens being starting the reset, and changed the capture portion.
                    \Kthis\.\w+\.\K\w+(?=\))|\)this\.\K\w+(?=\.)|\(\Kthis(?=\)) picks off the longest extended name and does it first, followed by the next section with this regex:
                    \Kthis\.\K\w+(?=\)) to pick off any objects immediately after the dot operator following this to capture that object and then folowed by:
                    \K(.*?)(?=\)) which captures the this object before the closing parens.

                    Screenshot of new FunctionList panel at work:
                    FLObjectListSuccess.PNG
                    So this was the original hope of being able to do, but after looking at it, since I can’t do replacement text, it makes sense to keep the object list together past the first one following the this, as that denotes a parent object TESTCONTAINER and the lineage to the child object VSCROLLBAR1.

                    So now my next goal, is to try and check after the initial object after the superparent this is set alone to allow any other objects that have children to continue being sucked into the capture and listed as is, in this case TESTCONTAINER.VSCROLLBAR1. So back to the drawing board on figure out how to test for a following dot operator without stopping the accumulation from stopping at the point. The look-ahead (positive?) worked to identify and not include the closing paren or the dot operator, so now to test a negative lookahead?

                    Thanks for help so far Peter, et al. It’s fun again for the moment. :-)

                    Lee

                    1 Reply Last reply Reply Quote 0
                    • guy038G
                      guy038
                      last edited by guy038

                      Hello, @lycan-thrope and All,

                      First I would say that, again, I was completely mistaken in this post, too :

                      https://community.notepad-plus-plus.org/post/72550

                      So, just forget my two previous posts and follow this simple rule to not add any code definition in comments, whatever the language used ( built_in or user-defined ) !


                      Now, regarding your IF/ELSE kind of Regex construction, there is, indeed, a valid IF THEN / ELSE regex contruction ! Its general syntax is :

                      (?ConditionTHEN_part) OR (?ConditionTHEN_part|ELSE_part), where condition is either :

                      • A previous defined group, named or not

                      • A look-around feature

                      • A recursive pattern

                      Two simple examples :

                      • The regex (TEST)?123(?(1)===|---)456 matches the TEST123===456 string and any 123—456 string, whatever occurs before the 123 part
                      TEST123===456
                      abc123---456
                      xyz123---456
                      
                      • The regex ___((?=TEST)TEST12345|67890)___ matches the two strings ___TEST12345___ and ___67890___
                      ___TEST12345___
                      ___67890___
                      

                      Back to your dbasePlus.xml parser and assuming these conditions :

                      • I just associated Normal text to your dbasePlus.xml parser :
                      		<association id= "dbaseplus.xml"  	 langID= "0"/>	<!-- Normal Text ID  -->
                      

                      I used this modified version :

                      <?xml version="1.0" encoding="UTF-8" ?>
                      <!-- ==========================================================================\
                      |
                      |   To learn how to make your own language parser, please check the following
                      |   link:
                      |       https://npp-user-manual.org/docs/function-list/
                      |
                      \=========================================================================== -->
                      <NotepadPlus>
                      	<functionList>
                      		<!-- ========================================================= [ dBASEPlus ] -->
                      		<parser
                      			displayName="dBASEPlus"
                      			id         ="dbaseplus"
                      			commentExpr="(?s:/\*.*?\*/)|(?-s)^(//|&&).*"
                      		>
                      			<classRange
                      				mainExpr="(?x-i)                        #  Free-spacing mode and inline comments + search sensitive to case
                      
                      						  ^\h*                          #  Optional leading whitespace chars
                      						  class                         #  'class' keyword
                      						  \h?                           #  Optional whitepace char
                      						  \w+                           #  Class name
                      
                      														#  Following the class name there is the option of parameters, and if so the first entry inside the parens is required, whether there is other 
                      														#  parameters or not, once the parens go up, the first is required. ie: class FrameCtrl(frameObj)
                      
                      						  (                             #  Beginning of the optional parameter(s) part  ( Group 1 )
                      							\h? \(                      #    Opening parenthesis
                      							\w+                         #    First and required parameter
                      							( , \h? \w+)*               #    Following optional/additional parameters
                      							\)                          #    Closing  parenthesis
                      						  )?                            #  End of the optional parameter(s) part
                      
                      														#  For the rest of the class declaration, after the class name, all other options are part of one big optional set, that follows 'of'
                      														#  and can be populated by one of several options.
                      
                      						  (?:                           #  Beginning of the main optional part, in a non-capturing group
                      
                      														#    The first and most prevalent is the Superclass name that the class is being subclassed from, and it's options of parameters and again, 
                      														#    if it has parameters, at least the first one is required ie.: class ToolButtonFx(oParent) of Toolbutton(oParent).
                      
                      							\h of \h                    #    Optional 'of' keyword, surrounded by 1 horizontal whitespace char
                      							\w+                         #    Superclass name
                      
                      							(?1)?                       #    Optional parameter(s) part ( Subroutine call to Group 1 )
                      
                      														#    The next possible option is that it is a custom object and needs to be in this line so if the object or form is opened up in the dBASE IDE,
                      														#    the designers in it won't mess up the object by streaming out missing parts or overriding properties or objects and functions.
                      
                      							( \h custom )?              #    Optional 'custom' keyword 
                      
                      														#    The next possible option is that the class is being subclassed from another object that is contained elsewhere and the compiler needs to know
                      														#    this reference. There are two options for pointing to the file. The first is an Alias path in the IDE that can be accessed by the compiler
                      														#    in the environment, or second, it is in the current directory and only the name is needed...or it has a path that can be listed here,
                      														#    but this is bad practice, and an Alias is recommended if the file is in a place other than the current directory. If it is, the name can be
                      														#    used in quotes as a string that gets passed to the compiler. Both follow the word 'From'. The Alias directory is a name that is enclosed
                      														#    in two colons, one immediately before the Alias name and one immediately after, no spaces.
                      
                      							(?:                         #    Beginning of the optional part, in a non-capturing group
                      							  \h from \h                #      Optional 'from' keyword, surrounded by 1 horizontal whitespace char
                      
                      							  (?:                       #    Beginning of a non-capturing group
                      								  : \w+ : \w+ \. \w+    #        First pointing file case
                      								|                       #      OR
                      								  \x22 \w+ \. \w+ \x22  #        Second pointing file case
                      							  )                         #    End of a non-capturing group
                      
                      							)?                          #    End of the optional part
                      
                      						  )?                            #  End of the main optional part
                      
                      						  $                             #  End of current line and end of the class declaration
                      
                      						  (?s:.*?^\h*endclass)          #  must match all the way to 'endclass'
                      
                      
                      						 "
                      
                      				 closeSymbole="endclass"
                      			>
                      				<className>
                      					<nameExpr
                      						expr="(?x-i)                    #  Free-spacing mode and inline comments and search sensible to case
                      						      \h*                       #  Optional leading whitespace chars
                      						      class                     #  'class' keyword
                      						      \h?                       #  Optional whitepace char
                      						      \K\w+                     #  Pure class name
                      						     "
                      					/>
                      					
                      				</className>
                      			<function
                      					mainExpr="(?x-s) 
                      									
                      									\h* 
                      									(?:
                      									
                      									function \h+ \w+
                      									|
                      									procedure \h+ \w+
                      									|
                      									with \h+ .+
                      								)
                      								\h*
                      							"
                      				>
                      					<functionName>
                      						<funcNameExpr expr="(?x-s)			# multiline/comments
                      															# (! // | && | * ) trying to keep following keywords from being included in comments
                      								\h*							# allow leading spaces
                      								(?:
                      									
                      									function				# must have word 'function' as first word
                      									\h+						# must have at least one horizontal space after function
                      									\K 						# don't keep 'function' in the name of the function in the panel
                      									\w+						# the name of the function is the first whole word after 'function'
                      								|
                      									procedure				# must have word 'procedure' as first word
                      									\h+      				# must have at least one horizontal space after procedure
                      									\K       				# don't keep 'procedure' in the name of the function in the panel
                      									(!to)\w+ 				# the name of the function is the first whole word after 'procedure' - 'to'
                      															# so as to exclude any 'set procedure to' statements, needs work though.
                      								|
                      									with					# must have word 'with' as first word
                      									\h+						# must have at least one horizontal space after function
                      									\K 						# don't keep 'with' in the name of the function in the panel
                      									((?=\(this\))\(this\)|.+)$  # If '(this)' exits at CURRENT position then select it ELSE select any NON NULL string till END of LINE
                      								)
                      							"
                      						/>
                      					</functionName>
                      				</function>
                      			</classRange>
                      			<function
                      					mainExpr="(?x-s) 
                      									
                      									\h* 
                      									(?:
                      									function \h+ \w+
                      									|
                      									procedure \h+ \w+
                      									|
                      									with \h+ .+
                      								)
                      								\h*
                      							"
                      				>
                      					<functionName>
                      						<nameExpr expr="(?x-s)			# multiline/comments
                      								
                      								\h*							# allow leading spaces
                      								(?:
                      									function				# must have word 'function' as first word
                      									\h+						# must have at least one horizontal space after function
                      									\K 						# don't keep 'function' in the name of the function in the panel
                      									\w+						# the name of the function is the first whole word after 'function'
                      								|
                      									procedure
                      									\h+
                      									\K
                      									(!to)\w+
                      								|
                      									with					    # must have word 'with' as first word
                      									\h+						    # must have at least one horizontal space after function
                      									\K 						    # don't keep 'with' in the name of the function in the panel
                      									((?=\(this\))\(this\)|.+)$  # If '(this)' exits at CURRENT position then select it ELSE select any NON NULL string till END of LINE
                      								)
                      							"
                      						/>
                      					</functionName>
                      				</function>
                      		</parser>
                      	</functionList>
                      </NotepadPlus>
                      

                      Important note : That it’s just a first try to give you some ideas !

                      I supposed that, when using the with syntax, you would want either :

                      • To see the (this) part if it exists

                      • To see anything till the end of line if the (this) part is absent, after the with and the blank char

                      And I did the modifications, both in the classRange part and in the function parts , using an IF...THEN...ELSE... construction :

                      									((?=\(this\))\(this\)|.+)$  # If '(this)' exits at CURRENT position then select it ELSE select any NON NULL string till END of LINE
                      

                      Of course, in order that the parser work properly, I had to change this line in the two mainExpr parts :

                      									with \h+ .+      #  INSTEAD of :   with \h+ \(.*?\)
                      

                      Now, I used the test file, below :

                      /*Test_1  OK
                      */
                      
                      /* Test_2  OK
                       */
                      
                      /*  Test_3  OK
                      */
                      
                      
                      //Test_4  OK
                      
                      // Test_5  OK
                      
                      //  Test_6  OK
                      
                      
                      &&Test_7  OK
                      
                      && Test_8  OK
                      
                      &&  Test_9  OK
                      
                      
                      class ABC
                      	bla
                      	blah
                      	function foo
                      		bla
                      		bla
                      		blah
                      		with ($^|]!:Test__--~
                      	blah
                      	bla
                      endclass
                      
                      class XYZ
                      	bla
                      	function 123
                      	bla
                          blah
                      	with (this)
                      	blah
                      endclass
                      BLA
                      
                      function bar
                      bla
                      blah
                      
                      	with (this)
                      bla
                      blaH
                      with (.This.TESTCONTAINER.)
                      bla
                      blah
                      

                      • It correctly avoids all the comment lines, at beginning of file

                      • It correctly displays the classes ABC and XYZ

                      • It correctly displays the functions foo and 123

                      And regarding the modified part :

                      • If the (this) part exists, after with, it correctly displays (this) ( method (this), in the XYZ class and single function this )

                      • If the (this) part is absent, after with, it correctly displays all the characters till end of line ( method ($^|]!:Test__--~, in the ABC class and the single function (.This.TESTCONTAINER.)


                      Here is a screenshot :

                      4b661779-3979-428f-a13b-d8dbb197f762-image.png


                      Please, take time to re-read this post ! Not easy to catch everything at first glance !

                      Best Regards,

                      guy038

                      Lycan ThropeL 1 Reply Last reply Reply Quote 1
                      • Lycan ThropeL
                        Lycan Thrope @guy038
                        last edited by

                        @guy038 ,

                        Thank you. Now, I will have to look at your code, but while I was signed out, I had another one of those epiphany things. :-)

                        Figured it out with the reduced complexity by allowing everything after the this and stopping before the \) with the lookahead, by using this regex:
                        \Kthis\.\K(.+)(?=\)) By doing this I was able to remove the longer more complex one that only went 3 levels deep, and reducing my or construct by one or level. This is what I can get now:
                        FLObjectListSuccess2.PNG

                        I think I have a problem with overthinking things. :-) I was looking for the one you showed up there, and I might still be able to use it, somewhere else, so thanks.

                        Lee

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors