Notepad++提供了一个函数列表。
我目前使用的是 Notepad++ 6.5
functionList.xml 使用正则表达式定义函数名称的解析器。
下面的代码定义了c函数的解析器
<parser id="c_function" displayName="C source" commentExpr="((/\*.*?\*)/|(//.*?$))">
<function
mainExpr="^[\t ]*((static|const|virtual)[\s]+)?[\w:]+([\s]+[\w]+)?([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+)([\w_]+[\s]*::)?(?!(if|while|for))[\w_]+[\s]*\([^\)\(]*\)([\s]*const[\s]*)?[\n\s]*\{"
displayMode="$functionName">
<functionName>
<nameExpr expr="(?!(if|while|for))[\w_~]+[\s]*\("/>
<nameExpr expr="(?!(if|while|for))[\w_~]+"/>
</functionName> </function>
</parser>
我在线尝试了我的正则表达式,一切正常。但它不适用于 functionList.xml 不知何故。函数列表保持为空。
这对于 Lua 函数来说会是什么样子?
这是我的尝试:
<parser id="lua_function" displayName="Lua Function" commentExpr="((--\[\[\*.*?\*)/|(--.*[\n\s\w\t]*\]\]))">
<function
mainExpr="^[\t\s]*(function)[\s]+[\w]+\("
displayMode="$functionName">
<functionName>
<nameExpr expr="(?:(function[\s]+))[\w]+"/>
</functionName>
</function>
</parser>
最佳答案
我对 Notepad++ 使用自己的定义。它的主要区别在于支持以下函数:local SomeFunction = function() end
和 function SomeObject:Func() end
。它还具有一些基本的 lua TableView 兼容性。
<!-- Basic lua parser for functionList.xml in Notepad++ 6.5.3 -->
<!-- See http://notepad-plus-plus.org/features/function-list.html -->
<parser id="lua_function" displayName="Lua" commentExpr="--.*?$">
<!-- Basic lua table view, nested lua table not supported -->
<classRange
mainExpr="[.\w]+[\s]*=[\s]*\{"
openSymbole="\{"
closeSymbole="\}"
displayMode="node">
<className>
<nameExpr expr="[.\w]+"/>
</className>
<function
mainExpr="[.\w]+[\s]*=[\s]*['"]?[\w]+['"]?">
<functionName>
<funcNameExpr expr=".*"/>
</functionName>
</function>
</classRange>
<!-- Basic lua functions support -->
<function
mainExpr="(function[\s]+[.\w]+(:[\w]+)?)|([.\w]+[\s]*=[\s]*function)"
displayMode="$className->$functionName">
<functionName>
<nameExpr expr="((?<=function)[\s]+[.:\w]+)|(([.\w]+)(?=([\s]*=[\s]*function)))"/>
</functionName>
<className>
<nameExpr expr="[.\w]+(?=:)"/>
</className>
</function>
</parser>
同时添加关联
<association id="lua_function" langID="23" />
关于xml - 如何将 Lua 函数添加到 Notepad++ functionList.XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19246077/