11import { toArray } from '../util/iterables.js' ;
2- import { insertBefore } from '../util/language-util.js' ;
32import 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- / ( \b i m p o r t \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- / ( \b i m p o r t \s + s t a t i c \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 (?: e x p o r t s | i m p o r t (?: \s + s t a t i c ) ? | m o d u l e | o p e n | o p e n s | p a c k a g e | p r o v i d e s | r e q u i r e s | t o | t r a n s i t i v e | u s e s | w i t h ) \s + ) (? ! < k e y w o r d > ) [ a - z ] \w * (?: \. [ a - z ] \w * ) * \. ? / . source . replace (
104- / < k e y w o r d > / 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+ / ( \b i m p o r t \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+ / ( \b i m p o r t \s + s t a t i c \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 (?: e x p o r t s | i m p o r t (?: \s + s t a t i c ) ? | m o d u l e | o p e n | o p e n s | p a c k a g e | p r o v i d e s | r e q u i r e s | t o | t r a n s i t i v e | u s e s | w i t h ) \s + ) (? ! < k e y w o r d > ) [ a - z ] \w * (?: \. [ a - z ] \w * ) * \. ? / . source . replace (
151+ / < k e y w o r d > / g,
152+ ( ) => keywords . source
153+ )
154+ ) ,
155+ lookbehind : true ,
156+ inside : {
157+ 'punctuation' : / \. / ,
158+ } ,
159+ } ,
160+ } ,
161+ } ,
162162 } ;
163163 } ,
164164} ;
0 commit comments