scope - Sublime Text : scope selector operators

标签 scope operators sublimetext2 sublimetext3 sublimetext

当前在TmThemeEditor上注册的243种配色方案中,
我注意到几乎没有人使用范围选择器运算符。

对于以下情况,运算符非常有用:

(text.html | text.xml) & (meta.tag entity)

我认为,配色方案设计师很少使用它们的原因是,他们的文献记录不多。
ST2的官方文档中根本没有提到它们
ST3,或
unofficial docs for colour schemes
unofficial docs for syntax definitions
提及范围选择器,但不提及运算符。

在哪里可以找到Sublime Text支持的范围选择器运算符的文档?

最佳答案

运算符按优先级顺序(从高到低)为:
( )分组
&交叉点
-不对称差(相对补码)
|联盟
,逗号

配色方案文件(.tmTheme)的文件格式是从TextMate继承的。

这是TextMate文档中有关范围选择器运算符的一些相关链接和引号:

  • Manual: Scope Selectors
  • Excluding Elements
    “我们可以减去范围选择器,以使用减号运算符获得(非对称)差异。”
  • Comma
    “当我们希望某项匹配多个不同的范围时,可以用逗号将范围选择器分组
    运算符(operator)。例如,为了匹配字符串和注释,作用域选择器将是:string, comment。“
  • Introduction to scopes
    “也可以进行AND,OR运算,然后减去范围选择器,例如:(a | b) & c - d将选择
    范围与d不匹配,并且与cab都匹配。”
  • Beta 17 notes: Scope selectors
    “可以在范围选择器上执行 bool 运算并采取非对称差异
    在两个范围选择器之间。因此,在上面的示例中,我们希望对#的自定义操作扩展为source.ruby string,但我们不希望将它用于string source(字符串中的嵌入式代码)。为了这
    我们现在可以将范围设置为:(source.ruby string) - (string source)。我加了括号
    为了清楚起见,它们不是必需的(因为-的优先级最低)。“

  • 提供了Allan Odgaard(TextMate的创建者)
    对有关范围选择器运算符的问题的一些非常有用的回答
    TextMate mailing list。线程已存档
    here
    原始消息在这里:
    1
    2
    3
    4
    5
    6。此响应特别有帮助:

    scopes are matched literally (e.g. string). These can form a “descendent selector” e.g. source.ruby string, and for descendent selectors one can take the union (| or ,), the intersection (&), or the asymmetric difference (-).

    one can also group with parenthesis. The reason though that both , and | can be used for union is that , was introduced long before the other operators (mimics CSS syntax), so when & was added, I felt that there should be | and | has higher precedence than , it is the operator with lowest precedence, so e.g.:

    a - b | c & d, e - f | g & h ⇔ (a - b | c & d), (e - f | g & h)
    


    TextMate支持Sublime Text不支持的其他运算符,包括*^>$L:R:B:。这些记录在这里:
    1
    2
    3
    4

    关于scope - Sublime Text : scope selector operators,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33562253/

    相关文章:

    vb.net - With... End With vs Using in VB.NET

    c++ - 回复未在此范围内声明

    C++ If 语句变量作用域

    c - i++, i=i+1 和 i+=1 哪个更快?

    javascript - 为什么将 $(this) 分配给 var

    R: += (plus equals) 和++ (plus plus) 等价于 c++/c#/java 等?

    C++ vector<T>::迭代器运算符 +

    javascript - 使用 Sublime Text 的 jquery 插件验证引擎的 JS 中带条件的正则表达式

    javascript - 如何将应用程序从 Sublime Text 引入 Web IDE 进行共享?

    sublimetext2 - sublimetext2中的项目特定主题