Sublime Text 中 >= 和 <= 运算符的语法高亮 [英] Syntax highlighting for >= and <= operators in 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
文件,其中包括 >=
和 <=
在运算符正则表达式中.
I've looked in the Matlab.tmLanguage
file, and both >=
and <=
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*(==|~=|>|>=|<|<=|&|&&|:|\||\|\||\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)\s*</string>
<key>name</key>
<string>keyword.operator.symbols.matlab</string>
</dict>
问题在于 或
的子表达式的顺序(|>|>=|<|<=代码>).例如.
>
在 >=
之前匹配,然后根本不匹配.所以解决方案是改变子表达式的顺序,先匹配较长的.IE.将 match
字符串更改为:
The issue is the order of the or
'ed sub-expressions (|>|>=|<|<=
). E.g. >
is matched before >=
, 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*(==|~=|>=|>|<=|<|&|&&|:|\||\|\||\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)\s*
这篇关于Sublime Text 中 >= 和 <= 运算符的语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!