Skip to content

Commit df6dd32

Browse files
Transform java
1 parent a91dfcb commit df6dd32

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

src/languages/java.js

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { toArray } from '../util/iterables.js';
2-
import { insertBefore } from '../util/language-util.js';
32
import clike from './clike.js';
43

54
/** @type {import('../types.d.ts').LanguageProto<'java'>} */
@@ -30,88 +29,6 @@ export default {
3029
},
3130
};
3231

33-
insertBefore(base, 'comment', {
34-
'doc-comment': {
35-
pattern: /\/\*\*(?!\/)[\s\S]*?(?:\*\/|$)/,
36-
greedy: true,
37-
alias: 'comment',
38-
inside: 'javadoc',
39-
},
40-
});
41-
42-
insertBefore(base, 'string', {
43-
'triple-quoted-string': {
44-
// http://openjdk.java.net/jeps/355#Description
45-
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
46-
greedy: true,
47-
alias: 'string',
48-
},
49-
'char': {
50-
pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
51-
greedy: true,
52-
},
53-
});
54-
55-
insertBefore(base, 'class-name', {
56-
'annotation': {
57-
pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
58-
lookbehind: true,
59-
alias: 'punctuation',
60-
},
61-
'generics': {
62-
pattern:
63-
/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
64-
inside: {
65-
'class-name': className,
66-
'keyword': keywords,
67-
'punctuation': /[<>(),.:]/,
68-
'operator': /[?&|]/,
69-
},
70-
},
71-
'import': [
72-
{
73-
pattern: RegExp(
74-
/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source
75-
),
76-
lookbehind: true,
77-
inside: {
78-
'namespace': className.inside.namespace,
79-
'punctuation': /\./,
80-
'operator': /\*/,
81-
'class-name': /\w+/,
82-
},
83-
},
84-
{
85-
pattern: RegExp(
86-
/(\bimport\s+static\s+)/.source +
87-
classNamePrefix +
88-
/(?:\w+|\*)(?=\s*;)/.source
89-
),
90-
lookbehind: true,
91-
alias: 'static',
92-
inside: {
93-
'namespace': className.inside.namespace,
94-
'static': /\b\w+$/,
95-
'punctuation': /\./,
96-
'operator': /\*/,
97-
'class-name': /\w+/,
98-
},
99-
},
100-
],
101-
'namespace': {
102-
pattern: RegExp(
103-
/(\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(
104-
/<keyword>/g,
105-
() => keywords.source
106-
)
107-
),
108-
lookbehind: true,
109-
inside: {
110-
'punctuation': /\./,
111-
},
112-
},
113-
});
114-
11532
return {
11633
'string': {
11734
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
@@ -146,7 +63,7 @@ export default {
14663
],
14764
'keyword': keywords,
14865
'function': [
149-
...toArray(base.function),
66+
...toArray(/** @type {import('../types.d.ts').GrammarTokens} */ (base).function),
15067
{
15168
pattern: /(::\s*)[a-z_]\w*/,
15269
lookbehind: true,
@@ -159,6 +76,89 @@ export default {
15976
lookbehind: true,
16077
},
16178
'constant': /\b[A-Z][A-Z_\d]+\b/,
79+
$insertBefore: {
80+
'comment': {
81+
'doc-comment': {
82+
pattern: /\/\*\*(?!\/)[\s\S]*?(?:\*\/|$)/,
83+
greedy: true,
84+
alias: 'comment',
85+
inside: 'javadoc',
86+
},
87+
},
88+
'string': {
89+
'triple-quoted-string': {
90+
// http://openjdk.java.net/jeps/355#Description
91+
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
92+
greedy: true,
93+
alias: 'string',
94+
},
95+
'char': {
96+
pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
97+
greedy: true,
98+
},
99+
},
100+
'class-name': {
101+
'annotation': {
102+
pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
103+
lookbehind: true,
104+
alias: 'punctuation',
105+
},
106+
'generics': {
107+
pattern:
108+
/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
109+
inside: {
110+
'class-name': className,
111+
'keyword': keywords,
112+
'punctuation': /[<>(),.:]/,
113+
'operator': /[?&|]/,
114+
},
115+
},
116+
'import': [
117+
{
118+
pattern: RegExp(
119+
/(\bimport\s+)/.source +
120+
classNamePrefix +
121+
/(?:[A-Z]\w*|\*)(?=\s*;)/.source
122+
),
123+
lookbehind: true,
124+
inside: {
125+
'namespace': className.inside.namespace,
126+
'punctuation': /\./,
127+
'operator': /\*/,
128+
'class-name': /\w+/,
129+
},
130+
},
131+
{
132+
pattern: RegExp(
133+
/(\bimport\s+static\s+)/.source +
134+
classNamePrefix +
135+
/(?:\w+|\*)(?=\s*;)/.source
136+
),
137+
lookbehind: true,
138+
alias: 'static',
139+
inside: {
140+
'namespace': className.inside.namespace,
141+
'static': /\b\w+$/,
142+
'punctuation': /\./,
143+
'operator': /\*/,
144+
'class-name': /\w+/,
145+
},
146+
},
147+
],
148+
'namespace': {
149+
pattern: RegExp(
150+
/(\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(
151+
/<keyword>/g,
152+
() => keywords.source
153+
)
154+
),
155+
lookbehind: true,
156+
inside: {
157+
'punctuation': /\./,
158+
},
159+
},
160+
},
161+
},
162162
};
163163
},
164164
};

0 commit comments

Comments
 (0)