Syntax highlighting for >= and <= operators in Sublime Text

送分小仙女□ 提交于 2019-12-10 10:39:02

问题


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 &gt;=and &lt;= are included in the operator regex.

What could be wrong here?


回答1:


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>

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*


来源:https://stackoverflow.com/questions/22167025/syntax-highlighting-for-and-operators-in-sublime-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!