@spyglassmc/mcdoc 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/binder/index.d.ts +7 -0
- package/lib/binder/index.js +260 -167
- package/lib/colorizer/index.js +2 -2
- package/lib/node/index.d.ts +18 -7
- package/lib/node/index.js +61 -28
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/index.js +162 -147
- package/lib/type/index.d.ts +39 -23
- package/lib/type/index.js +138 -56
- package/lib/uri_processors.js +5 -5
- package/package.json +3 -3
package/lib/parser/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import { any, Arrayable, failOnEmpty, failOnError, Failure, map, optional, Range, repeat, ResourceLocation, select, sequence, setType, stopBefore, validate } from '@spyglassmc/core';
|
|
2
|
+
import { any, Arrayable, failOnEmpty, failOnError, Failure, map, optional, Range, repeat, ResourceLocation, select, sequence, setType, stopBefore, validate, } from '@spyglassmc/core';
|
|
3
3
|
import { arrayToMessage, localeQuote, localize } from '@spyglassmc/locales';
|
|
4
4
|
import { RangeExclusiveChar } from '../node/index.js';
|
|
5
|
-
import { LiteralNumberCaseInsensitiveSuffixes, NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords } from '../type/index.js';
|
|
5
|
+
import { LiteralNumberCaseInsensitiveSuffixes, NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords, } from '../type/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* @returns A comment parser that accepts normal comments (`//`) and reports an error if it's a doc comment (`///`).
|
|
8
8
|
*
|
|
@@ -20,7 +20,9 @@ delegatesDocComments = false) {
|
|
|
20
20
|
return (src, ctx) => {
|
|
21
21
|
const ans = [];
|
|
22
22
|
src.skipWhitespace();
|
|
23
|
-
while (src.canRead() &&
|
|
23
|
+
while (src.canRead() &&
|
|
24
|
+
src.peek(2) === '//' &&
|
|
25
|
+
(!delegatesDocComments || src.peek(3) !== '///')) {
|
|
24
26
|
const result = comment(src, ctx);
|
|
25
27
|
ans.push(result);
|
|
26
28
|
src.skipWhitespace();
|
|
@@ -47,9 +49,10 @@ export function literal(literal, options) {
|
|
|
47
49
|
value: '',
|
|
48
50
|
colorTokenType: options?.colorTokenType,
|
|
49
51
|
};
|
|
50
|
-
ans.value = src.readIf(c => options?.allowedChars?.has(c) ??
|
|
52
|
+
ans.value = src.readIf((c) => options?.allowedChars?.has(c) ??
|
|
53
|
+
(options?.specialChars?.has(c) || /[a-z]/i.test(c)));
|
|
51
54
|
ans.range.end = src.cursor;
|
|
52
|
-
if (Arrayable.toArray(literal).every(l => l !== ans.value)) {
|
|
55
|
+
if (Arrayable.toArray(literal).every((l) => l !== ans.value)) {
|
|
53
56
|
ctx.err.report(localize('expected-got', arrayToMessage(literal), localeQuote(ans.value)), ans);
|
|
54
57
|
}
|
|
55
58
|
return ans;
|
|
@@ -83,22 +86,54 @@ function marker(punctuation) {
|
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
export function resLoc(options) {
|
|
86
|
-
return validate(core.resourceLocation(options), res => res.namespace !== undefined, localize('mcdoc.parser.resource-location.colon-expected', localeQuote(ResourceLocation.NamespacePathSep)));
|
|
89
|
+
return validate(core.resourceLocation(options), (res) => res.namespace !== undefined, localize('mcdoc.parser.resource-location.colon-expected', localeQuote(ResourceLocation.NamespacePathSep)));
|
|
87
90
|
}
|
|
88
91
|
const UnicodeControlCharacters = Object.freeze([
|
|
89
|
-
'\x00',
|
|
90
|
-
'\
|
|
91
|
-
'\
|
|
92
|
+
'\x00',
|
|
93
|
+
'\x01',
|
|
94
|
+
'\x02',
|
|
95
|
+
'\x03',
|
|
96
|
+
'\x04',
|
|
97
|
+
'\x05',
|
|
98
|
+
'\x06',
|
|
99
|
+
'\x07',
|
|
100
|
+
'\x08',
|
|
101
|
+
'\x09',
|
|
102
|
+
'\x0A',
|
|
103
|
+
'\x0B',
|
|
104
|
+
'\x0C',
|
|
105
|
+
'\x0D',
|
|
106
|
+
'\x0E',
|
|
107
|
+
'\x0F',
|
|
108
|
+
'\x7F',
|
|
92
109
|
]);
|
|
93
110
|
export const string = stopBefore(core.string({
|
|
94
|
-
escapable: {
|
|
111
|
+
escapable: {
|
|
112
|
+
characters: ['b', 'f', 'n', 'r', 't', '\\', '"'],
|
|
113
|
+
unicode: true,
|
|
114
|
+
},
|
|
95
115
|
quotes: ['"'],
|
|
96
116
|
}), ...UnicodeControlCharacters);
|
|
97
117
|
export const identifier = (src, ctx) => {
|
|
98
118
|
// https://spyglassmc.com/user/mcdoc/#identifier
|
|
99
119
|
const IdentifierStart = /^[\p{L}\p{Nl}]$/u;
|
|
100
120
|
const IdentifierContinue = /^[\p{L}\p{Nl}\u200C\u200D\p{Mn}\p{Mc}\p{Nd}\p{Pc}]$/u;
|
|
101
|
-
const ReservedWords = new Set([
|
|
121
|
+
const ReservedWords = new Set([
|
|
122
|
+
'any',
|
|
123
|
+
'boolean',
|
|
124
|
+
'byte',
|
|
125
|
+
'double',
|
|
126
|
+
'enum',
|
|
127
|
+
'false',
|
|
128
|
+
'float',
|
|
129
|
+
'int',
|
|
130
|
+
'long',
|
|
131
|
+
'short',
|
|
132
|
+
'string',
|
|
133
|
+
'struct',
|
|
134
|
+
'super',
|
|
135
|
+
'true',
|
|
136
|
+
]);
|
|
102
137
|
const ans = {
|
|
103
138
|
type: 'mcdoc:identifier',
|
|
104
139
|
range: Range.create(src),
|
|
@@ -145,7 +180,7 @@ function indexBody(options) {
|
|
|
145
180
|
const index = select([
|
|
146
181
|
{
|
|
147
182
|
prefix: '%',
|
|
148
|
-
parser: literal(StaticIndexKeywords.map(v => `%${v}`), { specialChars: new Set(['%']) }),
|
|
183
|
+
parser: literal(StaticIndexKeywords.map((v) => `%${v}`), { specialChars: new Set(['%']) }),
|
|
149
184
|
},
|
|
150
185
|
{
|
|
151
186
|
prefix: '"',
|
|
@@ -158,7 +193,13 @@ function indexBody(options) {
|
|
|
158
193
|
: dynamicIndex,
|
|
159
194
|
},
|
|
160
195
|
{
|
|
161
|
-
parser: any([
|
|
196
|
+
parser: any([
|
|
197
|
+
resLoc({
|
|
198
|
+
category: 'mcdoc/dispatcher',
|
|
199
|
+
accessType: options?.accessType,
|
|
200
|
+
}),
|
|
201
|
+
identifier,
|
|
202
|
+
]),
|
|
162
203
|
},
|
|
163
204
|
]);
|
|
164
205
|
return setType('mcdoc:index_body', syntax([
|
|
@@ -178,10 +219,7 @@ export const path = (src, ctx) => {
|
|
|
178
219
|
if (src.trySkip('::')) {
|
|
179
220
|
isAbsolute = true;
|
|
180
221
|
}
|
|
181
|
-
return map(sequence([
|
|
182
|
-
pathSegment,
|
|
183
|
-
repeat(sequence([marker('::'), pathSegment])),
|
|
184
|
-
]), res => {
|
|
222
|
+
return map(sequence([pathSegment, repeat(sequence([marker('::'), pathSegment]))]), (res) => {
|
|
185
223
|
const ans = {
|
|
186
224
|
type: 'mcdoc:path',
|
|
187
225
|
children: res.children,
|
|
@@ -196,12 +234,12 @@ const attributeTreePosValues = setType('mcdoc:attribute/tree/pos', syntax([
|
|
|
196
234
|
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(attributeValue) }], true), true),
|
|
197
235
|
], true));
|
|
198
236
|
const attributeNamedValue = syntax([
|
|
237
|
+
select([{ prefix: '"', parser: string }, { parser: identifier }]),
|
|
199
238
|
select([
|
|
200
|
-
{
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
{ prefix: '=', parser: syntax([punctuation('='), { get: () => attributeValue }], true) },
|
|
239
|
+
{
|
|
240
|
+
prefix: '=',
|
|
241
|
+
parser: syntax([punctuation('='), { get: () => attributeValue }], true),
|
|
242
|
+
},
|
|
205
243
|
{ parser: { get: () => attributeTree } },
|
|
206
244
|
]),
|
|
207
245
|
], true);
|
|
@@ -211,7 +249,12 @@ const attributeTreeNamedValues = setType('mcdoc:attribute/tree/named', syntax([
|
|
|
211
249
|
], true));
|
|
212
250
|
const treeBody = any([
|
|
213
251
|
syntax([attributeTreeNamedValues, optional(marker(','))]),
|
|
214
|
-
syntax([
|
|
252
|
+
syntax([
|
|
253
|
+
attributeTreePosValues,
|
|
254
|
+
punctuation(','),
|
|
255
|
+
attributeTreeNamedValues,
|
|
256
|
+
optional(marker(',')),
|
|
257
|
+
]),
|
|
215
258
|
syntax([attributeTreePosValues, optional(marker(','))]),
|
|
216
259
|
]);
|
|
217
260
|
const AttributeTreeClosure = Object.freeze({
|
|
@@ -220,7 +263,13 @@ const AttributeTreeClosure = Object.freeze({
|
|
|
220
263
|
'{': '}',
|
|
221
264
|
});
|
|
222
265
|
const attributeTree = (src, ctx) => {
|
|
223
|
-
const delim = src.trySkip('(')
|
|
266
|
+
const delim = src.trySkip('(')
|
|
267
|
+
? '('
|
|
268
|
+
: src.trySkip('[')
|
|
269
|
+
? '['
|
|
270
|
+
: src.trySkip('{')
|
|
271
|
+
? '{'
|
|
272
|
+
: undefined;
|
|
224
273
|
if (!delim) {
|
|
225
274
|
return Failure;
|
|
226
275
|
}
|
|
@@ -235,24 +284,60 @@ const attributeTree = (src, ctx) => {
|
|
|
235
284
|
return ans;
|
|
236
285
|
};
|
|
237
286
|
const attributeValue = select([
|
|
238
|
-
{
|
|
287
|
+
{
|
|
288
|
+
predicate: (src) => ['(', '[', '{'].includes(src.peek()),
|
|
289
|
+
parser: attributeTree,
|
|
290
|
+
},
|
|
239
291
|
{ parser: { get: () => type } },
|
|
240
292
|
]);
|
|
241
293
|
export const attribute = setType('mcdoc:attribute', syntax([
|
|
242
294
|
marker('#['),
|
|
243
295
|
identifier,
|
|
244
296
|
select([
|
|
245
|
-
{
|
|
246
|
-
|
|
297
|
+
{
|
|
298
|
+
prefix: '=',
|
|
299
|
+
parser: syntax([punctuation('='), attributeValue, punctuation(']')], true),
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
predicate: (src) => ['(', '[', '{'].includes(src.peek()),
|
|
303
|
+
parser: syntax([
|
|
304
|
+
attributeTree,
|
|
305
|
+
punctuation(']'),
|
|
306
|
+
], true),
|
|
307
|
+
},
|
|
247
308
|
{ parser: punctuation(']') },
|
|
248
309
|
]),
|
|
249
310
|
], true));
|
|
250
311
|
const attributes = repeat(attribute);
|
|
312
|
+
const typeParam = setType('mcdoc:type_param', syntax([
|
|
313
|
+
identifier,
|
|
314
|
+
// optional(syntax([failOnError(literal('extends')), { get: () => type }])),
|
|
315
|
+
]));
|
|
316
|
+
const typeParamBlock = setType('mcdoc:type_param_block', syntax([
|
|
317
|
+
punctuation('<'),
|
|
318
|
+
select([
|
|
319
|
+
{ prefix: '>', parser: punctuation('>') },
|
|
320
|
+
{
|
|
321
|
+
parser: syntax([
|
|
322
|
+
typeParam,
|
|
323
|
+
syntaxRepeat(syntax([marker(','), failOnEmpty(typeParam)])),
|
|
324
|
+
optional(marker(',')),
|
|
325
|
+
punctuation('>'),
|
|
326
|
+
]),
|
|
327
|
+
},
|
|
328
|
+
]),
|
|
329
|
+
]));
|
|
330
|
+
const noop = () => undefined;
|
|
331
|
+
const optionalTypeParamBlock = select([{ prefix: '<', parser: typeParamBlock }, { parser: noop }]);
|
|
251
332
|
export const dispatchStatement = setType('mcdoc:dispatch_statement', syntax([
|
|
252
333
|
attributes,
|
|
253
334
|
keyword('dispatch'),
|
|
254
|
-
resLoc({
|
|
335
|
+
resLoc({
|
|
336
|
+
category: 'mcdoc/dispatcher',
|
|
337
|
+
accessType: 1 /* SymbolAccessType.Write */,
|
|
338
|
+
}),
|
|
255
339
|
indexBody({ noDynamic: true }),
|
|
340
|
+
optionalTypeParamBlock,
|
|
256
341
|
literal('to'),
|
|
257
342
|
{ get: () => type },
|
|
258
343
|
], true));
|
|
@@ -260,40 +345,26 @@ export const docComment = core.comment({
|
|
|
260
345
|
singleLinePrefixes: new Set(['///']),
|
|
261
346
|
includesEol: true,
|
|
262
347
|
});
|
|
263
|
-
export const docComments = setType('mcdoc:doc_comments', repeat(docComment, src => {
|
|
348
|
+
export const docComments = setType('mcdoc:doc_comments', repeat(docComment, (src) => {
|
|
264
349
|
src.skipWhitespace();
|
|
265
350
|
return [];
|
|
266
351
|
}));
|
|
267
|
-
const prelim = syntax([
|
|
268
|
-
|
|
269
|
-
attributes,
|
|
270
|
-
]);
|
|
271
|
-
const enumType = literal([
|
|
272
|
-
'byte',
|
|
273
|
-
'short',
|
|
274
|
-
'int',
|
|
275
|
-
'long',
|
|
276
|
-
'string',
|
|
277
|
-
'float',
|
|
278
|
-
'double',
|
|
279
|
-
], { colorTokenType: 'type' });
|
|
352
|
+
const prelim = syntax([optional(failOnEmpty(docComments)), attributes]);
|
|
353
|
+
const enumType = literal(['byte', 'short', 'int', 'long', 'string', 'float', 'double'], { colorTokenType: 'type' });
|
|
280
354
|
export const float = core.float({
|
|
281
355
|
pattern: /^[-+]?(?:[0-9]+(?:[eE][-+]?[0-9]+)?|[0-9]*\.[0-9]+(?:[eE][-+]?[0-9]+)?)$/,
|
|
282
356
|
});
|
|
283
357
|
export const typedNumber = setType('mcdoc:typed_number', sequence([
|
|
284
358
|
float,
|
|
285
|
-
optional(keyword(LiteralNumberCaseInsensitiveSuffixes, {
|
|
359
|
+
optional(keyword(LiteralNumberCaseInsensitiveSuffixes, {
|
|
360
|
+
colorTokenType: 'keyword',
|
|
361
|
+
})),
|
|
286
362
|
]));
|
|
287
363
|
const enumValue = select([
|
|
288
364
|
{ prefix: '"', parser: string },
|
|
289
365
|
{ parser: typedNumber },
|
|
290
366
|
]);
|
|
291
|
-
const enumField = setType('mcdoc:enum/field', syntax([
|
|
292
|
-
prelim,
|
|
293
|
-
identifier,
|
|
294
|
-
punctuation('='),
|
|
295
|
-
enumValue,
|
|
296
|
-
], true));
|
|
367
|
+
const enumField = setType('mcdoc:enum/field', syntax([prelim, identifier, punctuation('='), enumValue], true));
|
|
297
368
|
const enumBlock = setType('mcdoc:enum/block', syntax([
|
|
298
369
|
punctuation('{'),
|
|
299
370
|
select([
|
|
@@ -317,11 +388,7 @@ export const enum_ = setType('mcdoc:enum', syntax([
|
|
|
317
388
|
optional(failOnError(identifier)),
|
|
318
389
|
enumBlock,
|
|
319
390
|
], true));
|
|
320
|
-
const structMapKey = setType('mcdoc:struct/map_key', syntax([
|
|
321
|
-
punctuation('['),
|
|
322
|
-
{ get: () => type },
|
|
323
|
-
punctuation(']'),
|
|
324
|
-
], true));
|
|
391
|
+
const structMapKey = setType('mcdoc:struct/map_key', syntax([punctuation('['), { get: () => type }, punctuation(']')], true));
|
|
325
392
|
const structKey = select([
|
|
326
393
|
{ prefix: '"', parser: string },
|
|
327
394
|
{ prefix: '[', parser: structMapKey },
|
|
@@ -329,17 +396,11 @@ const structKey = select([
|
|
|
329
396
|
]);
|
|
330
397
|
const structPairField = (src, ctx) => {
|
|
331
398
|
let isOptional;
|
|
332
|
-
const result0 = syntax([
|
|
333
|
-
prelim,
|
|
334
|
-
structKey,
|
|
335
|
-
], true)(src, ctx);
|
|
399
|
+
const result0 = syntax([prelim, structKey], true)(src, ctx);
|
|
336
400
|
if (src.trySkip('?')) {
|
|
337
401
|
isOptional = true;
|
|
338
402
|
}
|
|
339
|
-
const result1 = syntax([
|
|
340
|
-
punctuation(':'),
|
|
341
|
-
{ get: () => type },
|
|
342
|
-
], true)(src, ctx);
|
|
403
|
+
const result1 = syntax([punctuation(':'), { get: () => type }], true)(src, ctx);
|
|
343
404
|
const ans = {
|
|
344
405
|
type: 'mcdoc:struct/field/pair',
|
|
345
406
|
children: [...result0.children, ...result1.children],
|
|
@@ -348,15 +409,8 @@ const structPairField = (src, ctx) => {
|
|
|
348
409
|
};
|
|
349
410
|
return ans;
|
|
350
411
|
};
|
|
351
|
-
const structSpreadField = setType('mcdoc:struct/field/spread', syntax([
|
|
352
|
-
|
|
353
|
-
marker('...'),
|
|
354
|
-
{ get: () => type },
|
|
355
|
-
], true));
|
|
356
|
-
const structField = any([
|
|
357
|
-
structSpreadField,
|
|
358
|
-
structPairField,
|
|
359
|
-
]);
|
|
412
|
+
const structSpreadField = setType('mcdoc:struct/field/spread', syntax([attributes, marker('...'), { get: () => type }], true));
|
|
413
|
+
const structField = any([structSpreadField, structPairField]);
|
|
360
414
|
const structBlock = setType('mcdoc:struct/block', syntax([
|
|
361
415
|
punctuation('{'),
|
|
362
416
|
select([
|
|
@@ -371,12 +425,7 @@ const structBlock = setType('mcdoc:struct/block', syntax([
|
|
|
371
425
|
},
|
|
372
426
|
]),
|
|
373
427
|
], true));
|
|
374
|
-
export const struct = setType('mcdoc:struct', syntax([
|
|
375
|
-
prelim,
|
|
376
|
-
keyword('struct'),
|
|
377
|
-
optional(failOnEmpty(identifier)),
|
|
378
|
-
structBlock,
|
|
379
|
-
], true));
|
|
428
|
+
export const struct = setType('mcdoc:struct', syntax([prelim, keyword('struct'), optional(failOnEmpty(identifier)), structBlock], true));
|
|
380
429
|
const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
381
430
|
literal('enum'),
|
|
382
431
|
punctuation('('),
|
|
@@ -385,11 +434,7 @@ const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
|
385
434
|
path,
|
|
386
435
|
enumBlock,
|
|
387
436
|
]));
|
|
388
|
-
const structInjection = setType('mcdoc:injection/struct', syntax([
|
|
389
|
-
literal('struct'),
|
|
390
|
-
path,
|
|
391
|
-
structBlock,
|
|
392
|
-
]));
|
|
437
|
+
const structInjection = setType('mcdoc:injection/struct', syntax([literal('struct'), path, structBlock]));
|
|
393
438
|
export const injection = setType('mcdoc:injection', syntax([
|
|
394
439
|
keyword('inject'),
|
|
395
440
|
select([
|
|
@@ -397,31 +442,8 @@ export const injection = setType('mcdoc:injection', syntax([
|
|
|
397
442
|
{ parser: structInjection },
|
|
398
443
|
]),
|
|
399
444
|
]));
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
// optional(syntax([failOnError(literal('extends')), { get: () => type }])),
|
|
403
|
-
]));
|
|
404
|
-
const typeParamBlock = setType('mcdoc:type_param_block', syntax([
|
|
405
|
-
punctuation('<'),
|
|
406
|
-
select([
|
|
407
|
-
{ prefix: '>', parser: punctuation('>') },
|
|
408
|
-
{
|
|
409
|
-
parser: syntax([
|
|
410
|
-
typeParam,
|
|
411
|
-
syntaxRepeat(syntax([marker(','), failOnEmpty(typeParam)])),
|
|
412
|
-
optional(marker(',')),
|
|
413
|
-
punctuation('>'),
|
|
414
|
-
]),
|
|
415
|
-
},
|
|
416
|
-
]),
|
|
417
|
-
]));
|
|
418
|
-
const noop = () => undefined;
|
|
419
|
-
const optionalTypeParamBlock = select([
|
|
420
|
-
{ prefix: '<', parser: typeParamBlock },
|
|
421
|
-
{ parser: noop },
|
|
422
|
-
]);
|
|
423
|
-
export const typeAlias = setType('mcdoc:type_alias', syntax([
|
|
424
|
-
docComments,
|
|
445
|
+
export const typeAliasStatement = setType('mcdoc:type_alias', syntax([
|
|
446
|
+
prelim,
|
|
425
447
|
keyword('type'),
|
|
426
448
|
identifier,
|
|
427
449
|
optionalTypeParamBlock,
|
|
@@ -442,16 +464,33 @@ const topLevel = any([
|
|
|
442
464
|
enum_,
|
|
443
465
|
injection,
|
|
444
466
|
struct,
|
|
445
|
-
|
|
467
|
+
typeAliasStatement,
|
|
446
468
|
useStatement,
|
|
447
469
|
]);
|
|
448
470
|
export const module_ = setType('mcdoc:module', syntaxRepeat(topLevel, true));
|
|
471
|
+
const typeArgBlock = setType('mcdoc:type_arg_block', syntax([
|
|
472
|
+
marker('<'),
|
|
473
|
+
select([
|
|
474
|
+
{ prefix: '>', parser: punctuation('>') },
|
|
475
|
+
{
|
|
476
|
+
parser: syntax([
|
|
477
|
+
{ get: () => type },
|
|
478
|
+
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
479
|
+
optional(marker(',')),
|
|
480
|
+
punctuation('>'),
|
|
481
|
+
], true),
|
|
482
|
+
},
|
|
483
|
+
]),
|
|
484
|
+
]));
|
|
449
485
|
/* eslint-enable @typescript-eslint/indent */
|
|
450
486
|
function typeBase(type, parser) {
|
|
451
487
|
return setType(type, syntax([
|
|
452
488
|
attributes,
|
|
453
489
|
parser,
|
|
454
|
-
syntaxRepeat(
|
|
490
|
+
syntaxRepeat(select([
|
|
491
|
+
{ prefix: '<', parser: typeArgBlock },
|
|
492
|
+
{ parser: failOnError(indexBody()) },
|
|
493
|
+
])),
|
|
455
494
|
], true));
|
|
456
495
|
}
|
|
457
496
|
export const anyType = typeBase('mcdoc:type/any', keyword('any', { colorTokenType: 'type' }));
|
|
@@ -472,10 +511,7 @@ function range(type, number) {
|
|
|
472
511
|
return setType(type, select([
|
|
473
512
|
{
|
|
474
513
|
predicate: delimiterPredicate,
|
|
475
|
-
parser: sequence([
|
|
476
|
-
delimiterParser,
|
|
477
|
-
number,
|
|
478
|
-
]),
|
|
514
|
+
parser: sequence([delimiterParser, number]),
|
|
479
515
|
},
|
|
480
516
|
{
|
|
481
517
|
parser: sequence([
|
|
@@ -502,12 +538,12 @@ const atIntRange = optional((src, ctx) => {
|
|
|
502
538
|
src.skipWhitespace();
|
|
503
539
|
return intRange(src, ctx);
|
|
504
540
|
});
|
|
505
|
-
export const stringType = typeBase('mcdoc:type/string', syntax([
|
|
506
|
-
keyword('string', { colorTokenType: 'type' }),
|
|
507
|
-
atIntRange,
|
|
508
|
-
]));
|
|
541
|
+
export const stringType = typeBase('mcdoc:type/string', syntax([keyword('string', { colorTokenType: 'type' }), atIntRange]));
|
|
509
542
|
export const literalType = typeBase('mcdoc:type/literal', select([
|
|
510
|
-
{
|
|
543
|
+
{
|
|
544
|
+
predicate: (src) => src.tryPeek('false') || src.tryPeek('true'),
|
|
545
|
+
parser: keyword(['false', 'true'], { colorTokenType: 'type' }),
|
|
546
|
+
},
|
|
511
547
|
{ prefix: '"', parser: failOnEmpty(string) },
|
|
512
548
|
{ parser: failOnError(typedNumber) },
|
|
513
549
|
]));
|
|
@@ -521,7 +557,7 @@ const atFloatRange = optional((src, ctx) => {
|
|
|
521
557
|
});
|
|
522
558
|
export const numericType = typeBase('mcdoc:type/numeric_type', select([
|
|
523
559
|
{
|
|
524
|
-
predicate: src => NumericTypeFloatKinds.some(k => src.tryPeek(k)),
|
|
560
|
+
predicate: (src) => NumericTypeFloatKinds.some((k) => src.tryPeek(k)),
|
|
525
561
|
parser: syntax([
|
|
526
562
|
keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
|
|
527
563
|
atFloatRange,
|
|
@@ -537,15 +573,13 @@ export const numericType = typeBase('mcdoc:type/numeric_type', select([
|
|
|
537
573
|
export const primitiveArrayType = typeBase('mcdoc:type/primitive_array', syntax([
|
|
538
574
|
literal(PrimitiveArrayValueKinds),
|
|
539
575
|
atIntRange,
|
|
540
|
-
keyword('[]', {
|
|
576
|
+
keyword('[]', {
|
|
577
|
+
allowedChars: new Set(['[', ']']),
|
|
578
|
+
colorTokenType: 'type',
|
|
579
|
+
}),
|
|
541
580
|
atIntRange,
|
|
542
581
|
]));
|
|
543
|
-
export const listType = typeBase('mcdoc:type/list', syntax([
|
|
544
|
-
marker('['),
|
|
545
|
-
{ get: () => type },
|
|
546
|
-
punctuation(']'),
|
|
547
|
-
atIntRange,
|
|
548
|
-
], true));
|
|
582
|
+
export const listType = typeBase('mcdoc:type/list', syntax([marker('['), { get: () => type }, punctuation(']'), atIntRange], true));
|
|
549
583
|
export const tupleType = typeBase('mcdoc:type/tuple', syntax([
|
|
550
584
|
marker('['),
|
|
551
585
|
{ get: () => type },
|
|
@@ -562,10 +596,7 @@ export const tupleType = typeBase('mcdoc:type/tuple', syntax([
|
|
|
562
596
|
},
|
|
563
597
|
]),
|
|
564
598
|
], true));
|
|
565
|
-
export const dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([
|
|
566
|
-
failOnError(resLoc({ category: 'mcdoc/dispatcher' })),
|
|
567
|
-
indexBody(),
|
|
568
|
-
]));
|
|
599
|
+
export const dispatcherType = typeBase('mcdoc:type/dispatcher', syntax([failOnError(resLoc({ category: 'mcdoc/dispatcher' })), indexBody()]));
|
|
569
600
|
export const unionType = typeBase('mcdoc:type/union', syntax([
|
|
570
601
|
marker('('),
|
|
571
602
|
select([
|
|
@@ -580,23 +611,7 @@ export const unionType = typeBase('mcdoc:type/union', syntax([
|
|
|
580
611
|
},
|
|
581
612
|
]),
|
|
582
613
|
]));
|
|
583
|
-
export const referenceType = typeBase('mcdoc:type/reference', syntax([
|
|
584
|
-
path,
|
|
585
|
-
optional(syntax([
|
|
586
|
-
marker('<'),
|
|
587
|
-
select([
|
|
588
|
-
{ prefix: '>', parser: punctuation('>') },
|
|
589
|
-
{
|
|
590
|
-
parser: syntax([
|
|
591
|
-
{ get: () => type },
|
|
592
|
-
syntaxRepeat(syntax([marker(','), { get: () => failOnEmpty(type) }], true), true),
|
|
593
|
-
optional(marker(',')),
|
|
594
|
-
punctuation('>'),
|
|
595
|
-
], true),
|
|
596
|
-
},
|
|
597
|
-
]),
|
|
598
|
-
])),
|
|
599
|
-
]));
|
|
614
|
+
export const referenceType = typeBase('mcdoc:type/reference', syntax([path]));
|
|
600
615
|
export const type = any([
|
|
601
616
|
anyType,
|
|
602
617
|
booleanType,
|
package/lib/type/index.d.ts
CHANGED
|
@@ -35,17 +35,12 @@ export declare type Index = StaticIndex | DynamicIndex;
|
|
|
35
35
|
export declare type ParallelIndices = Index[];
|
|
36
36
|
export interface DispatcherData {
|
|
37
37
|
registry: FullResourceLocation;
|
|
38
|
-
|
|
38
|
+
parallelIndices: ParallelIndices;
|
|
39
39
|
}
|
|
40
|
-
export interface
|
|
41
|
-
kind: string;
|
|
42
|
-
attributes?: Attribute[];
|
|
43
|
-
indices?: ParallelIndices[];
|
|
44
|
-
}
|
|
45
|
-
export interface DispatcherType extends TypeBase, DispatcherData {
|
|
40
|
+
export interface DispatcherType extends DispatcherData {
|
|
46
41
|
kind: 'dispatcher';
|
|
47
42
|
}
|
|
48
|
-
export interface StructType
|
|
43
|
+
export interface StructType {
|
|
49
44
|
kind: 'struct';
|
|
50
45
|
fields: StructTypeField[];
|
|
51
46
|
}
|
|
@@ -62,7 +57,7 @@ export interface StructTypeSpreadField {
|
|
|
62
57
|
attributes?: Attribute[];
|
|
63
58
|
type: McdocType;
|
|
64
59
|
}
|
|
65
|
-
export interface EnumType
|
|
60
|
+
export interface EnumType {
|
|
66
61
|
kind: 'enum';
|
|
67
62
|
enumKind?: EnumKind;
|
|
68
63
|
values: EnumTypeField[];
|
|
@@ -72,21 +67,42 @@ export interface EnumTypeField {
|
|
|
72
67
|
identifier: string;
|
|
73
68
|
value: string | number | bigint;
|
|
74
69
|
}
|
|
75
|
-
export interface ReferenceType
|
|
70
|
+
export interface ReferenceType {
|
|
76
71
|
kind: 'reference';
|
|
77
72
|
path?: string;
|
|
78
|
-
typeParameters?: McdocType[];
|
|
79
73
|
}
|
|
80
|
-
export interface UnionType<T extends McdocType = McdocType>
|
|
74
|
+
export interface UnionType<T extends McdocType = McdocType> {
|
|
81
75
|
kind: 'union';
|
|
82
76
|
members: T[];
|
|
83
77
|
}
|
|
78
|
+
export interface AttributedType {
|
|
79
|
+
kind: 'attributed';
|
|
80
|
+
attribute: Attribute;
|
|
81
|
+
child: McdocType;
|
|
82
|
+
}
|
|
83
|
+
export interface IndexedType {
|
|
84
|
+
kind: 'indexed';
|
|
85
|
+
parallelIndices: Index[];
|
|
86
|
+
child: McdocType;
|
|
87
|
+
}
|
|
88
|
+
export interface TemplateType {
|
|
89
|
+
kind: 'template';
|
|
90
|
+
child: McdocType;
|
|
91
|
+
typeParams: {
|
|
92
|
+
path: string;
|
|
93
|
+
}[];
|
|
94
|
+
}
|
|
95
|
+
export interface ConcreteType {
|
|
96
|
+
kind: 'concrete';
|
|
97
|
+
child: McdocType;
|
|
98
|
+
typeArgs: McdocType[];
|
|
99
|
+
}
|
|
84
100
|
export declare const EmptyUnion: UnionType<never> & NoIndices;
|
|
85
101
|
export declare function createEmptyUnion(attributes?: Attribute[]): UnionType<never> & NoIndices;
|
|
86
|
-
export interface KeywordType
|
|
87
|
-
kind: 'any' | 'boolean';
|
|
102
|
+
export interface KeywordType {
|
|
103
|
+
kind: 'any' | 'boolean' | 'unsafe';
|
|
88
104
|
}
|
|
89
|
-
export interface StringType
|
|
105
|
+
export interface StringType {
|
|
90
106
|
kind: 'string';
|
|
91
107
|
lengthRange?: NumericRange;
|
|
92
108
|
}
|
|
@@ -101,7 +117,7 @@ export declare type LiteralValue = {
|
|
|
101
117
|
value: number;
|
|
102
118
|
suffix: 'b' | 's' | 'l' | 'f' | 'd' | undefined;
|
|
103
119
|
};
|
|
104
|
-
export interface LiteralType
|
|
120
|
+
export interface LiteralType {
|
|
105
121
|
kind: 'literal';
|
|
106
122
|
value: LiteralValue;
|
|
107
123
|
}
|
|
@@ -109,7 +125,7 @@ export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
|
|
|
109
125
|
export declare type LiteralNumberSuffix = typeof LiteralNumberSuffixes[number];
|
|
110
126
|
export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "B", "S", "L", "F", "D"];
|
|
111
127
|
export declare type LiteralNumberCaseInsensitiveSuffix = typeof LiteralNumberCaseInsensitiveSuffixes[number];
|
|
112
|
-
export interface NumericType
|
|
128
|
+
export interface NumericType {
|
|
113
129
|
kind: NumericTypeKind;
|
|
114
130
|
valueRange?: NumericRange;
|
|
115
131
|
}
|
|
@@ -119,7 +135,7 @@ export declare const NumericTypeFloatKinds: readonly ["float", "double"];
|
|
|
119
135
|
export declare type NumericTypeFloatKind = typeof NumericTypeFloatKinds[number];
|
|
120
136
|
export declare const NumericTypeKinds: readonly ["byte", "short", "int", "long", "float", "double"];
|
|
121
137
|
export declare type NumericTypeKind = typeof NumericTypeKinds[number];
|
|
122
|
-
export interface PrimitiveArrayType
|
|
138
|
+
export interface PrimitiveArrayType {
|
|
123
139
|
kind: 'byte_array' | 'int_array' | 'long_array';
|
|
124
140
|
valueRange?: NumericRange;
|
|
125
141
|
lengthRange?: NumericRange;
|
|
@@ -128,16 +144,16 @@ export declare const PrimitiveArrayValueKinds: readonly ["byte", "int", "long"];
|
|
|
128
144
|
export declare type PrimitiveArrayValueKind = typeof PrimitiveArrayValueKinds[number];
|
|
129
145
|
export declare const PrimitiveArrayKinds: readonly ("byte_array" | "int_array" | "long_array")[];
|
|
130
146
|
export declare type PrimitiveArrayKind = typeof PrimitiveArrayKinds[number];
|
|
131
|
-
export interface ListType
|
|
147
|
+
export interface ListType {
|
|
132
148
|
kind: 'list';
|
|
133
149
|
item: McdocType;
|
|
134
150
|
lengthRange?: NumericRange;
|
|
135
151
|
}
|
|
136
|
-
export interface TupleType
|
|
152
|
+
export interface TupleType {
|
|
137
153
|
kind: 'tuple';
|
|
138
154
|
items: McdocType[];
|
|
139
155
|
}
|
|
140
|
-
export declare type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType;
|
|
156
|
+
export declare type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType | AttributedType | IndexedType | TemplateType | ConcreteType;
|
|
141
157
|
export declare namespace McdocType {
|
|
142
158
|
function toString(type: McdocType | undefined): string;
|
|
143
159
|
}
|
|
@@ -160,7 +176,7 @@ export declare type ResolvedType = (Exclude<McdocType, DispatcherType | Referenc
|
|
|
160
176
|
declare type NoIndices = {
|
|
161
177
|
indices?: undefined;
|
|
162
178
|
};
|
|
163
|
-
export interface FlatStructType
|
|
179
|
+
export interface FlatStructType {
|
|
164
180
|
kind: 'flat_struct';
|
|
165
181
|
fields: Record<string, McdocType>;
|
|
166
182
|
}
|
|
@@ -169,7 +185,7 @@ export declare const unionTypes: (a: McdocType, b: McdocType) => McdocType;
|
|
|
169
185
|
export declare const simplifyUnionType: (union: UnionType) => McdocType;
|
|
170
186
|
export declare const simplifyListType: (list: ListType) => ListType;
|
|
171
187
|
export declare const simplifyType: (data: McdocType) => McdocType;
|
|
172
|
-
export declare const checkAssignability: ({ source, target }: {
|
|
188
|
+
export declare const checkAssignability: ({ source, target, }: {
|
|
173
189
|
source: McdocType | undefined;
|
|
174
190
|
target: McdocType | undefined;
|
|
175
191
|
}) => {
|