Question

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?

Was it helpful?

Solution

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*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top