【问题标题】:Notepad++ function list PHP not working if the function name begins with reserverd words如果函数名以保留字开头,Notepad++ 函数列表 PHP 不起作用
【发布时间】:2017-01-05 03:19:42
【问题描述】:

notepad++ 的函数列表插件工作正常,除了我的函数名称以“for / while / if”开头。

例如,我在表单类中有函数。所以他们以“表单”开头(例如 form_information)。 所以函数名不会出现在函数列表中,因为函数名以'for'开头。

有人有同样的问题,或者可能是正则表达式中的解决方案?

这是PHP函数列表的正则表达式和xml。

<parser id="php_function" displayName="PHP" commentExpr="((/\*.*?\*)/|(//.*?$))">
<classRange
    mainExpr="^[\s]*(class|abstract[\s]+class|final[\s]+class)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*([\s]*|[\s]*(extends|implements|(extends[\s]+(\\|[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+[\s]+implements))[\s]+(\,[\s]*|(\\|[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))+[\s]*)?\{"
    openSymbole = "\{"
    closeSymbole = "\}"
    displayMode="node">
    <className>
        <nameExpr expr="(class|abstract[\s]+class|final[\s]+class)[\s]+[\w]+"/>
        <nameExpr expr="[\s]+[\w]+\Z"/>
        <nameExpr expr="[\w]+\Z"/>
    </className>
    <function
        mainExpr="^[\s]*((static|public|protected|private|final)*(\s+(static|public|protected|private|final))+[\s]+)?(function[\s]+)+([\w]+([\s]+[\w]+)?([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+))?([\w_]+[\s]*::)?(?!(if|while|for|switch))[\w_~]+[\s]*\([^\{]*\{">
        <functionName>
            <funcNameExpr expr="(?!(if|while|for|switch))[\w_]+[\s]*\([^\{]*"/>
            <!-- comment below node if want display method with parmas -->
            <funcNameExpr expr="(?!(if|while|for|switch))[\w_]+"/>
        </functionName>
    </function>
</classRange>
<function
    mainExpr="^[\s]*function[\s]+\w+\("

    displayMode="$className->$functionName">
    <functionName>
        <nameExpr expr="(?!(if|while|for))[\w_]+[\s]*\("/>
        <nameExpr expr="(?!(if|while|for))[\w_]+"/>
    </functionName>
    <className>
        <nameExpr expr="[\w_]+(?=[\s]*::)"/>
    </className>
</function>

感谢您的宝贵时间!

【问题讨论】:

  • (?!(if|while|for|switch)) 更改为(?!(if|while|for|switch)\b)(?!(if|while|for)) yo (?!(if|while|for)\b).. 这可能对您有所帮助。
  • 谢谢!这对我也有用:)

标签: php regex function plugins notepad++


【解决方案1】:

我刚刚查看了 %APPDATA%\Notepad++\functionList.xml,看起来问题是 if|while|for|switch 被检查时没有字边界。您需要在适当的位置添加单词边界。查看修改后的第一个&lt;function&gt;节点:

<function
    mainExpr="^[\s]*((static|public|protected|private|final)*(\s+(static|public|protected|private|final))+[\s]+)?(function[\s]+)+([\w]+([\s]+[\w]+)?([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+))?([\w_]+[\s]*::)?\b(?!(if|while|for|switch)\b)[\w_~]+[\s]*\([^\{]*\{">
    <functionName>
        <funcNameExpr expr="\b(?!(if|while|for|switch)\b)[\w_]+[\s]*\([^\{]*"/>
        <!-- comment below node if want display method with parmas -->
        <funcNameExpr expr="\b(?!(if|while|for|switch)\b)[\w_]+"/>
    </functionName>
</function> 

POI 是 \b(?!(if|while|for|switch)\b) - 负前瞻之前和交替组之后的单词边界,仅将这些单词作为整个单词进行匹配。

【讨论】:

  • 是的,请注意您确实需要both在此处以\bs开头和结尾,否则将在每个字符之前执行前瞻一行 - 这是不必要的开销。
【解决方案2】:

解析器的一个问题是它测试函数名称不是ifwhileforswitch。但它不会检查名称是否继续存在 - 例如form。向正则表达式添加单词边界,它可能会对您有所帮助。

(?!(if|while|for|switch)) 更改为

(?!(if|while|for|switch)\b)

(?!(if|while|for))

(?!(if|while|for)\b)

这可能会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    相关资源
    最近更新 更多