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.
    • Matt KleinM
      Matt Klein
      last edited by

      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
      • dailD
        dail
        last edited by

        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
        • Matt KleinM
          Matt Klein
          last edited by

          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
          • Matt KleinM
            Matt Klein
            last edited by Matt Klein

            (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.

            Claudia FrankC 1 Reply Last reply Reply Quote 0
            • Claudia FrankC
              Claudia Frank @Matt Klein
              last edited by

              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
              • Matt KleinM
                Matt Klein
                last edited by

                @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>
                
                Claudia FrankC 1 Reply Last reply Reply Quote 0
                • Claudia FrankC
                  Claudia Frank @Matt Klein
                  last edited by

                  @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
                  • Matt KleinM
                    Matt Klein
                    last edited by

                    @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…

                    Claudia FrankC 1 Reply Last reply Reply Quote 0
                    • Claudia FrankC
                      Claudia Frank @Matt Klein
                      last edited by

                      @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

                        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