Commit 7af8f8bec0f32f02ed6d5ceee1f3e2cc38fb25bc

Michael Schmidt 2018-08-19T17:09:29

C/C++/Java operator update (#1528) This PR extends and updates the operators of C, C++, and Java. Java and C++ now support the -> operator. (C++ had a bug.) The tests of all languages were updated and the operator pattern for each language is now shorter.

diff --git a/components/prism-c.js b/components/prism-c.js
index 86ffac0..ea2452d 100644
--- a/components/prism-c.js
+++ b/components/prism-c.js
@@ -1,6 +1,6 @@
 Prism.languages.c = Prism.languages.extend('clike', {
 	'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
-	'operator': /-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]/,
+	'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/,
 	'number': /(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i
 });
 
diff --git a/components/prism-c.min.js b/components/prism-c.min.js
index 764ba0c..78b49c9 100644
--- a/components/prism-c.min.js
+++ b/components/prism-c.min.js
@@ -1 +1 @@
-Prism.languages.c=Prism.languages.extend("clike",{keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,operator:/-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]/,number:/(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,alias:"property",inside:{string:{pattern:/(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,lookbehind:!0},directive:{pattern:/(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,lookbehind:!0,alias:"keyword"}}},constant:/\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/}),delete Prism.languages.c["class-name"],delete Prism.languages.c["boolean"];
\ No newline at end of file
+Prism.languages.c=Prism.languages.extend("clike",{keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*\/%&|^!=<>]=?/,number:/(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,alias:"property",inside:{string:{pattern:/(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,lookbehind:!0},directive:{pattern:/(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,lookbehind:!0,alias:"keyword"}}},constant:/\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/}),delete Prism.languages.c["class-name"],delete Prism.languages.c["boolean"];
\ No newline at end of file
diff --git a/components/prism-cpp.js b/components/prism-cpp.js
index 1228e0f..3d66ba2 100644
--- a/components/prism-cpp.js
+++ b/components/prism-cpp.js
@@ -1,7 +1,7 @@
 Prism.languages.cpp = Prism.languages.extend('c', {
 	'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/,
 	'boolean': /\b(?:true|false)\b/,
-	'operator': /--?|\+\+?|!=?|<{1,2}=?|>{1,2}=?|->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|\|?|\?|\*|\/|\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/
 });
 
 Prism.languages.insertBefore('cpp', 'keyword', {
diff --git a/components/prism-cpp.min.js b/components/prism-cpp.min.js
index 4383acc..c0c6a00 100644
--- a/components/prism-cpp.min.js
+++ b/components/prism-cpp.min.js
@@ -1 +1 @@
-Prism.languages.cpp=Prism.languages.extend("c",{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/,"boolean":/\b(?:true|false)\b/,operator:/--?|\+\+?|!=?|<{1,2}=?|>{1,2}=?|->|:{1,2}|={1,2}|\^|~|%|&{1,2}|\|\|?|\?|\*|\/|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/}),Prism.languages.insertBefore("cpp","keyword",{"class-name":{pattern:/(class\s+)\w+/i,lookbehind:!0}}),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",{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/,"boolean":/\b(?:true|false)\b/,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*\/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/}),Prism.languages.insertBefore("cpp","keyword",{"class-name":{pattern:/(class\s+)\w+/i,lookbehind:!0}}),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/components/prism-java.js b/components/prism-java.js
index 881b306..6719969 100644
--- a/components/prism-java.js
+++ b/components/prism-java.js
@@ -2,7 +2,7 @@ Prism.languages.java = Prism.languages.extend('clike', {
 	'keyword': /\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,
 	'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,
 	'operator': {
-		pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
+		pattern: /(^|[^.])(?:<<=?|>>>?=?|->|([-+&|])\2|[?:~]|[-+*/%&|^!=<>]=?)/m,
 		lookbehind: true
 	}
 });
diff --git a/components/prism-java.min.js b/components/prism-java.min.js
index e583b73..24c928c 100644
--- a/components/prism-java.min.js
+++ b/components/prism-java.min.js
@@ -1 +1 @@
-Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}}),Prism.languages.insertBefore("java","class-name",{generics:{pattern:/<\s*\w+(?:\.\w+)?(?:\s*,\s*\w+(?:\.\w+)?)*>/i,alias:"function",inside:{keyword:Prism.languages.java.keyword,punctuation:/[<>(),.:]/}}});
\ No newline at end of file
+Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(?:abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp-]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?[df]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|([-+&|])\2|[?:~]|[-+*\/%&|^!=<>]=?)/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}}),Prism.languages.insertBefore("java","class-name",{generics:{pattern:/<\s*\w+(?:\.\w+)?(?:\s*,\s*\w+(?:\.\w+)?)*>/i,alias:"function",inside:{keyword:Prism.languages.java.keyword,punctuation:/[<>(),.:]/}}});
\ No newline at end of file
diff --git a/tests/languages/c/operator_feature.test b/tests/languages/c/operator_feature.test
index fdcfb19..95cef64 100644
--- a/tests/languages/c/operator_feature.test
+++ b/tests/languages/c/operator_feature.test
@@ -1,19 +1,61 @@
-+ - ++ -- ! !=
-< << <= <<=
-> >> >= >>=
--> == ^ ~ %
-& && | || ? * /
++ - * / % -- ++
+>> <<
+~ & | ^
++= -= *= /= %= >>= <<= &= |= ^=
+! && ||
+-> ::
+? :
+= == != < > <= >=
 
 ----------------------------------------------------
 
 [
-	["operator", "+"], ["operator", "-"], ["operator", "++"], ["operator", "--"], ["operator", "!"], ["operator", "!="],
-	["operator", "<"], ["operator", "<<"], ["operator", "<="], ["operator", "<<="],
-	["operator", ">"], ["operator", ">>"], ["operator", ">="], ["operator", ">>="],
-	["operator", "->"], ["operator", "=="], ["operator", "^"], ["operator", "~"], ["operator", "%"],
-	["operator", "&"], ["operator", "&&"], ["operator", "|"], ["operator", "||"], ["operator", "?"], ["operator", "*"], ["operator", "/"]
+	["operator", "+"],
+	["operator", "-"],
+	["operator", "*"],
+	["operator", "/"],
+	["operator", "%"],
+	["operator", "--"],
+	["operator", "++"],
+
+	["operator", ">>"],
+	["operator", "<<"],
+
+	["operator", "~"],
+	["operator", "&"],
+	["operator", "|"],
+	["operator", "^"],
+
+	["operator", "+="],
+	["operator", "-="],
+	["operator", "*="],
+	["operator", "/="],
+	["operator", "%="],
+	["operator", ">>="],
+	["operator", "<<="],
+	["operator", "&="],
+	["operator", "|="],
+	["operator", "^="],
+
+	["operator", "!"],
+	["operator", "&&"],
+	["operator", "||"],
+
+	["operator", "->"],
+	["operator", "::"],
+
+	["operator", "?"],
+	["operator", ":"],
+
+	["operator", "="],
+	["operator", "=="],
+	["operator", "!="],
+	["operator", "<"],
+	["operator", ">"],
+	["operator", "<="],
+	["operator", ">="]
 ]
 
 ----------------------------------------------------
 
