Community
    • Login

    Function list with PHP with abstract functions

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 3.2k 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.
    • Florent PagèsF
      Florent Pagès
      last edited by Florent Pagès

      I use function list with PHP files with abstract class.

      But abstract functions are not shown in the tree view.

      I have try to fix the functionList.xml file but a round bracket left in each class member in the treeview like : “GetPresentation(” instead of “GetPresentation”

      Sample of abstract class and function in php

      abstract class PageZZZ extends PageAAA {
      	abstract public function GetPresentation();
      	function MetaCSS() {
      		return '<link rel="stylesheet" type="text/css"  href="zzz.css" media="all" >';	
      	}	
      }
      

      in order to view GetPresentation in the function list i have done that in function list :

      In the parser php_function > classRange > function

      I replace

      				<function
      					mainExpr="^\s*((static|public|protected|private|final)*(\s+(static|public|protected|private|final))+\s+)?(function\s+)+(\w+(\s+\w+)?(\s+|\*\s+|\s+\*|\s+\*\s+))?(\w+\s*::)?(?!(if|while|for|switch))[\w~]+\s*\([^\{]*\{"
      				>
      					<functionName>
      						<funcNameExpr expr="(?!(if|while|for|switch))\w+\s*\([^\{]*" />
      						<!-- comment out the following node to display the method with parameters -->
      						<funcNameExpr expr="(?!(if|while|for|switch))\w+" />
      					</functionName>
      				</function>
      

      by

                      <function
      	mainExpr="^[\s]*((abstract|static|public|protected|private|final)\s+)*(function)\s+([\w]+[\w\d_]*)\s*\("
      				>
                         <functionName>
                            <funcNameExpr 
      	 expr="(?!(abstract|static|public|protected|private|final)function)[\w_]+[\s]*\("  
      					  /> 		
                          <!--    comment below node if want display method with parmas 
                               <funcNameExpr expr="(?!(if|while|for|switch))[\w_]+"/>  --> 
                          </functionName>
                      </function>
      

      it’s seem to work but an additionnal “(” appear.

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

        Hello, Florent,

        The solution consists to change the end of the expr attribute but a positive look-ahead , (?=\() , instead of the \( form !

        So expr="(?!(abstract|static|public|protected|private|final)function)[\w_]+[\s]*(?=\()"


        Secondly, I try to simplify, a bit, your two regexes :

        • The \s, \d, \w can be written, outside a class character. So, for instance, the syntax \s* is strictly equivalent to the [\s]* one !

        • The \w syntax is a single word character, and is equivalent to the class character [\d_\u\l. That is to say it represents any single digit OR the underscore character OR any upper-case letter, accentuated or not OR any lower-case letter, accentuated or not

        • I also deleted some round brackets couples as they create groups, which are not used later on, anyway !

        • Finally, I suppose, like in most languages, that the first character of a function name must be a letter or an underscore ( Thanks to MAPJe71 ) and all the other characters, of the name, are, simply, word characters


        If so, the mainExpr attribute can be simplified into :

        ^\s*((abstract|static|public|protected|private|final)\s+)*function\s+[\u\l_]\w*\s*\(

        And the expr attribute is, simply :

        (?!(abstract|static|public|protected|private|final)function)\w+\s*(?=\()

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • MAPJe71M
          MAPJe71
          last edited by

          First character of a function name can also be an underscore.

          1 Reply Last reply Reply Quote 0
          • Florent PagèsF
            Florent Pagès
            last edited by

            Thanks guy038 and MAPJe71 for this precious help.

            It’s works geat.

            In addition,

            constructors are like :

            	function __construct() {  ... }
            

            So MAPJe71 is right a function can start with “_”

            According to that remark, i change [\u\l] to [\u\l_] in mainExpr :

            	mainExpr="^\s*((abstract|static|public|protected|private|final)\s+)*function\s+[\u\l_]\w*\s*\("
            

            REM : The functionListxml in the 7.2.2 zip file containts really different RE

            				<function
            					mainExpr="^\s*((static|public|protected|private|final)*(\s+(static|public|protected|private|final))+\s+)?(function\s+)+(\w+(\s+\w+)?(\s+|\*\s+|\s+\*|\s+\*\s+))?(\w+\s*::)?(?!(if|while|for|switch))[\w~]+\s*\([^\{]*\{"
            				>
            					<functionName>
            						<funcNameExpr expr="(?!(if|while|for|switch))\w+\s*\([^\{]*" />
            						<!-- comment out the following node to display the method with parameters -->
            						<funcNameExpr expr="(?!(if|while|for|switch))\w+" />
            					</functionName>
            				</function>
            
            1 Reply Last reply Reply Quote 0
            • MAPJe71M
              MAPJe71
              last edited by

              The functionListxml in the 7.2.2 zip file containts really different RE

              That’s correct and it will change in the near future.

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

                Florent and MAPJe71,

                Thanks to you, both, for this this precision ! So, I’ve just updated my previous mail !

                And, after added your last example function __construct() { … }, in a new PHP file, the __construct function does appear, too, in the FunctionList panel :-)

                Cheers,

                guy038

                BTW, I don’t know the PHP language, at all, but, about regexes, up to now, I can manage ;-))

                1 Reply Last reply Reply Quote 0
                • Florent PagèsF
                  Florent Pagès
                  last edited by

                  Nice!

                  RE seem to be so powerful.

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