66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
(function (Prism) {
|
|
|
|
var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|null|open|opens|package|private|protected|provides|public|record|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
|
|
|
|
// based on the java naming conventions
|
|
var className = /\b[A-Z](?:\w*[a-z]\w*)?\b/;
|
|
|
|
Prism.languages.java = Prism.languages.extend('clike', {
|
|
'class-name': [
|
|
className,
|
|
|
|
// variables and parameters
|
|
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
|
/\b[A-Z]\w*(?=\s+\w+\s*[;,=())])/
|
|
],
|
|
'keyword': keywords,
|
|
'function': [
|
|
Prism.languages.clike.function,
|
|
{
|
|
pattern: /(\:\:)[a-z_]\w*/,
|
|
lookbehind: true
|
|
}
|
|
],
|
|
'number': /\b0b[01][01_]*L?\b|\b0x[\da-f_]*\.?[\da-f_p+-]+\b|(?:\b\d[\d_]*\.?[\d_]*|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
|
|
'operator': {
|
|
pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
|
|
lookbehind: true
|
|
}
|
|
});
|
|
|
|
Prism.languages.insertBefore('java', 'string', {
|
|
'triple-quoted-string': {
|
|
// http://openjdk.java.net/jeps/355#Description
|
|
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
|
|
greedy: true,
|
|
alias: 'string'
|
|
}
|
|
});
|
|
|
|
Prism.languages.insertBefore('java', 'class-name', {
|
|
'annotation': {
|
|
alias: 'punctuation',
|
|
pattern: /(^|[^.])@\w+/,
|
|
lookbehind: true
|
|
},
|
|
'namespace': {
|
|
pattern: RegExp(
|
|
/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
|
|
.source.replace(/<keyword>/g, function () { return keywords.source; })),
|
|
lookbehind: true,
|
|
inside: {
|
|
'punctuation': /\./,
|
|
}
|
|
},
|
|
'generics': {
|
|
pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
|
|
inside: {
|
|
'class-name': className,
|
|
'keyword': keywords,
|
|
'punctuation': /[<>(),.:]/,
|
|
'operator': /[?&|]/
|
|
}
|
|
}
|
|
});
|
|
}(Prism));
|