Sublime Forum

[BUG][FIX] Valid C syntax marked as invalid.illegal

#1

The current ST3 build (3035) has incorrect syntax highlighting for this perfectly valid C code:

<span class="syntaxdefault"><br />int main</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">int </span><span class="syntaxcomment">/*argc*/</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> char </span><span class="syntaxkeyword">*</span><span class="syntaxcomment">/*argv*/</span><span class="syntaxkeyword">])<br /></span><span class="syntaxdefault"> </span>

It sees a */ without being in a comment and triggers invalid.illegal.stray-comment-end.c which has the match \*/.*\n

The solution is to exclude the case where the / is part of a block comment start, changing the whole pattern to:

<dict>
    <key>match</key>
    <string>\*/(^*].*)?\n</string>
    <key>name</key>
    <string>invalid.illegal.stray-comment-end.c</string>
</dict>

Actual use case: When working with -Wall it is not uncommon to use block comments around the names of knowingly unused parameters to silence the warning to actually notice when a parameter was left unused by accident (shadowing etc…).

0 Likes