• Login
Community
  • Login

Class range regex in function list

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
function list
10 Posts 4 Posters 6.3k 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.
  • M
    Matt Klein
    last edited by Feb 8, 2016, 6:02 AM

    I am attempting to define a parser in functionList.xml. My file is split up as such:

    ------------------
    {{header}}
    ------------------ {
    
    [subheader]
    
    random text
    
    }
    

    And I’m pretending that the headers are classes and the subheaders are functions so that they will show up in a nice hierarchy in the function list, like so:

    header 1
    	subheader 1
    	subheader 2
    header 2
    	subheader 1
    

    This is the XML I’m using:

    <parser id="test_function" displayName="Test Syntax">
    	<classRange
    		mainExpr="\{\{.+?\}\}[\n\r]-+?\s\{"
    		openSymbole="\{"
    		closeSymbole="\}"
    		displayMode="node">
    		<className>
    			<nameExpr expr="[^\{].+[^\}]"/>
    		</className>
    		<function
    			mainExpr="\[.+\]"
    			displayMode="$functionName">
    			<functionName>
    				<nameExpr expr="[^\[].+[^\]]"/>
    			</functionName>
    		</function>
    	</classRange>
    </parser>
    

    The regex works fine when I verify it on RegexPal, but does not work in NP++ no matter how I try to rewrite it. I actually managed to get something somewhat working once, but it stopped working after I updated the program. Overall I’m just confused on exactly how this thing really parses and why such a simple(-looking) format isn’t getting properly recognized despite the regex being fine.

    (I had actually posted this question on SO two years ago…but am still struggling today so, updated some regex and am now asking here. Thanks for any help!)

    1 Reply Last reply Reply Quote 0
    • D
      dail
      last edited by Feb 8, 2016, 2:26 PM

      NOTE I’ve never messed with the function list parser myself, but can check out some of the regexs. Some look a bit off.

      mainExpr="\{\{.+?\}\}[\n\r]-+?\s\{"
      

      The [\n\r] looks weird because it will not match Windows line endings which use \r\n (meaning two characters). This regex can only match one \r or \n. So that is something that probably needs fixed. Also

      expr="[^\{].+[^\}]"
      

      within className/nameExpr also looks off. I’m not sure what this section of the XML does for the function list parser but assuming it is trying to find the text header then you’d want to use something like:

      expr="(?<=\{\{)[^\}]+"
      

      Also for the functionName/nameExpr again assuming you want to match subheader use something like:

      expr="(?<=\[)[^\]]+"
      
      1 Reply Last reply Reply Quote 0
      • M
        Matt Klein
        last edited by Feb 8, 2016, 9:17 PM

        Thanks, completely forgot about the \r\n thing for two years apparently! I’ve made the changes and verified all the expressions in NP++'s search by regex tool (honestly don’t know why I’ve been using external tools before…). This is my current parser:

        <classRange
        	mainExpr="^\{\{.+?\}\}\r\n-+?\s\{"
        	openSymbole="\{"
        	closeSymbole="\}"
        	displayMode="node">
        	<className>
        		<nameExpr expr="(?<=\{\{)[^\}]+"/>
        	</className>
        	<function
        		mainExpr="^\[.+?\]"
        		displayMode="$functionName">
        		<functionName>
        			<nameExpr expr="(?<=\[)[^\]]+"/>
        		</functionName>
        	</function>
        </classRange>
        

        Unfortunately, this still doesn’t work–the functionlist is still empty. Hoping someone who’s worked with the file before can point out what’s wrong.

        1 Reply Last reply Reply Quote 0
        • M
          Matt Klein
          last edited by Matt Klein Feb 9, 2016, 2:18 AM Feb 9, 2016, 2:16 AM

          (Couldn’t find any rules about double posting here but I can no longer edit my previous posts:)

          Not sure if this information changes anything but, what’s really strange is that if I make a plain function parser using the exact same code (eg. just deleting every node relating to classRange), each header is sensed perfectly fine as a function. Subheaders work too. I just can’t get anything to work when parsing them as part of a class.

          C 1 Reply Last reply Feb 10, 2016, 9:50 PM Reply Quote 0
          • C
            Claudia Frank @Matt Klein
            last edited by Feb 10, 2016, 9:50 PM

            Hello @Matt-Klein,

            can you show the complete parser xml as well as the association part?

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • M
              Matt Klein
              last edited by Feb 11, 2016, 12:57 AM

              @Claudia-Frank Here’s all the relevant XML:

              <association ext=".testsyntax" userDefinedLangName="Test" id="test_function"/>
              
              <parser id="test_function" displayName="Test Syntax">
              	<classRange
              		mainExpr="^\{\{.+?\}\}\r\n-+?\s\{"
              		openSymbole="\{"
              		closeSymbole="\}"
              		displayMode="node">
              		<className>
              			<nameExpr expr="(?<=\{\{)[^\}]+"/>
              		</className>
              		<function
              			mainExpr="\[.+?\]"
              			displayMode="$functionName">
              			<functionName>
              				<nameExpr expr="(?<=\[)[^\]]+"/>
              			</functionName>
              		</function>
              	</classRange>
              </parser>
              
              C 1 Reply Last reply Feb 11, 2016, 7:18 PM Reply Quote 0
              • C
                Claudia Frank @Matt Klein
                last edited by Feb 11, 2016, 7:18 PM

                @Matt-Klein

                I hope this does it

                        <parser id="test_function" displayName="Test Syntax">
                            <classRange 
                                mainExpr="^\{{2}.+?\}{2}\R-+?\s\{"
                                openSymbole = "\{"
                				closeSymbole = "\}">
                                <className>
                                    <nameExpr expr="\w+"/>
                                </className>
                                <function mainExpr="\[.+?\]">
                                    <functionName>
                                        <funcNameExpr expr="\w+"/>
                                    </functionName>
                                </function>
                            </classRange>
                            <function mainExpr="\[.+?\]">
                                <functionName>
                                    <nameExpr expr="\w+"/>
                                </functionName>
                            </function>
                        </parser>
                

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 0
                • M
                  Matt Klein
                  last edited by Feb 11, 2016, 11:48 PM

                  @Claudia-Frank Ahhhh thank you so much! After replacing a bunch of regex and checking what went wrong, it seems that writing nameExpr instead of funcNameExpr under classRange -> functionName was what had caused everything to not work. Hard to believe that took two years, but I’ll be remembering this fix for a long while…

                  C 1 Reply Last reply Feb 11, 2016, 11:54 PM Reply Quote 0
                  • C
                    Claudia Frank @Matt Klein
                    last edited by Feb 11, 2016, 11:54 PM

                    @Matt-Klein to be honest, I didn’t even notice this.
                    I always copy a working one and then start modifying it.

                    Cheers
                    Claudia

                    1 Reply Last reply Reply Quote 0
                    • guy038G
                      guy038
                      last edited by Feb 19, 2016, 6:56 PM

                      Hello Matt,

                      Indeed, the way Claudia wrote your parser, as you noticed, is the right syntax. Just refer to the sections Class parser or Mix parser, of the article below :

                      https://notepad-plus-plus.org/features/function-list.html

                      Best Regards

                      guy038

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