Sublime Forum

C/C++ syntax highlighting bug

#1

Arguments of macros which have more than one argument can’t be hightlighted correctly.

0 Likes

[BUG] Syntax highlighting goes white at ~10KSLOC (Bld 3059)
#2

That’s because the code has undefined behavior.

0 Likes

#3

No, There is something wrong with the C.tmLanguage

Line 170: ((,) \s* \g<id> \s*)* // \g dosen’t work
Line 171: (?:...)? // should be corrected as (?:,\s*...\s*)?

0 Likes

#4

In short…

replace starting at line 162 with this:

[pre=#2D2D2D] begin
(?x)
^\s*#\s*(define)\s+ # define
(([a-zA-Z_][a-zA-Z0-9_])) # macro name
(?: # and optionally:
(() # an open parenthesis
(
\s
([a-zA-Z_][a-zA-Z0-9_]) \s # first argument
((,) \s* ([a-zA-Z_][a-zA-Z0-9_]) \s)* # additional arguments
(?:,\s*...\s*)? # varargs ellipsis?
)
()) # a close parenthesis
)?
[/pre]

0 Likes

#5

Sigh. No sense of humor.

0 Likes

#6

Hi, I also noticed some bugs in C++ syntax highlighting.

Keywords public/private/**protected **are not properly highlighted for base classes.

Method name highlighting breaks in classes with more than one base class.

Edit: There’s also bug when calling template functions/methods.

0 Likes

#7

[quote=“facelessuser”]In short…
replace starting at line 162 with this: …
[/quote]

Yeah, but even if this is fixed, there is still a second problem - The commas separating the macro arguments would be highlighted along with the macro arguments!
And the this problem can’t be solved just by editing the C.tmLanguage… It got me, a perfectionist, anxious.
.jpg (14.3 KB)

0 Likes

#8

:cry: I can’t see the pictures
sigh, really wish the author work more on C/C++ syntax highlighting.

0 Likes

#9

Yeah, but even if this is fixed, there is still a second problem - The commas separating the macro arguments would be highlighted along with the macro arguments!
And the this problem can’t be solved just by editing the C.tmLanguage… It got me, a perfectionist, anxious.[/quote]

This can be fixed as well in the C.tmLanguage. It would just require some more complexity. I don’t have time right now, but maybe in a couple of days.

[quote=“jwegrzyn”]Hi, I also noticed some bugs in C++ syntax highlighting.

Keywords public/private/**protected **are not properly highlighted for base classes.

Method name highlighting breaks in classes with more than one base class.

Edit: There’s also bug when calling template functions/methods.

Yes, the C tmLanguage file isn’t that good. It needs a lot of work. I do a little here and there on my own personal copy of it. I mainly try to hit the things that annoy me most since I stare at C code all day.

0 Likes

#10

[quote=“Prazz”]

:cry: I can’t see the pictures.[/quote]

I’m not sure why you can’t see them. They are uploaded to CloudApp so maybe there are some issues with the service.

I’m spending most of my time working with C++ code and those little things are making me crazy :wink: Editing *.tmLanguage files is not trivial task, but maybe someone had worked on similar issues and simply will share some solutions.

It is a little suprising to see such limited support for C/C++, I belive that ST2 was written mainly with C++ so you could expect that it will at least provide better syntax highlighting.

0 Likes

#11

That will be great! Thanks!

0 Likes

#12

Similar problem can be seen here:

0 Likes

#13

The c++ syntax parsing issues are still not fixed.

I’m using ST3 build 3103.

0 Likes

#14

It was largely improved in latest dev build (3110), most bugs described here were fixed (except the template function one)

0 Likes

#15

Thanks for responding.
Is it just to modify the corresponding regex in C++ syntax definition for fixing the template function highlighting bugs?

0 Likes

#16

Yes, but if you do a modification please submit it to the package repository so that your fix can be integrated in the next ST release.
I just submitted the issue on the repo.

0 Likes

#17

I’d like to contribute. But I have some questions about the regex used in ST3 c++ syntax.
For example, what is the meaning of *+ and ++ in the following snippets:

    - match: |-
        (?x) (?: (?= \s )  (?:(?<=else|new|return) | (?<!\w)) (\s+))?
        (\b
          (?!(while|for|do|if|else|switch|catch|enumerate|return|r?iterate)\s*\()(?:(?!NS)[A-Za-z_][A-Za-z0-9_<>]*+\b | :: )++   # <-
        )
         \s*(\()
      scope: meta.function-call.c
0 Likes

#18

Possessive Quantifiers - similar to how atomic groups work: http://www.regular-expressions.info/possessive.html

0 Likes

#19

As @kingkeith mentioned, those are possessive quantifiers. However, the snippet you referenced is from an old version of the C++ (or C) syntax. We don’t use possessive quantifiers in the default packages moving forward since they are not supported by the new regex engine. Additionally, they are usually not needed if the contexts in the syntax are constructed in a certain way.

The latest versions of the packages are hosted at https://github.com/sublimehq/Packages. You can learn more about the syntax file and testing it at http://www.sublimetext.com/docs/3/syntax.html.

0 Likes