]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/java.js
1 /*! `java` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
6 // https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
7 var decimalDigits
= '[0-9](_*[0-9])*';
8 var frac
= `\\.(${decimalDigits})`;
9 var hexDigits
= '[0-9a-fA-F](_*[0-9a-fA-F])*';
13 // DecimalFloatingPointLiteral
14 // including ExponentPart
15 { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
16 `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
17 // excluding ExponentPart
18 { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
19 { begin: `(${frac})[fFdD]?\\b` },
20 { begin: `\\b(${decimalDigits})[fFdD]\\b` },
22 // HexadecimalFloatingPointLiteral
23 { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
24 `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
26 // DecimalIntegerLiteral
27 { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
30 { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
32 // OctalIntegerLiteral
33 { begin: '\\b0(_*[0-7])*[lL]?\\b' },
35 // BinaryIntegerLiteral
36 { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
43 Author: Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
44 Category: common, enterprise
45 Website: https://www.java.com/
50 * Allows recursive regex expressions to a given depth
52 * ie: recurRegex("(abc~~~)", /~~~/g, 2) becomes:
56 * @param {RegExp} substitution (should be a g mode regex)
57 * @param {number} depth
60 function recurRegex(re
, substitution
, depth
) {
61 if (depth
=== -1) return "";
63 return re
.replace(substitution
, _
=> {
64 return recurRegex(re
, substitution
, depth
- 1);
68 /** @type LanguageFn */
70 const regex
= hljs
.regex
;
71 const JAVA_IDENT_RE
= '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';
72 const GENERIC_IDENT_RE
= JAVA_IDENT_RE
73 + recurRegex('(?:<' + JAVA_IDENT_RE
+ '~~~(?:\\s*,\\s*' + JAVA_IDENT_RE
+ '~~~)*>)?', /~~~/g, 2);
74 const MAIN_KEYWORDS
= [
144 keyword: MAIN_KEYWORDS
,
152 begin: '@' + JAVA_IDENT_RE
,
157 contains: [ "self" ] // allow nested () inside our annotation
167 contains: [ hljs
.C_BLOCK_COMMENT_MODE
],
184 // eat up @'s in emails to prevent them to be recognized as doctags
197 begin: /import java
\.[a
-z
]+\./,
201 hljs
.C_LINE_COMMENT_MODE
,
202 hljs
.C_BLOCK_COMMENT_MODE
,
207 contains: [ hljs
.BACKSLASH_ESCAPE
]
209 hljs
.APOS_STRING_MODE
,
210 hljs
.QUOTE_STRING_MODE
,
213 /\b(?:class|interface|enum|extends|implements|new)/,
223 // Exceptions for hyphenated keywords
229 regex
.concat(/(?!else)/, JAVA_IDENT_RE
),
253 hljs
.C_LINE_COMMENT_MODE
,
254 hljs
.C_BLOCK_COMMENT_MODE
258 // Expression keywords prevent 'keyword Name(...)' from being
259 // recognized as a function definition
260 beginKeywords: 'new throw return else',
265 '(?:' + GENERIC_IDENT_RE
+ '\\s+)',
266 hljs
.UNDERSCORE_IDENT_RE
,
269 className: { 2: "title.function" },
280 hljs
.APOS_STRING_MODE
,
281 hljs
.QUOTE_STRING_MODE
,
283 hljs
.C_BLOCK_COMMENT_MODE
286 hljs
.C_LINE_COMMENT_MODE
,
287 hljs
.C_BLOCK_COMMENT_MODE
300 hljs
.registerLanguage('java', hljsGrammar
);