Skip to content

Commit

Permalink
C++: Added support for default comparison operator (PrismJS#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored and quentinvernot committed Sep 11, 2020
1 parent 3804d08 commit 7b486cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
13 changes: 5 additions & 8 deletions components/prism-cpp.js
Expand Up @@ -5,7 +5,7 @@
Prism.languages.cpp = Prism.languages.extend('c', {
'class-name': [
{
pattern: RegExp(/(\b(?:class|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source
.replace(/<keyword>/g, function () { return keyword.source; })),
lookbehind: true
},
Expand All @@ -17,19 +17,16 @@
// This will capture the class name before destructors like:
// Foo::~Foo() {}
/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
{
// This also intends to capture the class name of method implementations but here the class has template
// parameters, so it can't be a namespace (until C++ adds generic namespaces).
pattern: /\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/,
inside: null // see below
}
// This also intends to capture the class name of method implementations but here the class has template
// parameters, so it can't be a namespace (until C++ adds generic namespaces).
/\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
],
'keyword': keyword,
'number': {
pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,
greedy: true
},
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
'boolean': /\b(?:true|false)\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.

2 changes: 2 additions & 0 deletions tests/languages/cpp/class-name_feature.test
@@ -1,5 +1,6 @@
class Foo
class Foo_bar
concept Foo_bar
struct foo
enum bar
enum class FooBar
Expand All @@ -14,6 +15,7 @@ void Foo<int>::bar() {}
[
["keyword", "class"], ["class-name", "Foo"],
["keyword", "class"], ["class-name", "Foo_bar"],
["keyword", "concept"], ["class-name", "Foo_bar"],
["keyword", "struct"], ["class-name", "foo"],
["keyword", "enum"], ["class-name", "bar"],
["keyword", "enum"], ["keyword", "class"], ["class-name", "FooBar"],
Expand Down
3 changes: 2 additions & 1 deletion tests/languages/cpp/operator_feature.test
Expand Up @@ -5,7 +5,7 @@
! && ||
-> ::
? :
= == != < > <= >=
= == != < > <= >= <=>
and and_eq bitand bitor not not_eq or or_eq xor xor_eq

----------------------------------------------------
Expand Down Expand Up @@ -55,6 +55,7 @@ and and_eq bitand bitor not not_eq or or_eq xor xor_eq
["operator", ">"],
["operator", "<="],
["operator", ">="],
["operator", "<=>"],

["operator", "and"],
["operator", "and_eq"],
Expand Down

0 comments on commit 7b486cc

Please sign in to comment.