Sublime Text 中 >= 和 <= 运算符的语法高亮 [英] Syntax highlighting for >= and <= operators in Sublime Text

查看:56
本文介绍了Sublime Text 中 >= 和 <= 运算符的语法高亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Matlab 运算符 >=<= 获得正确的语法突出显示.目前,只有 <> 被高亮显示——而不是 =.但是例如== 突出显示.

I am trying to get proper syntax highlighting for the Matlab operators >= and <=. Currently, only < and > are highlighted -- not the =. But e.g. == is highlighted.

我查看了 Matlab.tmLanguage 文件,其中包括 &gt;=&lt;=在运算符正则表达式中.

I've looked in the Matlab.tmLanguage file, and both &gt;=and &lt;= are included in the operator regex.

这里有什么问题?

推荐答案

问题在于完整的正则表达式,可在以下位置找到:

The issue is with the complete regex, which is found under:

</dict>
<key>operators</key>
<dict>
    <key>comment</key>
    <string>Operator symbols</string>
    <key>match</key>
    <string>\s*(==|~=|&gt;|&gt;=|&lt;|&lt;=|&amp;|&amp;&amp;|:|\||\|\||\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)\s*</string>
    <key>name</key>
    <string>keyword.operator.symbols.matlab</string>
</dict>

问题在于 的子表达式的顺序(|&gt;|&gt;=|&lt;|&lt;=).例如.&gt;&gt;= 之前匹配,然后根本不匹配.所以解决方案是改变子表达式的顺序,先匹配较长的.IE.将 match 字符串更改为:

The issue is the order of the or'ed sub-expressions (|&gt;|&gt;=|&lt;|&lt;=). E.g. &gt; is matched before &gt;=, which then isn't matched at all. So the solution is to change the order of the subexpressions, matching the longer first. I.e. change the match string to:

 \s*(==|~=|&gt;=|&gt;|&lt;=|&lt;|&amp;|&amp;&amp;|:|\||\|\||\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)\s*

这篇关于Sublime Text 中 &gt;= 和 &lt;= 运算符的语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