Notepad ++ List of functions: returns a class even if empty

I am trying to define a custom function list (functionList.xml in% appdata% / Notepad ++) to use it as a navigator for a long text file used as input to the software.

I managed to get it to work almost perfectly, although there is another problem that bothers me: I would like to return the class even if there is no function in it .

Firstly, this is an example of what my text file looks like (some of you may recognize the .inp file used for eQuest energy modeling software, but that doesn't matter):

$ ********************************************************* $ ** ** $ ** 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 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> 

The following appears in the function list area: Function List in its current state

I would really like it if it could also display "Fuel Meters" in the list, even if it is empty. The reason for this is that I am going to use this as a navigation page, and therefore I need anchors for empty sections so that I can quickly get there and add material.

Is this possible in Notepad ++? Any help would be greatly appreciated.

Something I was thinking about: if I could write regular code there, in ClassRange> Function, I would do an IF statement. If found "^ \". *? \ "= [^] +", Then go to the rest of the parsing. Otherwise, return the position of the first line of the class. I do not know how to do this with RegEx or if it is possible.


Update: I think I found a way that could work, but I cannot figure out the correct regex. Basically, I think that the problem with my current parser is that when the class is empty, it still returns as a class and, therefore, will not be received later by a function outside the class. I need to find a way to change this:

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

He must not pick up the Fuel Meters class. Now he understands this:

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

until the next $ sign.

How can I modify the above regex to make sure that there is at least one character that is not \ n \ r or spaces?

+5
source share
1 answer

Did you spot it? I'm not quite sure what you are asking, but using something like this:

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

You get a code that matches:

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

But what exactly are you trying to capture?

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

 (?<=\$\s-+\s+\$\s+)\w+(?:\s+\w+)+ 
+1
source

Source: https://habr.com/ru/post/1208431/


All Articles