如何将Lua函数添加到Notepad++的functionList.XML中

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>
点赞
用户1150918
用户1150918

来自FunctionList插件2.1的片段:

<语言名称="Lua" imagelistpath="">
    <CommList param1='&quot;' param2='&quot;' />
    <CommList param1="&apos;" param2="&apos;" />
    <CommList param1="--" param2="" />
    <CommList param1="--\[\[" param2="\]\]" />
    <Group name="FUNCTION" subgroup="" icon="0" child="0" autoexp="0" matchcase="1" fendtobbeg="" bbegtobend="\&lt;do\&gt;|\&lt;if\&gt;|\&lt;function\&gt;" keywords="">
        <Rules regexbeg="^[-\s]*function\s+" regexfunc="[\w_:.]+" regexend="\s*\([\w_,.\s]*\)" bodybegin="" bodyend="\&lt;end\&gt;" sep="" />
        <Rules regexbeg="^[-\s]*" regexfunc="[\w_:.]+" regexend="\s*=\s*function\s*\([\w_,\s]*\)" bodybegin="" bodyend="\&lt;end\&gt;" sep="" />
        <Rules regexbeg="^" regexfunc="[\w_]+" regexend="\s*=" bodybegin="\{" bodyend="\}" sep="" />
    </Group>
</Language>

我猜,你可以只获取最新版本的插件而不必担心了... :)

2013-10-08 12:29:59
用户83369
用户83369

我已经让以下代码起作用了。它非常简单,我没有烦恼commentExpr属性(因为它是可选的,详见文档):

<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
  <functionList>
    <associationMap>
      <association langID = "23" id="lua_function"/>
    </associationMap>
    <parsers>
      <parser id="lua_function" displayName="Lua">
        <function mainExpr="^[\t\s]*function\s+[^0-9][_A-Za-z0-9]+\s*\("
                  displayMode="$functionName">
          <functionName>
            <nameExpr expr="[^0-9][_A-Za-z0-9]+\s*\("/>
            <nameExpr expr="[^0-9][_A-Za-z0-9]+"/>
          </functionName>
        </function>
      </parser>
    </parsers>
  </functionList>
</NotepadPlus>

你确定已经将你的分析器添加到了associationMap标签中了吗?

多个nameExpr标签是为了将匹配字符串过滤到仅为函数名称。

2013-10-12 20:27:39
用户2212298
用户2212298

我使用lua和函数列表时,我首先必须在%appdata% \ Notepad ++中使用functionList.xml才能使其工作,但这可能是由于我的安装。第二个是从您的配置中缺少两个内容。首先是关联langID =“23”

<associationMap>
  <association langID = "23" id="lua_function"/>
</associationMap>

其次,正则表达式会错过局部函数,我的当前配置如下

        <parser id="lua_function" displayName="Lua">
            <function mainExpr="^[\t|local\s]*function\s+[^0-9][_A-Za-z0-9]+\s*\("
                      displayMode="$functionName">
              <functionName>
                <nameExpr expr="[^0-9][_A-Za-z0-9]+\s*\("/>
                <nameExpr expr="[^0-9][_A-Za-z0-9]+"/>
              </functionName>
            </function>
         </parser>

将两者都添加到functionList.xml(根据安装位置,程序文件或%appdata%)将使lua语言在Notepad ++ 6.5.1中的函数列表工作。

2013-11-21 17:52:50
用户1688183
用户1688183

我对Notepad++使用了自己的定义。它的主要区别在于支持 local SomeFunction = function() endfunction SomeObject:Func() end 这样的函数。此外,它还具有一些基本的lua表视图兼容性。

<!-- 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]*['&quot;]?[\w]+['&quot;]?">
            <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" />
2014-01-31 12:46:37