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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
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.