source: node_modules/highlight.js/lib/languages/java.js@ 65b6638

main
Last change on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[d24f17c]1// https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
2var decimalDigits = '[0-9](_*[0-9])*';
3var frac = `\\.(${decimalDigits})`;
4var hexDigits = '[0-9a-fA-F](_*[0-9a-fA-F])*';
5var NUMERIC = {
6 className: 'number',
7 variants: [
8 // DecimalFloatingPointLiteral
9 // including ExponentPart
10 { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
11 `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
12 // excluding ExponentPart
13 { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
14 { begin: `(${frac})[fFdD]?\\b` },
15 { begin: `\\b(${decimalDigits})[fFdD]\\b` },
16
17 // HexadecimalFloatingPointLiteral
18 { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
19 `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
20
21 // DecimalIntegerLiteral
22 { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
23
24 // HexIntegerLiteral
25 { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
26
27 // OctalIntegerLiteral
28 { begin: '\\b0(_*[0-7])*[lL]?\\b' },
29
30 // BinaryIntegerLiteral
31 { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
32 ],
33 relevance: 0
34};
35
36/*
37Language: Java
38Author: Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
39Category: common, enterprise
40Website: https://www.java.com/
41*/
42
43function java(hljs) {
44 var JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';
45 var GENERIC_IDENT_RE = JAVA_IDENT_RE + '(<' + JAVA_IDENT_RE + '(\\s*,\\s*' + JAVA_IDENT_RE + ')*>)?';
46 var KEYWORDS = 'false synchronized int abstract float private char boolean var static null if const ' +
47 'for true while long strictfp finally protected import native final void ' +
48 'enum else break transient catch instanceof byte super volatile case assert short ' +
49 'package default double public try this switch continue throws protected public private ' +
50 'module requires exports do';
51
52 var ANNOTATION = {
53 className: 'meta',
54 begin: '@' + JAVA_IDENT_RE,
55 contains: [
56 {
57 begin: /\(/,
58 end: /\)/,
59 contains: ["self"] // allow nested () inside our annotation
60 },
61 ]
62 };
63 const NUMBER = NUMERIC;
64
65 return {
66 name: 'Java',
67 aliases: ['jsp'],
68 keywords: KEYWORDS,
69 illegal: /<\/|#/,
70 contains: [
71 hljs.COMMENT(
72 '/\\*\\*',
73 '\\*/',
74 {
75 relevance: 0,
76 contains: [
77 {
78 // eat up @'s in emails to prevent them to be recognized as doctags
79 begin: /\w+@/, relevance: 0
80 },
81 {
82 className: 'doctag',
83 begin: '@[A-Za-z]+'
84 }
85 ]
86 }
87 ),
88 // relevance boost
89 {
90 begin: /import java\.[a-z]+\./,
91 keywords: "import",
92 relevance: 2
93 },
94 hljs.C_LINE_COMMENT_MODE,
95 hljs.C_BLOCK_COMMENT_MODE,
96 hljs.APOS_STRING_MODE,
97 hljs.QUOTE_STRING_MODE,
98 {
99 className: 'class',
100 beginKeywords: 'class interface enum', end: /[{;=]/, excludeEnd: true,
101 // TODO: can this be removed somehow?
102 // an extra boost because Java is more popular than other languages with
103 // this same syntax feature (this is just to preserve our tests passing
104 // for now)
105 relevance: 1,
106 keywords: 'class interface enum',
107 illegal: /[:"\[\]]/,
108 contains: [
109 { beginKeywords: 'extends implements' },
110 hljs.UNDERSCORE_TITLE_MODE
111 ]
112 },
113 {
114 // Expression keywords prevent 'keyword Name(...)' from being
115 // recognized as a function definition
116 beginKeywords: 'new throw return else',
117 relevance: 0
118 },
119 {
120 className: 'class',
121 begin: 'record\\s+' + hljs.UNDERSCORE_IDENT_RE + '\\s*\\(',
122 returnBegin: true,
123 excludeEnd: true,
124 end: /[{;=]/,
125 keywords: KEYWORDS,
126 contains: [
127 { beginKeywords: "record" },
128 {
129 begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(',
130 returnBegin: true,
131 relevance: 0,
132 contains: [hljs.UNDERSCORE_TITLE_MODE]
133 },
134 {
135 className: 'params',
136 begin: /\(/, end: /\)/,
137 keywords: KEYWORDS,
138 relevance: 0,
139 contains: [
140 hljs.C_BLOCK_COMMENT_MODE
141 ]
142 },
143 hljs.C_LINE_COMMENT_MODE,
144 hljs.C_BLOCK_COMMENT_MODE
145 ]
146 },
147 {
148 className: 'function',
149 begin: '(' + GENERIC_IDENT_RE + '\\s+)+' + hljs.UNDERSCORE_IDENT_RE + '\\s*\\(', returnBegin: true, end: /[{;=]/,
150 excludeEnd: true,
151 keywords: KEYWORDS,
152 contains: [
153 {
154 begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(', returnBegin: true,
155 relevance: 0,
156 contains: [hljs.UNDERSCORE_TITLE_MODE]
157 },
158 {
159 className: 'params',
160 begin: /\(/, end: /\)/,
161 keywords: KEYWORDS,
162 relevance: 0,
163 contains: [
164 ANNOTATION,
165 hljs.APOS_STRING_MODE,
166 hljs.QUOTE_STRING_MODE,
167 NUMBER,
168 hljs.C_BLOCK_COMMENT_MODE
169 ]
170 },
171 hljs.C_LINE_COMMENT_MODE,
172 hljs.C_BLOCK_COMMENT_MODE
173 ]
174 },
175 NUMBER,
176 ANNOTATION
177 ]
178 };
179}
180
181module.exports = java;
Note: See TracBrowser for help on using the repository browser.