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.
I've looked in the Matlab.tmLanguage file, and both >=and <= are included in the operator regex.
What could be wrong here?
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>
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*
来源:https://stackoverflow.com/questions/22167025/syntax-highlighting-for-and-operators-in-sublime-text