Commit 462ad57eb419b095c932afe446b521cdd145fedd

Simon 2020-03-07T14:32:58

C++: Added C++20 keywords (#2236) This adds support for the ney keywords added in C++20. https://en.cppreference.com/w/cpp/keyword

diff --git a/components/prism-cpp.js b/components/prism-cpp.js
index 412d65e..08be199 100644
--- a/components/prism-cpp.js
+++ b/components/prism-cpp.js
@@ -3,7 +3,7 @@ Prism.languages.cpp = Prism.languages.extend('c', {
 		pattern: /(\b(?:class|enum|struct)\s+)\w+/,
 		lookbehind: true
 	},
-	'keyword': /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|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|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/,
+	'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/,
 	'number': {
 		pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,
 		greedy: true
diff --git a/components/prism-cpp.min.js b/components/prism-cpp.min.js
index 6e8c5dd..819c167 100644
--- a/components/prism-cpp.min.js
+++ b/components/prism-cpp.min.js
@@ -1 +1 @@
-Prism.languages.cpp=Prism.languages.extend("c",{"class-name":{pattern:/(\b(?:class|enum|struct)\s+)\w+/,lookbehind:!0},keyword:/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|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|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/,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,greedy:!0},operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:true|false)\b/}),Prism.languages.insertBefore("cpp","string",{"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}});
\ No newline at end of file
+Prism.languages.cpp=Prism.languages.extend("c",{"class-name":{pattern:/(\b(?:class|enum|struct)\s+)\w+/,lookbehind:!0},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/,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+\.?[\da-f']*|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+\.?[\d']*|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]*/i,greedy:!0},operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:true|false)\b/}),Prism.languages.insertBefore("cpp","string",{"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}});
\ No newline at end of file
diff --git a/tests/languages/cpp/keyword_feature.test b/tests/languages/cpp/keyword_feature.test
index b782149..ac72b6a 100644
--- a/tests/languages/cpp/keyword_feature.test
+++ b/tests/languages/cpp/keyword_feature.test
@@ -1,51 +1,183 @@
-alignas alignof asm auto bool
-break case catch char char16_t char32_t
+alignas
+alignof
+asm
+auto
+bool
+break
+case
+catch
+char
+char8_t
+char16_t
+char32_t
 class;
-compl const constexpr
-const_cast continue decltype default
-delete do double dynamic_cast
-else enum;
-explicit export extern
-float for friend goto if
-inline int long mutable namespace
-new noexcept nullptr operator
-private protected public register
-reinterpret_cast 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
-int8_t int16_t int32_t int64_t
-uint8_t uint16_t uint32_t uint64_t
+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
+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
+int8_t
+int16_t
+int32_t
+int64_t
+uint8_t
+uint16_t
+uint32_t
+uint64_t
 
 ----------------------------------------------------
 
 [
-	["keyword", "alignas"], ["keyword", "alignof"], ["keyword", "asm"], ["keyword", "auto"], ["keyword", "bool"],
-	["keyword", "break"], ["keyword", "case"], ["keyword", "catch"], ["keyword", "char"], ["keyword", "char16_t"], ["keyword", "char32_t"],
+	["keyword", "alignas"],
+	["keyword", "alignof"],
+	["keyword", "asm"],
+	["keyword", "auto"],
+	["keyword", "bool"],
+	["keyword", "break"],
+	["keyword", "case"],
+	["keyword", "catch"],
+	["keyword", "char"],
+	["keyword", "char8_t"],
+	["keyword", "char16_t"],
+	["keyword", "char32_t"],
 	["keyword", "class"], ["punctuation", ";"],
-	["keyword", "compl"], ["keyword", "const"], ["keyword", "constexpr"],
-	["keyword", "const_cast"], ["keyword", "continue"], ["keyword", "decltype"], ["keyword", "default"],
-	["keyword", "delete"], ["keyword", "do"], ["keyword", "double"], ["keyword", "dynamic_cast"],
-	["keyword", "else"], ["keyword", "enum"], ["punctuation", ";"],
-	["keyword", "explicit"], ["keyword", "export"], ["keyword", "extern"],
-	["keyword", "float"], ["keyword", "for"], ["keyword", "friend"], ["keyword", "goto"], ["keyword", "if"],
-	["keyword", "inline"], ["keyword", "int"], ["keyword", "long"], ["keyword", "mutable"], ["keyword", "namespace"],
-	["keyword", "new"], ["keyword", "noexcept"], ["keyword", "nullptr"], ["keyword", "operator"],
-	["keyword", "private"], ["keyword", "protected"], ["keyword", "public"], ["keyword", "register"],
-	["keyword", "reinterpret_cast"], ["keyword", "return"], ["keyword", "short"],
-	["keyword", "signed"], ["keyword", "sizeof"], ["keyword", "static"], ["keyword", "static_assert"],
-	["keyword", "static_cast"], ["keyword", "struct"], ["punctuation", ";"],
-	["keyword", "switch"], ["keyword", "template"],
-	["keyword", "this"], ["keyword", "thread_local"], ["keyword", "throw"], ["keyword", "try"],
-	["keyword", "typedef"], ["keyword", "typeid"], ["keyword", "typename"], ["keyword", "union"],
-	["keyword", "unsigned"], ["keyword", "using"], ["keyword", "virtual"], ["keyword", "void"],
-	["keyword", "volatile"], ["keyword", "wchar_t"], ["keyword", "while"],
-	["keyword", "int8_t"], ["keyword", "int16_t"], ["keyword", "int32_t"], ["keyword", "int64_t"],
-	["keyword", "uint8_t"], ["keyword", "uint16_t"], ["keyword", "uint32_t"], ["keyword", "uint64_t"]
+	["keyword", "compl"],
+	["keyword", "concept"],
+	["keyword", "const"],
+	["keyword", "consteval"],
+	["keyword", "constexpr"],
+	["keyword", "constinit"],
+	["keyword", "const_cast"],
+	["keyword", "continue"],
+	["keyword", "co_await"],
+	["keyword", "co_return"],
+	["keyword", "co_yield"],
+	["keyword", "decltype"],
+	["keyword", "default"],
+	["keyword", "delete"],
+	["keyword", "do"],
+	["keyword", "double"],
+	["keyword", "dynamic_cast"],
+	["keyword", "else"],
+	["keyword", "enum"], ["punctuation", ";"],
+	["keyword", "explicit"],
+	["keyword", "export"],
+	["keyword", "extern"],
+	["keyword", "float"],
+	["keyword", "for"],
+	["keyword", "friend"],
+	["keyword", "goto"],
+	["keyword", "if"],
+	["keyword", "inline"],
+	["keyword", "int"],
+	["keyword", "long"],
+	["keyword", "mutable"],
+	["keyword", "namespace"],
+	["keyword", "new"],
+	["keyword", "noexcept"],
+	["keyword", "nullptr"],
+	["keyword", "operator"],
+	["keyword", "private"],
+	["keyword", "protected"],
+	["keyword", "public"],
+	["keyword", "register"],
+	["keyword", "reinterpret_cast"],
+	["keyword", "requires"],
+	["keyword", "return"],
+	["keyword", "short"],
+	["keyword", "signed"],
+	["keyword", "sizeof"],
+	["keyword", "static"],
+	["keyword", "static_assert"],
+	["keyword", "static_cast"],
+	["keyword", "struct"], ["punctuation", ";"],
+	["keyword", "switch"],
+	["keyword", "template"],
+	["keyword", "this"],
+	["keyword", "thread_local"],
+	["keyword", "throw"],
+	["keyword", "try"],
+	["keyword", "typedef"],
+	["keyword", "typeid"],
+	["keyword", "typename"],
+	["keyword", "union"],
+	["keyword", "unsigned"],
+	["keyword", "using"],
+	["keyword", "virtual"],
+	["keyword", "void"],
+	["keyword", "volatile"],
+	["keyword", "wchar_t"],
+	["keyword", "while"],
+	["keyword", "int8_t"],
+	["keyword", "int16_t"],
+	["keyword", "int32_t"],
+	["keyword", "int64_t"],
+	["keyword", "uint8_t"],
+	["keyword", "uint16_t"],
+	["keyword", "uint32_t"],
+	["keyword", "uint64_t"]
 ]
 
 ----------------------------------------------------