Community
    • Login

    Function List able to show PHP Comments?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 5 Posters 1.1k 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.
    • stephan-romhartS
      stephan-romhart @PeterJones
      last edited by

      @peterjones hello Peter, thank you for your post.
      I did not get it work in the stanard php.xml
      The mainExpr-Term is very very big.
      Have I to add the “sub” before the regex and the “|” pipe means OR ?
      :-)

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @stephan-romhart
        last edited by

        @stephan-romhart ,

        No offence, but if you don’t know that | means OR in regular expressions, you have some studying to do before you can be effective at manipulating Function List regex. The forum has a FAQ about regular expressions, and the online User Manual (npp-user-manual.org, linked to in the ? menu in Notepad++) has a large page on regular expressions.

        Unfortunately, I am swamped right now, so cannot do more than point you to that documentation. Maybe another regex guru with more time will be able to hand you a working expression that takes the existing php function list and adds the ability to list ### comments as functions as well in the next couple days…

        Alex Sunny 0A stephan-romhartS 2 Replies Last reply Reply Quote 2
        • Alex Sunny 0A
          Alex Sunny 0 @PeterJones
          last edited by

          @peterjones said in Function List able to show PHP Comments?:

          @stephan-romhart ,
          No offence, but if you don’t know that | means OR in regular expressions, you have some studying to do before you can be effective at manipulating Function List regex. The forum has a FAQ about regular expressions, and the online User Manual (npp-user-manual.org, linked to in the ? menu in Notepad++) has a large page on regular expressions.
          Unfortunately, I am swamped right now, so cannot do more than point you to that documentation. Maybe another regex guru with more time will be able to hand you a working expression that takes the existing php function list and adds the ability to list ### comments as functions as well in the next couple days…

          thanks my issue has been fixed.

          1 Reply Last reply Reply Quote 0
          • stephan-romhartS
            stephan-romhart @PeterJones
            last edited by

            @peterjones Thank you :-)

            Stephan Romhart 0S 1 Reply Last reply Reply Quote 0
            • Stephan Romhart 0S
              Stephan Romhart 0 @stephan-romhart
              last edited by

              @stephan-romhart

              Sorry could not log in with my twitter…

              Probably somebody could help me?
              I still try to get

              function name(){
              }
              

              and

              ### comment
              

              shown in the function list.

              My current code:

              <functionName mainExpr="function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*">
                  <nameExpr expr="[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{" />
                  <nameExpr expr="###.*?$" />
              </functionName>
              

              How can I tell the function list to use first nameExpr for left side of the “or” regex and last nameExpr for the right side?

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Stephan Romhart 0
                last edited by PeterJones

                @Stephan-Romhart-0 ,

                Sorry could not log in with my twitter…

                Yeah, it appears Twitter stopped providing OAuth some time ago (Feb 9)

                How can I tell the function list to use first nameExpr for left side of the “or” regex and last nameExpr for the right side?

                My experiments today could not get anything to work when I have two separate <nameExpr> tags. I thought it used to (and that’s what I have documented), but I couldn’t get that to work; maybe @MAPJe71 can chime in whether or not it’s really expected to work with multiple <nameExpr> tags (and if not, I need to fix the documentation).

                For a simple example, I made one that looked for either function or ### and grabbed that and everything after it on the line, using a single expression rather than trying two – it is just a simple Function Parser, not a Class Parser or Mixed Parser.

                One thing I found while doing that: the functionList parser appears to have a problem with the # in the expression unless I manually turn off extended mode (?-x); I thought it used to be the other way around, but maybe something changed. (My advice when doing functionList definitions is to always be explicit about your desires for at least the s (. matches newline) and x (extended spaces and comments) options by using the (?...-...) syntax.

                91a2516f-15c4-4f70-bfb6-c4f657993dad-image.png
                text to grab functions from

                this is text
                ### comment
                #sub here
                sub one
                function xyz
                this is text
                    function pdq
                this is text
                ### comment
                sub two
                #sub there
                function name(){
                }
                

                parser.xml

                <?xml version="1.0" encoding="UTF-8"?>
                <NotepadPlus>
                    <functionList>
                            <parser
                                id="fn_normal"
                                displayName="Normal (plain text)"
                            >
                                <function
                                    mainExpr="(?-sx)^\h*\bfunction.*$|^###.*$"
                                >
                                    <functionName>
                                        <nameExpr expr="(?-sx)^\h*\K\bfunction.*$|^###.*$" />
                                    </functionName>
                                </function>
                            </parser>
                    </functionList>
                </NotepadPlus>
                

                Once you get something simple like that working, then slowly add back in the added complexities, it might work for you.

                BTW: I tried your mainExpr value in just a Notepad++ FIND-dialog regex search, and it found things okay, but it claimed your first expr was not a valid regex – I don’t know whether you really had backslash-bracket in your expression someplace, which the forum messes up, or whether you have a bad regex there. But if a regex doesn’t work in Notepad++'s find dialog, it won’t work in your functionList definition, either.

                I went back to your mainExpr, duplicated that as the Expr, and then tweaked it until it stripped the function prefix

                <?xml version="1.0" encoding="UTF-8"?>
                <NotepadPlus>
                    <functionList>
                            <parser
                                id="fn_normal"
                                displayName="Normal (plain text)"
                            >
                                <function
                                    mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*"
                                >
                                    <functionName>
                                        <nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|^###.*" />
                                    </functionName>
                                </function>
                            </parser>
                    </functionList>
                </NotepadPlus>
                

                And it now restricts it to the name(){ rather than my two dummy functions which don’t match your definitions:
                41d3d19a-4798-4709-ad4a-8f2ae3236255-image.png

                Similar regex should work in the function-section of a Class or Mixed parser, too, but you’ll have to make sure to use the right element names (the elements inside a <classRange><function> are different than the elements inside a top-level <function> element).

                Stephan Romhart 0S MAPJe71M 2 Replies Last reply Reply Quote 2
                • Stephan Romhart 0S
                  Stephan Romhart 0 @PeterJones
                  last edited by

                  @PeterJones Thank you very much! It works perfectly.

                  			<function mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###.*">
                  				<functionName>
                  					<nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx).*" />
                  				</functionName>
                  			</function>
                  

                  I changed the ^ to (?-sx), so comments can be indented.

                  The question is, how can I strip the ### in the function list?
                  I did not understand how to remove some string with the expr.

                  Is this done through groups with ()?
                  If so how can I adress them in the nameExpr?

                  Stephan Romhart 0S 1 Reply Last reply Reply Quote 0
                  • Stephan Romhart 0S
                    Stephan Romhart 0 @Stephan Romhart 0
                    last edited by

                    @Stephan-Romhart-0 I found it out!
                    With \K as Meta Escape:

                    \K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match.

                    			<function mainExpr="(?-sx)function(\s+[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###.*">
                    				<functionName>
                    					<nameExpr expr="(?-sx)function(\s+\K[A-Za-z_$][\w$]*)?\s*\([^\)\(]*\)[\n\s]*\{|(?-sx)###\K.*" />
                    				</functionName>
                    			</function>
                    

                    So my Functionlist shows now alle PHP functions and all Comments!
                    Thank you again, Peter!

                    1 Reply Last reply Reply Quote 3
                    • MAPJe71M
                      MAPJe71 @PeterJones
                      last edited by

                      @PeterJones

                      The result of a <nameExpr .. /> is the input for the next <nameExpr ... /> i.e. they work in series, not parallel.

                      Stephan Romhart 0S 1 Reply Last reply Reply Quote 2
                      • Stephan Romhart 0S
                        Stephan Romhart 0 @MAPJe71
                        last edited by

                        @MAPJe71 Thank you!

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