Skip to content

Commit 6b4c7a0

Browse files
authored
fix: wrong java keywords (#5759)
1 parent 8b6ac67 commit 6b4c7a0

File tree

4 files changed

+161
-79
lines changed

4 files changed

+161
-79
lines changed

demo/kitchen-sink/docs/java.java

+18
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,21 @@ String nestedMultilineTemplates() {
3737
}
3838
""";
3939
}
40+
41+
var to = "working";
42+
43+
module com.example.myapp {
44+
/**
45+
* Test doc comment
46+
* @property test
47+
*/
48+
requires transitive java.base;
49+
//comment
50+
exports com.example.myapp.api;
51+
/*
52+
multiline comment
53+
*/
54+
opens com.example.myapp.internal to other.module;
55+
uses com.example.myapp.service.MyService;
56+
provides com.example.myapp.service.MyService with com.example.myapp.impl.MyServiceImpl;
57+
}

src/mode/_test/tokens_drools.json

+14-47
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,13 @@
206206
["comment.doc","/**"]
207207
],[
208208
"doc-start",
209-
[
210-
"comment.doc.body",
211-
" * "
212-
],
209+
["comment.doc.body"," * "],
213210
["comment.doc.tag","@param"],
214-
[
215-
"comment.doc.body",
216-
" name who we'll salute?"
217-
]
211+
["comment.doc.body"," name who we'll salute?"]
218212
],[
219213
"start",
220-
[
221-
"comment.doc.body",
222-
" "
223-
],
224-
[
225-
"comment.doc",
226-
"*/"
227-
]
214+
["comment.doc.body"," "],
215+
["comment.doc","*/"]
228216
],[
229217
"start",
230218
["keyword","function"],
@@ -427,30 +415,18 @@
427415
"java-start",
428416
["keyword","then"]
429417
],[
430-
"java-doc-start",
418+
["java-doc-start","java-start"],
431419
["text"," "],
432420
["comment.doc","/**"]
433421
],[
434-
"java-doc-start",
435-
[
436-
"comment.doc.body",
437-
" * "
438-
],
422+
["java-doc-start","java-start"],
423+
["comment.doc.body"," * "],
439424
["comment.doc.tag.storage.type","TODO"],
440-
[
441-
"comment.doc.body",
442-
" There mus be better way"
443-
]
425+
["comment.doc.body"," There mus be better way"]
444426
],[
445427
"java-start",
446-
[
447-
"comment.doc.body",
448-
" "
449-
],
450-
[
451-
"comment.doc",
452-
"*/"
453-
]
428+
["comment.doc.body"," "],
429+
["comment.doc","*/"]
454430
],[
455431
"java-start",
456432
["text"," "],
@@ -777,20 +753,11 @@
777753
["comment.doc","/**"]
778754
],[
779755
"doc-start",
780-
[
781-
"comment.doc.body",
782-
" * Go Right"
783-
]
756+
["comment.doc.body"," * Go Right"]
784757
],[
785758
"start",
786-
[
787-
"comment.doc.body",
788-
" "
789-
],
790-
[
791-
"comment.doc",
792-
"*/"
793-
]
759+
["comment.doc.body"," "],
760+
["comment.doc","*/"]
794761
],[
795762
"start",
796763
["keyword","rule"],
@@ -968,4 +935,4 @@
968935
["keyword","end"]
969936
],[
970937
"start"
971-
]]
938+
]]

src/mode/_test/tokens_java.json

+89
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,93 @@
252252
["rparen","}"]
253253
],[
254254
"start"
255+
],[
256+
"start",
257+
["keyword","var"],
258+
["text"," "],
259+
["identifier","to"],
260+
["text"," "],
261+
["keyword.operator","="],
262+
["text"," "],
263+
["string","\"working\""],
264+
["text",";"]
265+
],[
266+
"start"
267+
],[
268+
["paren.lparen","keyword"],
269+
["keyword","module"],
270+
["text"," "],
271+
["identifier","com"],
272+
["punctuation.operator","."],
273+
["identifier","example"],
274+
["punctuation.operator","."],
275+
["identifier","myapp"],
276+
["text"," "],
277+
["paren.lparen","{"]
278+
],[
279+
["doc-start","paren.lparen","paren.lparen","keyword"],
280+
["text"," "],
281+
["comment.doc","/**"]
282+
],[
283+
["doc-start","paren.lparen","paren.lparen","keyword"],
284+
["comment.doc.body"," * Test doc comment"]
285+
],[
286+
["doc-start","paren.lparen","paren.lparen","keyword"],
287+
["comment.doc.body"," * "],
288+
["comment.doc.tag","@property"],
289+
["comment.doc.body"," test"]
290+
],[
291+
["paren.lparen","keyword"],
292+
["comment.doc.body"," "],
293+
["comment.doc","*/"]
294+
],[
295+
["paren.lparen","keyword"],
296+
["text"," "],
297+
["keyword","requires"],
298+
["text"," "],
299+
["keyword","transitive"],
300+
["text"," java.base;"]
301+
],[
302+
["paren.lparen","keyword"],
303+
["text"," "],
304+
["comment","//comment"]
305+
],[
306+
["paren.lparen","keyword"],
307+
["text"," "],
308+
["keyword","exports"],
309+
["text"," com.example.myapp.api;"]
310+
],[
311+
["comment","paren.lparen","paren.lparen","keyword"],
312+
["text"," "],
313+
["comment","/*"]
314+
],[
315+
["comment","paren.lparen","paren.lparen","keyword"],
316+
["comment"," multiline comment"]
317+
],[
318+
["paren.lparen","keyword"],
319+
["comment"," */"]
320+
],[
321+
["paren.lparen","keyword"],
322+
["text"," "],
323+
["keyword","opens"],
324+
["text"," com.example.myapp.internal "],
325+
["keyword","to"],
326+
["text"," other.module;"]
327+
],[
328+
["paren.lparen","keyword"],
329+
["text"," "],
330+
["keyword","uses"],
331+
["text"," com.example.myapp.service.MyService;"]
332+
],[
333+
["paren.lparen","keyword"],
334+
["text"," "],
335+
["keyword","provides"],
336+
["text"," com.example.myapp.service.MyService "],
337+
["keyword","with"],
338+
["text"," com.example.myapp.impl.MyServiceImpl;"]
339+
],[
340+
"keyword",
341+
["paren.rparen","}"]
342+
],[
343+
"start"
255344
]]

src/mode/java_highlight_rules.js

+40-32
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ var JavaHighlightRules = function() {
1919
"char|final|interface|static|void|" +
2020
"class|finally|long|strictfp|volatile|" +
2121
"const|float|native|super|while|" +
22-
"var|exports|opens|requires|uses|yield|" +
23-
"module|permits|(?:non\\-)?sealed|var|" +
24-
"provides|to|when|" +
25-
"open|record|transitive|with"
22+
"yield|when|record|var|" +
23+
"permits|(?:non\\-)?sealed"
2624
);
2725

2826
var buildinConstants = ("null|Infinity|NaN|undefined");
@@ -66,16 +64,7 @@ var JavaHighlightRules = function() {
6664

6765
this.$rules = {
6866
"start" : [
69-
{
70-
token : "comment",
71-
regex : "\\/\\/.*$"
72-
},
73-
DocCommentHighlightRules.getStartRule("doc-start"),
74-
{
75-
token : "comment", // multi line comment
76-
regex : "\\/\\*",
77-
next : "comment"
78-
},
67+
{include: "comments"},
7968
{include: "multiline-strings"},
8069
{include: "strings"},
8170
{include: "constants"},
@@ -85,15 +74,19 @@ var JavaHighlightRules = function() {
8574
next: [{
8675
regex: "{",
8776
token: "paren.lparen",
88-
next: [{
89-
regex: "}",
90-
token: "paren.rparen",
91-
next: "start"
92-
}, {
93-
// From Section 3.9 of http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jls-diffs.pdf
94-
regex: "\\b(requires|transitive|exports|opens|to|uses|provides|with)\\b",
95-
token: "keyword"
96-
}]
77+
push: [
78+
{
79+
regex: "}",
80+
token: "paren.rparen",
81+
next: "pop"
82+
},
83+
{include: "comments"},
84+
{
85+
// From Section 3.9 of http://cr.openjdk.java.net/~mr/jigsaw/spec/java-se-9-jls-diffs.pdf
86+
regex: "\\b(requires|transitive|exports|opens|to|uses|provides|with)\\b",
87+
token: "keyword"
88+
}
89+
]
9790
}, {
9891
token : "text",
9992
regex : "\\s+"
@@ -113,14 +106,29 @@ var JavaHighlightRules = function() {
113106
},
114107
{include: "statements"}
115108
],
116-
"comment" : [
109+
"comments" : [
117110
{
118-
token : "comment", // closing comment
119-
regex : "\\*\\/",
120-
next : "start"
121-
}, {
122-
defaultToken : "comment"
123-
}
111+
token : "comment",
112+
regex : "\\/\\/.*$"
113+
},
114+
{
115+
token : "comment.doc", // doc comment
116+
regex: /\/\*\*(?!\/)/,
117+
push : "doc-start"
118+
},
119+
{
120+
token : "comment", // multi line comment
121+
regex : "\\/\\*",
122+
push : [
123+
{
124+
token : "comment", // closing comment
125+
regex : "\\*\\/",
126+
next : "pop"
127+
}, {
128+
defaultToken : "comment"
129+
}
130+
]
131+
},
124132
],
125133
"strings": [
126134
{
@@ -265,9 +273,9 @@ var JavaHighlightRules = function() {
265273
]
266274
};
267275

268-
276+
269277
this.embedRules(DocCommentHighlightRules, "doc-",
270-
[ DocCommentHighlightRules.getEndRule("start") ]);
278+
[ DocCommentHighlightRules.getEndRule("pop") ]);
271279
this.normalizeRules();
272280
};
273281

0 commit comments

Comments
 (0)