Hi,
There a several issues with the current C/C++ grammar (actually in C.tmLanguage) related to operator overloading that make the parser fail to read legal C++ code:
-
it is legal to have any amount of space between the “operator” keyword and the actual operator (i.e. “operator ++” is legal, but only “operator++” is parsed correctly with the current grammar)
-
“operator()” is broken
-
you are missing a few operators, namely “^%|,~/”
-
you are missing the implicit conversion operators :
struct A {
operator int* ();
};
- … and new/delete overloading:
struct A {
void* operator new (size_t);
};
All these can be partially fixed by tweaking the entity.name.function.c regex (C.tmLanguage line 399-400 in v3047) from
(?: [A-Za-z_][A-Za-z0-9_]*+ | :: )++ | # actual name
(?: (?<=operator) (?: -*&<>=+!]+ | \(\) | \\] ) ) # if it is a C++ operator
to
(?: (?!operator) [A-Za-z_][A-Za-z0-9_]*+ | :: )++ | # actual name
(?: operator (?: \s* -*&<>=+!^%|,~/]+ | \s* \(\) | \s* \\] | (?:\s*(?:\*|&|[A-Za-z_][A-Za-z0-9_]*))+) ) # if it is a C++ operator
For some reason, I had to disable the positive look-behind in order to make it match when there is no space between “operator” and the operator. As a side effect, both the keyword “operator” and the operator are highlighted as function definitions. Might not be the ideal way to do it (I’m no regex expert), but at least it works.
A negative side-effect is that is seems to point out another inconsitency in the grammar, because:
this->foo(); // highlights "foo" as a function call
this->operator](i); // highlights "operator]" as a function definition
This starts to reach the end of my knowledge and expertise on both regex and Sublime Text’s behavior.