Community
    • Login

    Displaying Comma Separated Structures in FunctionList

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 322 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.
    • DravokD
      Dravok
      last edited by

      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.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Dravok
        last edited by

        @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

        PeterJonesP 1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @PeterJones
          last edited by PeterJones

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

          DravokD 1 Reply Last reply Reply Quote 4
          • DravokD
            Dravok @PeterJones
            last edited by

            @PeterJones
            That’s awesome. Thank you.

            1 Reply Last reply Reply Quote 1
            • MAPJe71M
              MAPJe71
              last edited by

              @PeterJones Well done!

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

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