]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/java.js
1 /*! `java` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
5 // https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
6 var decimalDigits
= '[0-9](_*[0-9])*';
7 var frac
= `\\.(${decimalDigits})`;
8 var hexDigits
= '[0-9a-fA-F](_*[0-9a-fA-F])*';
12 // DecimalFloatingPointLiteral
13 // including ExponentPart
14 { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
15 `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
16 // excluding ExponentPart
17 { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
18 { begin: `(${frac})[fFdD]?\\b` },
19 { begin: `\\b(${decimalDigits})[fFdD]\\b` },
21 // HexadecimalFloatingPointLiteral
22 { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
23 `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
25 // DecimalIntegerLiteral
26 { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
29 { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
31 // OctalIntegerLiteral
32 { begin: '\\b0(_*[0-7])*[lL]?\\b' },
34 // BinaryIntegerLiteral
35 { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
42 Author: Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
43 Category: common, enterprise
44 Website: https://www.java.com/
49 * Allows recursive regex expressions to a given depth
51 * ie: recurRegex("(abc~~~)", /~~~/g, 2) becomes:
55 * @param {RegExp} substitution (should be a g mode regex)
56 * @param {number} depth
59 function recurRegex(re
, substitution
, depth
) {
60 if (depth
=== -1) return "";
62 return re
.replace(substitution
, _
=> {
63 return recurRegex(re
, substitution
, depth
- 1);
67 /** @type LanguageFn */
69 const regex
= hljs
.regex
;
70 const JAVA_IDENT_RE
= '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';
71 const GENERIC_IDENT_RE
= JAVA_IDENT_RE
72 + recurRegex('(?:<' + JAVA_IDENT_RE
+ '~~~(?:\\s*,\\s*' + JAVA_IDENT_RE
+ '~~~)*>)?', /~~~/g, 2);
73 const MAIN_KEYWORDS
= [
143 keyword: MAIN_KEYWORDS
,
151 begin: '@' + JAVA_IDENT_RE
,
156 contains: [ "self" ] // allow nested () inside our annotation
166 contains: [ hljs
.C_BLOCK_COMMENT_MODE
],
183 // eat up @'s in emails to prevent them to be recognized as doctags
196 begin: /import java
\.[a
-z
]+\./,
200 hljs
.C_LINE_COMMENT_MODE
,
201 hljs
.C_BLOCK_COMMENT_MODE
,
206 contains: [ hljs
.BACKSLASH_ESCAPE
]
208 hljs
.APOS_STRING_MODE
,
209 hljs
.QUOTE_STRING_MODE
,
212 /\b(?:class|interface|enum|extends|implements|new)/,
222 // Exceptions for hyphenated keywords
228 regex
.concat(/(?!else)/, JAVA_IDENT_RE
),
252 hljs
.C_LINE_COMMENT_MODE
,
253 hljs
.C_BLOCK_COMMENT_MODE
257 // Expression keywords prevent 'keyword Name(...)' from being
258 // recognized as a function definition
259 beginKeywords: 'new throw return else',
264 '(?:' + GENERIC_IDENT_RE
+ '\\s+)',
265 hljs
.UNDERSCORE_IDENT_RE
,
268 className: { 2: "title.function" },
279 hljs
.APOS_STRING_MODE
,
280 hljs
.QUOTE_STRING_MODE
,
282 hljs
.C_BLOCK_COMMENT_MODE
285 hljs
.C_LINE_COMMENT_MODE
,
286 hljs
.C_BLOCK_COMMENT_MODE
299 export default hljsGrammar
;