• Login
Community
  • Login

Displaying Comma Separated Structures in FunctionList

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 353 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.
  • D
    Dravok
    last edited by Aug 18, 2020, 5:27 AM

    The custom language I work with allows multiple structures with the same definition to be declared using one command. Here is the syntax:

    STRUCT name[{,name}] (contents)

    For example:
    STRUCT str1, str2, str3 (…)

    Is there a regex that would be able to grab all structure names and display them separately in the FunctionList? I was reading about recursion but that’s a little too advanced for me and I am not even sure it would work.

    P 1 Reply Last reply Aug 18, 2020, 1:12 PM Reply Quote 0
    • P
      PeterJones @Dravok
      last edited by Aug 18, 2020, 1:12 PM

      @Dravok ,

      @MAPJe71 or another FunctionList expert will have to chime in, but from my understanding, when the FunctionList parses the document, each match corresponds to a single entry in the FunctionList display; I don’t know of a way to make it grab multiple from the same line.

      However, maybe using an alternation in the regex with \G syntax (which says "start at the end of the previous match), it might be possible. I’ll give it some thought, and if I have a chance to play around with that sometime today (and if no one else has beat me to it), I’ll see if I can come up with something

      P 1 Reply Last reply Aug 18, 2020, 2:20 PM Reply Quote 0
      • P
        PeterJones @PeterJones
        last edited by PeterJones Aug 18, 2020, 2:21 PM Aug 18, 2020, 2:20 PM

        @Dravok ,

        I created a small UDL called CommaStruct, and gave it a dummy file of:

        https://community.notepad-plus-plus.org/topic/19873/displaying-comma-separated-structures-in-functionlist
        STRUCT str1, str2, str3 (…)
            STRUCT aaa, bbb, ccc (…)
        STRUCT zzz (…,…,…)
        

        To my functionList.xml, I added:

        <association id="CommaStruct"             userDefinedLangName="CommaStruct"    />
        <association id="CommaStruct"             ext=".csl"                           />
        ...
        <parser id="CommaStruct" displayName="Comma-based STRUCT" commentExpr="">
          <function
            mainExpr="(?x-s)^\h*STRUCT\h+(\w+)|\G,\h*(\w+)"
          >
            <functionName>
                <nameExpr expr="(?:STRUCT\h+|,\h*)\K\w+" />
            </functionName>
          </function>
        </parser>
        

        When I reloaded, I saw:
        16ea5a9f-514b-4bef-ad2a-0dce9db2c517-image.png
        … so str1,str2,str3, aaa,bbb,ccc, and zzz were all recognized as STRUCT, which is what I understood you wanted.

        D 1 Reply Last reply Aug 18, 2020, 4:02 PM Reply Quote 4
        • D
          Dravok @PeterJones
          last edited by Aug 18, 2020, 4:02 PM

          @PeterJones
          That’s awesome. Thank you.

          1 Reply Last reply Reply Quote 1
          • M
            MAPJe71
            last edited by Aug 18, 2020, 7:22 PM

            @PeterJones Well done!

            Nitpicking: you could remove the x in (?x-s).

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