Skip to content

Commit

Permalink
C/C++/Java operator update (#1528)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Aug 19, 2018
1 parent e63d159 commit 7af8f8b
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 19 deletions.
2 changes: 1 addition & 1 deletion components/prism-c.js
Original file line number Diff line number Diff line change
@@ -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
});

Expand Down
2 changes: 1 addition & 1 deletion components/prism-c.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-cpp.js
Original file line number Diff line number Diff line change
@@ -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', {
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: 1 addition & 1 deletion components/prism-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-java.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 53 additions & 11 deletions tests/languages/c/operator_feature.test
Original file line number Diff line number Diff line change
@@ -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
Checks for all operators
73 changes: 73 additions & 0 deletions tests/languages/cpp/operator_feature.test
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions tests/languages/java/operator_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
& && &=
| || |=
? : ~
^ ^=
* *=
/ /=
% %=
->

----------------------------------------------------

Expand All @@ -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.
Checks for all operators.

0 comments on commit 7af8f8b

Please sign in to comment.