Community
    • Login

    Regex help needed editing the function list xml file

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 1.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.
    • Thomas AnT
      Thomas An
      last edited by Thomas An

      I am trying to edit the Notepad++ xml file to display a Javascript “class” (prototype functions) hierarchy as nodes and have (preferably) the public methods nested underneath and the private methods also displayed in the tree

      The objective is to have it recognize a coding convention that looks like:

       function TypeMyClass ()
       {
          Private properties
          var a;
          var b;
      
          //Public properties
          this.c;
          this.d;
      
          //Private methods
          var Init = function ()
          {
           //... Do something ...
          }
      
          //Public methods
          this.GetVarA = function ()
          {
            return a;
          }
      
          //Initialization
          Init ();
       }
      

      This is what I have so far, but I am getting nothing:

      <parser 
      id="js_function" 
      displayName="Javascript" 
      commentExpr="((/\*.*?\*)/|(//.*?$))"
      >     <!--parser: sniff comment lines; either /*blah*/ or // blah -->
      <classRange
          mainExpr="^[\s]*function([\s]+[_A-Za-z]?[\w_]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{" 
          openSymbole = "\{"
          closeSymbole = "\}"
          displayMode = "node"
          > 
          <className>
              <nameExpr expr="[_A-Za-z]?[\w_]*[\s]*\("/>    <!--Narrow down from mainExpr towards the class names-->
              <nameExpr expr="[_A-Za-z]?[\w_]"/>            <!--Narrow down to the name itself -->
          </className>
          <function
              mainExpr="(var/let|(this+[.]))+[\s]*[_A-Za-z][\w_]*[\s]*[=]+[\s]*[_A-Za-z][\w_]*[\s]*\("
              displayMode="$functionName">                  <!--function: is used to find the method definitions -->
              <functionName>
                  <nameExpr expr="[_A-Za-z][\w_]*[\s]*[=]+[\s]*[_A-Za-z]?[\w_]*[\s]*\("/> <!--Narrow down the mainExpr-->
                  <nameExpr expr="[_A-Za-z][\w_]*[\s]*[=]"/>                              <!--Narrow further down to the name itself -->
              </functionName>
          </function>
      </classRange>
      </parser>
      
      1 Reply Last reply Reply Quote 0
      • Florent PagèsF
        Florent Pagès
        last edited by

        try this one

        		<!-- ========================================================= [ JS FPS ] -->			
        		
        		<parser 
        		  displayName="Javascript" 
        		  id="js_function" 
        		  commentExpr="(?s:/\*.*?\*/)|(?m-s://.*?$)"
        		>
        		
        			<function
        
        				mainExpr="((^|\s+|[;\}\.])([A-Za-z_]\w*\.)*[A-Za-z_]\w*\s*[=:]|^|[\s;\}]+)\s*function(\s+[A-Za-z_]?\w*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{"
        			>
        				<functionName>
        
        
        					<nameExpr expr="[A-Za-z_]\w*\s*[=:]|[A-Za-z_]?\w*\s*\(" />
        					<nameExpr expr="[A-Za-z_]?\w*" />
        				</functionName>
        
        
        
        				<className>
        					<nameExpr expr="([A-Za-z_]\w*\.)*[A-Za-z_]\w*\." />
        					<nameExpr expr="([A-Za-z_]\w*\.)*[A-Za-z_]\w*" />
        				</className>
        			</function>
        			
        		</parser>
        
        MAPJe71M 1 Reply Last reply Reply Quote 0
        • MAPJe71M
          MAPJe71 @Florent Pagès
          last edited by

          @Florent-Pagès as available in Notepad++ v7.3.2.0 which was enhanced in v7.5.1.0 i.e. allowing $ in identifiers and whitespace before the left/open parenthesis.

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