jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
154 stars 29 forks source link

Syntax highlight fails for line inheriting from templated class and not finishing with "{" #629

Open jmigual opened 1 year ago

jmigual commented 1 year ago

Checklist

The code with a problem is:

// With templates
template <typename T> class MyClass {
};
template <typename T> class MyDerivedClass : public MyClass<T> 
{
};
template <typename T> class MyDerivedClass2 : public MyClass<T> {
};

// Without templates
class NonTemplate {
};
template <typename t> class MyDerivedClass3 : public NonTemplate 
{
};
template <typename t> class MyDerivedClass4 : public NonTemplate {
};

It looks like:

code

Default VS code theme (Dark+)

It should look like:

Line 4 has the keywords "class" and "public" in blue, the words "MyDerivedClass" and "MyClass" in green and the token "T" in green.


Related issues:

jeff-hykin commented 1 year ago

This is probably going to be a tough one to fix.

Its this is happening because of the screwed up template pattern. The "T> class MyDerivedClass : public MyClass<T is swallowed by the <> of the first template.

C++ thought it'd be great to allow less-than and greater-than operators inside of template angle brackets, and it turns out thats a very hard thing to parse inside of recursive regular expressions. So this is kind of an artifact of that difficulty. The whole template matching pattern needs to be rewritten