[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | module.exports = java
|
---|
| 4 | java.displayName = 'java'
|
---|
| 5 | java.aliases = []
|
---|
| 6 | function java(Prism) {
|
---|
| 7 | ;(function (Prism) {
|
---|
| 8 | var keywords =
|
---|
| 9 | /\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|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/ // full package (optional) + parent classes (optional)
|
---|
| 10 | var classNamePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/
|
---|
| 11 | .source // based on the java naming conventions
|
---|
| 12 | var className = {
|
---|
| 13 | pattern: RegExp(classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
|
---|
| 14 | lookbehind: true,
|
---|
| 15 | inside: {
|
---|
| 16 | namespace: {
|
---|
| 17 | pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
|
---|
| 18 | inside: {
|
---|
| 19 | punctuation: /\./
|
---|
| 20 | }
|
---|
| 21 | },
|
---|
| 22 | punctuation: /\./
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
| 25 | Prism.languages.java = Prism.languages.extend('clike', {
|
---|
| 26 | string: {
|
---|
| 27 | pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
|
---|
| 28 | lookbehind: true,
|
---|
| 29 | greedy: true
|
---|
| 30 | },
|
---|
| 31 | 'class-name': [
|
---|
| 32 | className,
|
---|
| 33 | {
|
---|
| 34 | // variables and parameters
|
---|
| 35 | // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
---|
| 36 | pattern: RegExp(
|
---|
| 37 | classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source
|
---|
| 38 | ),
|
---|
| 39 | lookbehind: true,
|
---|
| 40 | inside: className.inside
|
---|
| 41 | }
|
---|
| 42 | ],
|
---|
| 43 | keyword: keywords,
|
---|
| 44 | function: [
|
---|
| 45 | Prism.languages.clike.function,
|
---|
| 46 | {
|
---|
| 47 | pattern: /(::\s*)[a-z_]\w*/,
|
---|
| 48 | lookbehind: true
|
---|
| 49 | }
|
---|
| 50 | ],
|
---|
| 51 | number:
|
---|
| 52 | /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
|
---|
| 53 | operator: {
|
---|
| 54 | pattern:
|
---|
| 55 | /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
|
---|
| 56 | lookbehind: true
|
---|
| 57 | }
|
---|
| 58 | })
|
---|
| 59 | Prism.languages.insertBefore('java', 'string', {
|
---|
| 60 | 'triple-quoted-string': {
|
---|
| 61 | // http://openjdk.java.net/jeps/355#Description
|
---|
| 62 | pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
|
---|
| 63 | greedy: true,
|
---|
| 64 | alias: 'string'
|
---|
| 65 | },
|
---|
| 66 | char: {
|
---|
| 67 | pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
|
---|
| 68 | greedy: true
|
---|
| 69 | }
|
---|
| 70 | })
|
---|
| 71 | Prism.languages.insertBefore('java', 'class-name', {
|
---|
| 72 | annotation: {
|
---|
| 73 | pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
|
---|
| 74 | lookbehind: true,
|
---|
| 75 | alias: 'punctuation'
|
---|
| 76 | },
|
---|
| 77 | generics: {
|
---|
| 78 | pattern:
|
---|
| 79 | /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
|
---|
| 80 | inside: {
|
---|
| 81 | 'class-name': className,
|
---|
| 82 | keyword: keywords,
|
---|
| 83 | punctuation: /[<>(),.:]/,
|
---|
| 84 | operator: /[?&|]/
|
---|
| 85 | }
|
---|
| 86 | },
|
---|
| 87 | namespace: {
|
---|
| 88 | pattern: RegExp(
|
---|
| 89 | /(\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(
|
---|
| 90 | /<keyword>/g,
|
---|
| 91 | function () {
|
---|
| 92 | return keywords.source
|
---|
| 93 | }
|
---|
| 94 | )
|
---|
| 95 | ),
|
---|
| 96 | lookbehind: true,
|
---|
| 97 | inside: {
|
---|
| 98 | punctuation: /\./
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | })
|
---|
| 102 | })(Prism)
|
---|
| 103 | }
|
---|