Community
    • Login

    Function list for user defined language

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 2.0k 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.
    • Hristo GoumnerovH
      Hristo Goumnerov
      last edited by

      Hey guys,

      I’ve been playing around with the function list feature, and i’ve gotten to a point where i’m stuck.

      I can’t seem to upload files here so i have pasted the test file and the entries in the functionList.xml file after.

      Only the test1_parser works and i can see the “function”, i.e. Header, First, Second, … in the list. When i switch to the test2_parser the function list is empty.

      Does anyone know how to fix this problem? Ideally i would have one parser where the C---- entries can be folded and the K---- entries are contained in them.

      Thanks a lot in advance.

      ±-------------------------------------------------------------------------------+
      The file in Fortran free form:

      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      C---- HEADER
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

      @$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      @
      C---- FIRST
      @
      K---- TEST 1

      @$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      @
      C---- SECOND
      @
      K---- TEST 2

      @$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
      @
      C---- THIRD
      @
      K---- TEST 3

      K---- TEST 4

      C---- END
      @$$$$$$$$$$$$$$$$$$$$$$$$$$ END $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

      ±-------------------------------------------------------------------------------+
      The entries in the functionList.xml file:

      <!--  === Test related parser associations ========================= -->
      <association langID="25" id="test1_parser"/>
      
        <!-- === Test related parsers ===================================== -->
      <parser id="test1_parser" displayName="Test1" commentExpr="(@.*?)$">
      	<function mainExpr="(^C----[\s]*[\w]*)" displayMode="$functionName">
      		<functionName> <nameExpr expr="[\s]+[\w]+" /></functionName>
      	</function>
      </parser>
      		
      <parser id="test2_parser" displayName="Test2" commentExpr="(@.*?)$">
      	<function mainExpr="(^K----[\s]*[\w]+*)" displayMode="$functionName">
      		<functionName> <nameExpr expr="[\s]+[\w]+" /></functionName>
      	</function>
      </parser>
      
      1 Reply Last reply Reply Quote 0
      • MAPJe71M
        MAPJe71
        last edited by

        Try one of these:

        <?xml version="1.0" encoding="UTF-8" ?>
        <!-- ==========================================================================\
        |
        |   To learn how to make your own language parser, please check the following
        |   link:
        |       http://notepad-plus-plus.org/features/function-list.html
        |
        \=========================================================================== -->
        <NotepadPlus>
        	<functionList>
        		<associationMap>
        			<association id=     "fortran_freeform"      langID="25"                              />
        			<association id=     "fortran_fixedform"     langID="59"                              />
        		</associationMap>
        		<parsers>
        			<!-- ===================================================== [ Fortran ] -->
        
        			<!--
        			|   Based on:
        			|       https://community.notepad-plus-plus.org/topic/11059/custom-functions-list-rules
        			|       https://community.notepad-plus-plus.org/topic/13553/functionlist-xml-regular-expressions-not-parsing-properly
        			\-->
        			<parser
        				displayName="Fortran Free Form style - FORmula TRANslation"
        				id         ="fortran_freeform"
        				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
        						(?m-s:!.*$)                                             # Single Line Comment
        					"
        			>
        				<function
        					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
        							(?im-s)                                             # case-insensitive, ^ and $ match at line-breaks, dot does not
        							^\h*                                                # optional leading white-space at start-of-line
        							(?:
        								(?:
        									ELEMENTAL
        								|	(?:IM)?PURE
        								|	MODULE
        								|	(?:NON_)?RECURSIVE
        								)
        								\s+
        							)*
        							(?:FUNCTION|SUBROUTINE)\s+
        							\K                                                  # discard text matched so far
        							[A-Z]\w{0,62}                                       # valid character combination for identifiers
        							(?:\s*\([^()]*\))?                                  # optional parameter list
        						"
        				>
        					<!-- comment out the following node to display the method with its parameters -->
        					<functionName>
        						<nameExpr expr="\w+" />
        					</functionName>
        				</function>
        			</parser>
        			<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
        			<parser
        				displayName="Fortran Fixed Form style - FORmula TRANslation"
        				id         ="fortran_fixedform"
        				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
        						(?m-s:(?:!|^[Cc*].*$)                                   # Single Line Comment 1..3
        					"
        			>
        				<function
        					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
        							(?im-s)                                             # case-insensitive, ^ and $ match at line-breaks, dot does not
        							^\h*                                                # optional leading white-space at start-of-line
        							(?:FUNCTION|SUBROUTINE)\s+
        							\K                                                  # discard text matched so far
        							[A-Z]\w{0,62}                                       # valid character combination for identifiers
        							(?:\s*\([^()]*\))?                                  # optional parameter list
        						"
        				>
        					<!-- comment out the following node to display the method with its parameters -->
        					<functionName>
        						<nameExpr expr="\w+" />
        					</functionName>
        				</function>
        			</parser>
        
        			<!-- =================================================== [ Fortran77 ] -->
        
        			<parser
        				displayName="[#4] Fortran77 (see Fortran Fixed Form style / fortran_fixedform)"
        				id         ="fortran77_syntax"
        			/>
        
        			<!-- ================================================================= -->
        		</parsers>
        	</functionList>
        </NotepadPlus>
        
        1 Reply Last reply Reply Quote 3
        • guy038G
          guy038
          last edited by guy038

          Hello, @hristo-goumnerov, @MAPJe71 and All,

          To specifically match your text, Here is a possible parser :

            <!-- === Test related parsers ===================================== -->
                                  <parser
                                      id="Test_Parser" displayName="Test" commentExpr="^@.*?$" >
                                      <function
                                          mainExpr="^(?-i)^(C|K).+?$"
                                      >
                                          <functionName>
                                              <nameExpr expr="[\w\x20]+$" />
                                          </functionName>
                                      </function>
                                  </parser>
                      
          

          I, then, realized that when, both, the function and class nodes are absent, the function name can be extracted, directly, from the mainExpr regex :-))

          So, this parser can even be shortened as :

             <!-- === Test related parsers ===================================== -->
                                  <parser
                                      id="Test_Parser" displayName="Test" commentExpr="^@.*?$" >
                                      <function
                                          mainExpr="(?-i)^(C|K)----\h*\K.+?$" >
                                      </function>
                                  </parser>
                      
          

          Remarks :

          • I simply used the line, below, to associate the parser to Normal text, for easier tests !
          			<association id= "Test_Parser" langID= "0" />
          
          • The name of this parser is Test_Parser, each word beginning with an upper-case letter

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 3
          • Hristo GoumnerovH
            Hristo Goumnerov
            last edited by

            Thanks a lot guys :)

            It works now.

            Best wishes.

            1 Reply Last reply Reply Quote 3
            • Hristo GoumnerovH
              Hristo Goumnerov
              last edited by

              A bonus question if anyone is still interested in helping a newbie :)

              I’m trying to make the function list show me the classes (starting with C—) and the functions (starting with K---- or S----), with the functions being inside of the classes. I got it to work so that the classes and the functions are shown, but the functions are not part of the classes, and when i collapse the classes they are empty. I’ve tried various versions of the below script, but to no avail. I’m sure that it has to be some minor fix. Thanks in advance.

              <parser
              displayName="hgg"
              id         ="hgg"
              commentExpr="(@.*?)$"
              >
                  <classRange
              	mainExpr="(^C----.+?$)"
                  >
              	<className>
              		<nameExpr expr=".+?$" />
              	</className>
              	<function
              		mainExpr="(^[KS]----.+?$)"
              	>
              		<functionName>
              			<nameExpr expr=".+?$" />
              		</functionName>
              	</function>
                   </classRange>
              </parser>
              
              1 Reply Last reply Reply Quote 0
              • MAPJe71M
                MAPJe71
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • MAPJe71M
                  MAPJe71
                  last edited by

                  Maybe FAQ Desk: Function List Basics will give you some ideas.

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