4

我正在尝试扩展python.lang文件,以便它使方法像__init__突出显示。我一直在尝试想出一个匹配 all 的正则表达式__privateMethods()

python.lang是一个 XML 文件,其中包含 python 文件的所有突出显示规则。前任:

<context id="special-variables" style-ref="special-variable">
   <prefix>(?&lt;![\w\.])</prefix>
   <keyword>self</keyword>
   <keyword>__name__</keyword>
   <keyword>__debug__</keyword>
</context>

如何扩展它以匹配双下划线?


[解决方案]:我添加到python.lang文件中的内容(如果有人感兴趣):

首先,您需要在定义样式的顶部附近添加此行。

<style id="private-methods" _name="Private Methods" map-to="def:special-constant"/>

然后,您将添加Carles 在他的回答中提供的正则表达式:

<context id="private-methods" style-ref="private-methods">
    <match>(__[a-zA-Z_]*(__)?)</match>
</context>

这是完成后的样子!

在此处输入图像描述

4

2 回答 2

4

它应该是:

(__[a-zA-Z0-9_]*(__)?)

为了匹配以下所有内容:

__hello()
__init__()
__this_is_a_function()
__this_is_also_a_function__()
__a_URL2_function__()
于 2011-02-04T21:00:17.917 回答
1

将您之前的案例与以下管道匹配(rubular 示例):

(^__[a-z]*__$)
于 2011-02-04T20:23:18.683 回答