Displaying Comma Separated Structures in FunctionList

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

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

  • @Dravok ,

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

    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="">
            <nameExpr expr="(?:STRUCT\h+|,\h*)\K\w+" />

    When I reloaded, I saw:
    … so str1,str2,str3, aaa,bbb,ccc, and zzz were all recognized as STRUCT, which is what I understood you wanted.

  • @PeterJones
    That’s awesome. Thank you.

  • @PeterJones Well done!

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

Log in to reply