我正在尝试定义一个自定义函数列表(%appdata%/ Notepad ++中的functionList.xml),以便将其用作导航器,用于作为软件输入的基于文本的长文件.
我设法让它几乎完美地工作,虽然还有一个困扰我的问题:即使它没有函数,我也想返回一个类.
首先,这是我的文本文件的样本(你们中的一些人可能会认识到用于eQuest能量建模软件的.inp文件,但这是无关紧要的):
$ *********************************************************
$ ** **
$ ** 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
..
Run Code Online (Sandbox Code Playgroud)
这是我当前的解析器:
<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>
Run Code Online (Sandbox Code Playgroud)
它将在"功能列表"窗格中显示以下内容:

我非常希望它是否也可以在列表中显示"Fuel Meters",即使它是空的.其背后的原因是我将使用它作为导航页面,因此我需要锚定空白部分,以便我可以快速去那里并添加东西.
在Notepad ++中有可能吗?任何帮助将不胜感激.
我一直在想的东西:如果我可以在那里编写常规代码,在ClassRange> Function下,我会做一个IF语句.如果找到"^ \".*?\"= [^] +",则继续进行其余的解析.否则,返回班级第一行的位置.我不知道如何使用RegEx或者如果可行的话.
更新:我认为我找到了一种方法可行,但我无法弄清楚正确的正则表达式.基本上,我认为我对当前解析器的问题是,当类为空时,它仍然作为一个类返回,因此以后不会被类范围之外的函数拾取.我需要找到一种方法来修改它:
<classRange
mainExpr="\$.*?\r\n\r\n.*?(?=\$)"
displayMode="node" >
Run Code Online (Sandbox Code Playgroud)
它不需要拿起"燃料表"类.现在它确实接受了这个:
$ ---------------------------------------------------------
$ Fuel Meters
$ ---------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
直到下一个$符号.
如何修改上面的Regex以确保至少有一个字符不是\n\r或空格?
这个问题你弄清楚了吗?我不太确定你在问什么,但使用这样的东西:
\$\s-+\s+\$(?:\s+\w+)+
Run Code Online (Sandbox Code Playgroud)
您将获得匹配的代码:
$ ---------------------------------------------------------
$ ANY ALPHANUMERIC SENTENCES HERE
Run Code Online (Sandbox Code Playgroud)
但你到底想捕捉什么?
或者,如果您只想要类名,您可以这样做:
(?<=\$\s-+\s+\$\s+)\w+(?:\s+\w+)+
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
340 次 |
| 最近记录: |