Home Download Buy Blog Forum Support

Syntax highlighting (C++)

Syntax highlighting (C++)

Postby BLK Dragon on Tue Feb 12, 2013 3:45 pm

The symbols/operators in C++ (stuff like brackets, == && += etc) colored just like normal text.
It is what's intended or is it a bug?
Am I missing some settings in language/theme definition?

ST3 build#3012
BLK Dragon
 
Posts: 2
Joined: Tue Feb 12, 2013 3:41 pm

Re: Syntax highlighting (C++)

Postby qgates on Wed Feb 13, 2013 1:12 am

There are two things that affect this, 1. The chosen colouriser and 2. the syntax definition for the language. I assume you are using the correct syntax for you file (check the bottom right on Sublime's status, it should say C++).

The chosen colour scheme defines "how much" colourising goes on typically; I've seen some colourisers with more variation than others.

However in Sublime's C/C++/Objective C++ language definitions, brackets, operators and symbols are coloured the same. The Java language definition by contrast highlights them differently, even with the same colouriser chosen (the default Monokai for example). I'd suggest having a looksee at the Java syntax defs, migrating some of these across to the C/C++ ones if you really want operators and the like coloured differently.
qgates
 
Posts: 230
Joined: Mon Nov 05, 2012 4:33 pm

Re: Syntax highlighting (C++)

Postby Grant on Wed Feb 13, 2013 4:06 pm

if you do whatq gates suggests, feel free to share your results :)
Grant
 
Posts: 68
Joined: Fri Jan 20, 2012 2:42 pm

Re: Syntax highlighting (C++)

Postby BLK Dragon on Thu Feb 14, 2013 7:39 am

qgates wrote:There are two things that affect this, 1. The chosen colouriser and 2. the syntax definition for the language.
[...]


Thanks, now I understand what I need to do.

Grant wrote:if you do whatq gates suggests, feel free to share your results :)

Yeah, of course.
BLK Dragon
 
Posts: 2
Joined: Tue Feb 12, 2013 3:41 pm

Re: Syntax highlighting (C++)

Postby domshyra on Wed Feb 27, 2013 2:45 am

I have also noticed that in classes Struct.dataType will work but Struct->ptDataType wont work the same... idk but something else to see if you can solve haha
domshyra
 
Posts: 1
Joined: Wed Feb 27, 2013 2:44 am

Re: Syntax highlighting (C++)

Postby qgates on Sun Mar 03, 2013 2:19 am

domshyra wrote:I have also noticed that in classes Struct.dataType will work but Struct->ptDataType wont work the same... idk but something else to see if you can solve haha

In contrast to the thread starter's issue, your problem comes down to the colouriser that's in use.

In other words, Sublime's C++ syntax definition does differentiate these items (ie. data member of struct vs. data member of struct pointer); some colourisers choose to show this difference and some don't. Which is fine, because either choice is probably a matter of taste.

The colouriser I use (Tomorrow Night) does show the difference; Monokai (Sublime's default) doesn't.

Personally, I prefer it because in complex lines like:

structptr->someclassinstance.anotherclassptr->anotherclassinstance.member;

...it's far easier to instantly see what's going on when data members of instances are colourised differently to members of pointers:

structptr->someclassinstance.anotherclassptr->anotherclassinstance.member;

Fixing your chosen colouriser to not show this difference would likely be very straightforward.
qgates
 
Posts: 230
Joined: Mon Nov 05, 2012 4:33 pm

Re: Syntax highlighting (C++)

Postby miamirulz29 on Sat Apr 06, 2013 1:23 pm

I have figured out to highlight a data member of a struct that is a pointer (struct->variable).
In sublime test, go to preferences, browse packages. Go to the c++ folder and open C.tmLanguage. For me it was line 453, but go to this part of the code:

Code: Select all
<key>access</key>
      <dict>
         <key>match</key>
         <string>\.[a-zA-Z_][a-zA-Z_0-9]*\b(?!\s*\()</string>
         <key>name</key>
         <string>variable.other.dot-access.c</string>
      </dict>


Now, in the string with the regex expression, at the end, add the following regex
Code: Select all
\->[a-zA-Z_][a-zA-Z_0-9]*\b(?!\s*\()
The final result should look like this:

Code: Select all
<key>access</key>
      <dict>
         <key>match</key>
         <string>\.[a-zA-Z_][a-zA-Z_0-9]*\b(?!\s*\()|\->[a-zA-Z_][a-zA-Z_0-9]*\b(?!\s*\()</string>
         <key>name</key>
         <string>variable.other.dot-access.c</string>
      </dict>


Your color scheme has to have a color option for the scope variable.other.dot-access (tomorrow night has this, you can add it to other color schemes as well). Just add this to your color scheme:

Code: Select all
<dict>
            <key>name</key>
            <string>Variable</string>
            <key>scope</key>
            <string>variable</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#Pick Color Here</string>
            </dict>
        </dict>
miamirulz29
 
Posts: 3
Joined: Sat Apr 06, 2013 3:09 am


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 19 guests