Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Added support for default comparison operator #2426

Merged
merged 1 commit into from Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
}
// 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