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:
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?
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+)+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With