Warm tip: This article is reproduced from serverfault.com, please click

Custom np++ functionlist expressions

发布于 2020-11-26 18:49:05

Oh, I'm having trouble just understanding what I'm doing here.

I'm creating a custom Notepad++ FunctionList. I know how to add it, and it's parsing, but I can't figure out from the docs how to specify the regex correctly.

In my code file (for a program called Squiffy), it has sections, kind of like an .ini file, so I started by copying the ini file's functionlist code.

I'm looking for sections like this: [[something]]: on it's own line, and for subsections like this: [somesubsection]:.

<?xml version="1.0" encoding="UTF-8" ?>

<NotepadPlus>
    <functionList>
        <!-- File format used for: .sq         -->
        <parser displayName="Squiffy" id="Squiffy" 
            commentExpr=""
        >
            <function mainExpr=mainExpr="^\[\[.*\]\]\:$" >
                <functionName>
                    <nameExpr expr="^\[\[.*\]\]*"/>
                </functionName>
            </function>
        </parser>
    </functionList>
</NotepadPlus>

My problem is that I don't really understand what mainExpr and nameExpr are supposed to find. I know I can find the sections with the regex I have in mainExpr, but I'm not sure what to with the nameXpr field.

Questioner
bgmCoder
Viewed
0
bgmCoder 2020-11-28 12:19:38

Hmmmph. Nobody had anything to say! So I posted on the notepad++ forum, which is where this solution comes from:

        <parser
            id="Squiffy" displayName="Squiffy" commentExpr=""
        >
            <function
                mainExpr="(?-s)^\[(?:\[([^\[\]\r\n]+)\]|(?1))\]:"
            >
                <functionName>
                    <nameExpr expr="[^\[\]\r\n]+" />
                </functionName>
            </function>
        </parser>

And here is a thread describing just notepad++ functionlists are configured.