6

I'm trying to define a custom Function List (functionList.xml in %appdata%/Notepad++) in order to use that as a navigator for a long text-based file used as an input to a software.

I managed to make it work almost perfectly, though there is still one issue that bothers me: I'd like to return a Class even if it doesn't have a Function in it.

First, this is a sample of what my text file looks like (some of you might recognize an .inp file used for the eQuest energy modeling software, but that's irrelevant):

$ *********************************************************
$ **                                                     **
$ **              Electric & Fuel Meters                 **
$ **                                                     **
$ *********************************************************

$ ---------------------------------------------------------
$              Electric Meters
$ ---------------------------------------------------------

"EM1" = ELEC-METER      
   TYPE             = UTILITY
   ..


$ ---------------------------------------------------------
$              Fuel Meters
$ ---------------------------------------------------------



$ ---------------------------------------------------------
$              Master Meters
$ ---------------------------------------------------------

"MASTER-METERS 1" = MASTER-METERS   
   MSTR-ELEC-METER  = "EM1"
   MSTR-FUEL-METER  = "FM1"
   ..

$ ---------------------------------------------------------
$              Something else
$ ---------------------------------------------------------


"XXX" = blabla
    ..

Here is the current parser that I have:

<parser 
    id="equest_full" 
    displayName="eQuest Full Function List">

    <!-- Find The entire Class using a positive lookahead -->
    <classRange
        mainExpr="\$.*?\r\n\r\n.*?(?=\$)" 
        displayMode="node" >

        <!-- Here we return just the Class name -->
        <className>
            <!-- Find only the text, using a negative lookahead to exclude multiple white spaces -->
            <nameExpr expr='\w(\w|-|/| (?! ))+'/>
        </className>

        <!-- Here we find the "function" - here it's something that starts a line with "XXXX" = "blabla" -->
        <function
            mainExpr='^\".*?\" = [^ ]+' >
            <functionName>
                <!-- We already have exactly what we want with the above -->                    
                <funcNameExpr expr=".*"/>
            </functionName>
        </function>
    </classRange>
    <function 
        mainExpr="\$.*?\r\n\r\n">
        <!-- A poor attempt to display classes even if empty... doesn't work properly -->
        <functionName>
            <!-- Find only the text, using a negative lookahead to exclude multiple white spaces -->
            <nameExpr expr="\w(\w|-|/| (?! ))+"/>
        </functionName>
    </function>
</parser>

It will show the following in the Function List pane: Function List in its current state

I would very much like if it could also display "Fuel Meters" in the list, even if it's empty. The reason behind it is that I'm going to use that as a navigation page and therefore I need anchors to empty sections so I can go there quickly and add stuff.

Is it possible in Notepad++? Any help will be greatly appreciated.

Something I've been thinking: If I could write regular code in there, under the ClassRange > Function, I would do an IF statement. If "^\".*?\" = [^ ]+" is found, then proceed with the rest of the parsing. Else, return the position of the first line of the class. I don't know how to do that with a RegEx or if it's feasible.


Update: I think I found a way that could work, but I can't figure out the proper regex. Basically, I think the problem I have with my current parser is that when the class is empty it still returns as a class and therefore won't be picked up later by the function that is outside of the classrange. I need to find a way to modify this:

<classRange
                mainExpr="\$.*?\r\n\r\n.*?(?=\$)" 
                displayMode="node" >

It needs to NOT pick up the "Fuel Meters" class. Right now it does pick up this:

$ ---------------------------------------------------------
$              Fuel Meters
$ ---------------------------------------------------------

until the next $ sign.

How can I modify to above Regex to make sure there is at least one character that isn't \n \r or spaces?

1
  • Not the answer, but why not SynWrite editor. It has fully configurable tree pane, with regex too, and all syntax colors. Commented Dec 7, 2014 at 12:09

1 Answer 1

2

Did you figure this one out? I'm not exactly sure what you're asking, but using something like this:

\$\s-+\s+\$(?:\s+\w+)+

You get code that matches:

$ ---------------------------------------------------------
$ ANY ALPHANUMERIC SENTENCES HERE

But what exactly are you trying to capture?

Alternatively if you only want the class names, you could do it like this:

(?<=\$\s-+\s+\$\s+)\w+(?:\s+\w+)+
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't figure it out, but it doesn't bother me much anymore... What I wanted to do is to return a class even if it's got no function, so I would still have an anchor to go there. I ended up learning the entire navigation pane so I know where to click above or below and get there fast enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.