Skip to content

Commit 30b4e25

Browse files
authored
C++: Fixed enum class class names (#2342)
The `class` keyword in `enum class` enums was falsely highlighted as the class name.
1 parent 33e4995 commit 30b4e25

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

components/prism-cpp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Prism.languages.cpp = Prism.languages.extend('c', {
22
'class-name': {
3-
pattern: /(\b(?:class|enum|struct)\s+)\w+/,
3+
pattern: /(\b(?:class|enum|struct)\s+)(?!class|enum|struct)\w+/,
44
lookbehind: true
55
},
66
'keyword': /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,

components/prism-cpp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/cpp/class-name_feature.test

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ class Foo
22
class Foo_bar
33
struct foo
44
enum bar
5+
enum class FooBar
56

67
----------------------------------------------------
78

89
[
910
["keyword", "class"], ["class-name", "Foo"],
1011
["keyword", "class"], ["class-name", "Foo_bar"],
1112
["keyword", "struct"], ["class-name", "foo"],
12-
["keyword", "enum"], ["class-name", "bar"]
13+
["keyword", "enum"], ["class-name", "bar"],
14+
["keyword", "enum"], ["keyword", "class"], ["class-name", "FooBar"]
1315
]
1416

1517
----------------------------------------------------

0 commit comments

Comments
 (0)