Skip to content

Commit

Permalink
C++: Fixed enum class class names (#2342)
Browse files Browse the repository at this point in the history
The `class` keyword in `enum class` enums was falsely highlighted as the class name.
  • Loading branch information
jsmolka authored Apr 29, 2020
1 parent 33e4995 commit 30b4e25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-cpp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Prism.languages.cpp = Prism.languages.extend('c', {
'class-name': {
pattern: /(\b(?:class|enum|struct)\s+)\w+/,
pattern: /(\b(?:class|enum|struct)\s+)(?!class|enum|struct)\w+/,
lookbehind: true
},
'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/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-cpp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/languages/cpp/class-name_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ class Foo
class Foo_bar
struct foo
enum bar
enum class FooBar

----------------------------------------------------

[
["keyword", "class"], ["class-name", "Foo"],
["keyword", "class"], ["class-name", "Foo_bar"],
["keyword", "struct"], ["class-name", "foo"],
["keyword", "enum"], ["class-name", "bar"]
["keyword", "enum"], ["class-name", "bar"],
["keyword", "enum"], ["keyword", "class"], ["class-name", "FooBar"]
]

----------------------------------------------------
Expand Down

0 comments on commit 30b4e25

Please sign in to comment.