-Checks for all operators
\ No newline at end of file
+Checks for all operators
diff --git a/tests/languages/cpp/operator_feature.test b/tests/languages/cpp/operator_feature.test
new file mode 100644
index 0000000..a29f08e
--- /dev/null
+++ b/tests/languages/cpp/operator_feature.test
@@ -0,0 +1,73 @@
++ - * / % -- ++
+>> <<
+~ & | ^
++= -= *= /= %= >>= <<= &= |= ^=
+! && ||
+-> ::
+? :
+= == != < > <= >=
+and and_eq bitand bitor not not_eq or or_eq xor xor_eq
+
+----------------------------------------------------
+
+[
+	["operator", "+"],
+	["operator", "-"],
+	["operator", "*"],
+	["operator", "/"],
+	["operator", "%"],
+	["operator", "--"],
+	["operator", "++"],
+
+	["operator", ">>"],
+	["operator", "<<"],
+
+	["operator", "~"],
+	["operator", "&"],
+	["operator", "|"],
+	["operator", "^"],
+
+	["operator", "+="],
+	["operator", "-="],
+	["operator", "*="],
+	["operator", "/="],
+	["operator", "%="],
+	["operator", ">>="],
+	["operator", "<<="],
+	["operator", "&="],
+	["operator", "|="],
+	["operator", "^="],
+
+	["operator", "!"],
+	["operator", "&&"],
+	["operator", "||"],
+
+	["operator", "->"],
+	["operator", "::"],
+
+	["operator", "?"],
+	["operator", ":"],
+
+	["operator", "="],
+	["operator", "=="],
+	["operator", "!="],
+	["operator", "<"],
+	["operator", ">"],
+	["operator", "<="],
+	["operator", ">="],
+
+	["operator", "and"],
+	["operator", "and_eq"],
+	["operator", "bitand"],
+	["operator", "bitor"],
+	["operator", "not"],
+	["operator", "not_eq"],
+	["operator", "or"],
+	["operator", "or_eq"],
+	["operator", "xor"],
+	["operator", "xor_eq"]
+]
+
+----------------------------------------------------
+
+Checks for all operators.
diff --git a/tests/languages/java/operator_feature.test b/tests/languages/java/operator_feature.test
index 87f4906..8c8eb39 100644
--- a/tests/languages/java/operator_feature.test
+++ b/tests/languages/java/operator_feature.test
@@ -7,9 +7,11 @@
 & && &=
 | || |=
 ? : ~
+^ ^=
 * *=
 / /=
 % %=
+->
 
 ----------------------------------------------------
 
@@ -23,11 +25,13 @@
 	["operator", "&"], ["operator", "&&"], ["operator", "&="],
 	["operator", "|"], ["operator", "||"], ["operator", "|="],
 	["operator", "?"], ["operator", ":"], ["operator", "~"],
+	["operator", "^"], ["operator", "^="],
 	["operator", "*"], ["operator", "*="],
 	["operator", "/"], ["operator", "/="],
-	["operator", "%"], ["operator", "%="]
+	["operator", "%"], ["operator", "%="],
+	["operator", "->"]
 ]
 
 ----------------------------------------------------
 
-Checks for all operators.
\ No newline at end of file
+Checks for all operators.