@spyglassmc/mcdoc 0.2.0 → 0.3.0
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 +10 -2
- package/lib/binder/index.js +705 -2
- package/lib/{binder/util.d.ts → common.d.ts} +4 -1
- package/lib/{binder/util.js → common.js} +1 -1
- package/lib/index.d.ts +5 -2
- package/lib/index.js +6 -4
- package/lib/node/index.d.ts +190 -29
- package/lib/node/index.js +323 -12
- package/lib/parser/index.d.ts +4 -2
- package/lib/parser/index.js +52 -41
- package/lib/type/index.d.ts +70 -41
- package/lib/type/index.js +23 -9
- package/lib/uri_processors.d.ts +4 -0
- package/lib/{binder/uriBinder.js → uri_processors.js} +15 -8
- package/package.json +3 -3
- package/lib/binder/uriBinder.d.ts +0 -3
- package/lib/checker/CheckerContext.d.ts +0 -18
- package/lib/checker/CheckerContext.js +0 -2
- package/lib/checker/entry.d.ts +0 -4
- package/lib/checker/entry.js +0 -354
- package/lib/checker/index.d.ts +0 -2
- package/lib/checker/index.js +0 -2
package/lib/parser/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
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
|
+
import { RangeExclusiveChar } from '../node/index.js';
|
|
5
|
+
import { LiteralNumberCaseInsensitiveSuffixes, NumericTypeFloatKinds, NumericTypeIntKinds, PrimitiveArrayValueKinds, StaticIndexKeywords } from '../type/index.js';
|
|
4
6
|
/**
|
|
5
7
|
* @returns A comment parser that accepts normal comments (`//`) and reports an error if it's a doc comment (`///`).
|
|
6
8
|
*
|
|
@@ -143,7 +145,7 @@ function indexBody(options) {
|
|
|
143
145
|
const index = select([
|
|
144
146
|
{
|
|
145
147
|
prefix: '%',
|
|
146
|
-
parser: literal(
|
|
148
|
+
parser: literal(StaticIndexKeywords.map(v => `%${v}`), { specialChars: new Set(['%']) }),
|
|
147
149
|
},
|
|
148
150
|
{
|
|
149
151
|
prefix: '"',
|
|
@@ -151,7 +153,9 @@ function indexBody(options) {
|
|
|
151
153
|
},
|
|
152
154
|
{
|
|
153
155
|
prefix: '[',
|
|
154
|
-
parser:
|
|
156
|
+
parser: options?.noDynamic
|
|
157
|
+
? validate(dynamicIndex, () => false, localize('mcdoc.parser.index-body.dynamic-index-not-allowed'))
|
|
158
|
+
: dynamicIndex,
|
|
155
159
|
},
|
|
156
160
|
{
|
|
157
161
|
parser: any([resLoc({ category: 'mcdoc/dispatcher', accessType: options?.accessType }), identifier]),
|
|
@@ -278,7 +282,7 @@ export const float = core.float({
|
|
|
278
282
|
});
|
|
279
283
|
export const typedNumber = setType('mcdoc:typed_number', sequence([
|
|
280
284
|
float,
|
|
281
|
-
optional(keyword(
|
|
285
|
+
optional(keyword(LiteralNumberCaseInsensitiveSuffixes, { colorTokenType: 'keyword' })),
|
|
282
286
|
]));
|
|
283
287
|
const enumValue = select([
|
|
284
288
|
{ prefix: '"', parser: string },
|
|
@@ -313,29 +317,6 @@ export const enum_ = setType('mcdoc:enum', syntax([
|
|
|
313
317
|
optional(failOnError(identifier)),
|
|
314
318
|
enumBlock,
|
|
315
319
|
], true));
|
|
316
|
-
const typeParam = setType('mcdoc:type_param', syntax([
|
|
317
|
-
identifier,
|
|
318
|
-
optional(syntax([failOnError(literal('extends')), path])),
|
|
319
|
-
]));
|
|
320
|
-
const typeParamBlock = setType('mcdoc:type_param_block', syntax([
|
|
321
|
-
punctuation('<'),
|
|
322
|
-
select([
|
|
323
|
-
{ prefix: '>', parser: punctuation('>') },
|
|
324
|
-
{
|
|
325
|
-
parser: syntax([
|
|
326
|
-
typeParam,
|
|
327
|
-
syntaxRepeat(syntax([marker(','), failOnEmpty(typeParam)])),
|
|
328
|
-
optional(marker(',')),
|
|
329
|
-
punctuation('>'),
|
|
330
|
-
]),
|
|
331
|
-
},
|
|
332
|
-
]),
|
|
333
|
-
]));
|
|
334
|
-
const noop = () => undefined;
|
|
335
|
-
const optionalTypeParamBlock = select([
|
|
336
|
-
{ prefix: '<', parser: typeParamBlock },
|
|
337
|
-
{ parser: noop },
|
|
338
|
-
]);
|
|
339
320
|
const structMapKey = setType('mcdoc:struct/map_key', syntax([
|
|
340
321
|
punctuation('['),
|
|
341
322
|
{ get: () => type },
|
|
@@ -394,7 +375,6 @@ export const struct = setType('mcdoc:struct', syntax([
|
|
|
394
375
|
prelim,
|
|
395
376
|
keyword('struct'),
|
|
396
377
|
optional(failOnEmpty(identifier)),
|
|
397
|
-
optionalTypeParamBlock,
|
|
398
378
|
structBlock,
|
|
399
379
|
], true));
|
|
400
380
|
const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
@@ -408,7 +388,6 @@ const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
|
408
388
|
const structInjection = setType('mcdoc:injection/struct', syntax([
|
|
409
389
|
literal('struct'),
|
|
410
390
|
path,
|
|
411
|
-
optionalTypeParamBlock,
|
|
412
391
|
structBlock,
|
|
413
392
|
]));
|
|
414
393
|
export const injection = setType('mcdoc:injection', syntax([
|
|
@@ -418,8 +397,31 @@ export const injection = setType('mcdoc:injection', syntax([
|
|
|
418
397
|
{ parser: structInjection },
|
|
419
398
|
]),
|
|
420
399
|
]));
|
|
400
|
+
const typeParam = setType('mcdoc:type_param', syntax([
|
|
401
|
+
identifier,
|
|
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
|
+
]);
|
|
421
423
|
export const typeAlias = setType('mcdoc:type_alias', syntax([
|
|
422
|
-
|
|
424
|
+
docComments,
|
|
423
425
|
keyword('type'),
|
|
424
426
|
identifier,
|
|
425
427
|
optionalTypeParamBlock,
|
|
@@ -458,11 +460,20 @@ export const integer = core.integer({
|
|
|
458
460
|
pattern: /^(?:0|[-+]?[1-9][0-9]*)$/,
|
|
459
461
|
});
|
|
460
462
|
function range(type, number) {
|
|
463
|
+
const delimiterPredicate = (src) => src.tryPeek('..') || src.tryPeek(`${RangeExclusiveChar}..`);
|
|
464
|
+
const delimiterParser = literal([
|
|
465
|
+
'..',
|
|
466
|
+
`..${RangeExclusiveChar}`,
|
|
467
|
+
`${RangeExclusiveChar}..`,
|
|
468
|
+
`${RangeExclusiveChar}..${RangeExclusiveChar}`,
|
|
469
|
+
], {
|
|
470
|
+
allowedChars: new Set(['.', RangeExclusiveChar]),
|
|
471
|
+
});
|
|
461
472
|
return setType(type, select([
|
|
462
473
|
{
|
|
463
|
-
|
|
474
|
+
predicate: delimiterPredicate,
|
|
464
475
|
parser: sequence([
|
|
465
|
-
|
|
476
|
+
delimiterParser,
|
|
466
477
|
number,
|
|
467
478
|
]),
|
|
468
479
|
},
|
|
@@ -471,9 +482,9 @@ function range(type, number) {
|
|
|
471
482
|
stopBefore(number, '..'),
|
|
472
483
|
select([
|
|
473
484
|
{
|
|
474
|
-
|
|
485
|
+
predicate: delimiterPredicate,
|
|
475
486
|
parser: sequence([
|
|
476
|
-
|
|
487
|
+
delimiterParser,
|
|
477
488
|
optional(failOnEmpty(number)),
|
|
478
489
|
]),
|
|
479
490
|
},
|
|
@@ -483,7 +494,7 @@ function range(type, number) {
|
|
|
483
494
|
},
|
|
484
495
|
]));
|
|
485
496
|
}
|
|
486
|
-
const intRange = range('mcdoc:int_range', integer);
|
|
497
|
+
export const intRange = range('mcdoc:int_range', integer);
|
|
487
498
|
const atIntRange = optional((src, ctx) => {
|
|
488
499
|
if (!src.trySkip('@')) {
|
|
489
500
|
return Failure;
|
|
@@ -500,7 +511,7 @@ export const literalType = typeBase('mcdoc:type/literal', select([
|
|
|
500
511
|
{ prefix: '"', parser: failOnEmpty(string) },
|
|
501
512
|
{ parser: failOnError(typedNumber) },
|
|
502
513
|
]));
|
|
503
|
-
const floatRange = range('mcdoc:float_range', float);
|
|
514
|
+
export const floatRange = range('mcdoc:float_range', float);
|
|
504
515
|
const atFloatRange = optional((src, ctx) => {
|
|
505
516
|
if (!src.trySkip('@')) {
|
|
506
517
|
return Failure;
|
|
@@ -510,21 +521,21 @@ const atFloatRange = optional((src, ctx) => {
|
|
|
510
521
|
});
|
|
511
522
|
export const numericType = typeBase('mcdoc:type/numeric_type', select([
|
|
512
523
|
{
|
|
513
|
-
predicate: src =>
|
|
524
|
+
predicate: src => NumericTypeFloatKinds.some(k => src.tryPeek(k)),
|
|
514
525
|
parser: syntax([
|
|
515
|
-
keyword(
|
|
526
|
+
keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
|
|
516
527
|
atFloatRange,
|
|
517
528
|
]),
|
|
518
529
|
},
|
|
519
530
|
{
|
|
520
531
|
parser: syntax([
|
|
521
|
-
keyword(
|
|
532
|
+
keyword(NumericTypeIntKinds, { colorTokenType: 'type' }),
|
|
522
533
|
atIntRange,
|
|
523
534
|
]),
|
|
524
535
|
},
|
|
525
536
|
]));
|
|
526
537
|
export const primitiveArrayType = typeBase('mcdoc:type/primitive_array', syntax([
|
|
527
|
-
literal(
|
|
538
|
+
literal(PrimitiveArrayValueKinds),
|
|
528
539
|
atIntRange,
|
|
529
540
|
keyword('[]', { allowedChars: new Set(['[', ']']), colorTokenType: 'type' }),
|
|
530
541
|
atIntRange,
|
|
@@ -569,7 +580,7 @@ export const unionType = typeBase('mcdoc:type/union', syntax([
|
|
|
569
580
|
},
|
|
570
581
|
]),
|
|
571
582
|
]));
|
|
572
|
-
export const
|
|
583
|
+
export const referenceType = typeBase('mcdoc:type/reference', syntax([
|
|
573
584
|
path,
|
|
574
585
|
optional(syntax([
|
|
575
586
|
marker('<'),
|
|
@@ -599,6 +610,6 @@ export const type = any([
|
|
|
599
610
|
struct,
|
|
600
611
|
tupleType,
|
|
601
612
|
unionType,
|
|
602
|
-
|
|
613
|
+
referenceType,
|
|
603
614
|
]);
|
|
604
615
|
//# sourceMappingURL=index.js.map
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
import type { FullResourceLocation, ProcessorContext
|
|
2
|
-
import type { EnumKind } from '../node/index.js';
|
|
1
|
+
import type { FullResourceLocation, ProcessorContext } from '@spyglassmc/core';
|
|
2
|
+
import type { EnumKind, RangeKind } from '../node/index.js';
|
|
3
3
|
export interface Attribute {
|
|
4
4
|
name: string;
|
|
5
|
-
value
|
|
5
|
+
value?: AttributeValue;
|
|
6
6
|
}
|
|
7
|
-
export declare type AttributeValue =
|
|
7
|
+
export declare type AttributeValue = McdocType | {
|
|
8
|
+
kind: 'tree';
|
|
9
|
+
values: AttributeTree;
|
|
10
|
+
};
|
|
11
|
+
export declare type AttributeTree = {
|
|
8
12
|
[key: string | number]: AttributeValue;
|
|
9
13
|
};
|
|
10
|
-
export declare type NumericRange =
|
|
11
|
-
|
|
14
|
+
export declare type NumericRange = {
|
|
15
|
+
kind: RangeKind;
|
|
16
|
+
min?: number;
|
|
17
|
+
max?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown"];
|
|
20
|
+
export declare type StaticIndexKeyword = typeof StaticIndexKeywords[number];
|
|
21
|
+
export interface StaticIndex {
|
|
12
22
|
kind: 'static';
|
|
13
|
-
value: string
|
|
14
|
-
keyword: 'fallback' | 'none' | 'unknown';
|
|
15
|
-
};
|
|
23
|
+
value: string;
|
|
16
24
|
}
|
|
17
|
-
interface DynamicIndex {
|
|
25
|
+
export interface DynamicIndex {
|
|
18
26
|
kind: 'dynamic';
|
|
19
27
|
accessor: (string | {
|
|
20
28
|
keyword: 'key' | 'parent';
|
|
21
29
|
})[];
|
|
22
30
|
}
|
|
23
31
|
export declare type Index = StaticIndex | DynamicIndex;
|
|
24
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Corresponds to the IndexBodyNode
|
|
34
|
+
*/
|
|
35
|
+
export declare type ParallelIndices = Index[];
|
|
25
36
|
export interface DispatcherData {
|
|
26
|
-
registry: FullResourceLocation
|
|
37
|
+
registry: FullResourceLocation;
|
|
27
38
|
index: ParallelIndices;
|
|
28
39
|
}
|
|
29
|
-
interface TypeBase {
|
|
40
|
+
export interface TypeBase {
|
|
30
41
|
kind: string;
|
|
31
42
|
attributes?: Attribute[];
|
|
32
43
|
indices?: ParallelIndices[];
|
|
@@ -36,28 +47,35 @@ export interface DispatcherType extends TypeBase, DispatcherData {
|
|
|
36
47
|
}
|
|
37
48
|
export interface StructType extends TypeBase {
|
|
38
49
|
kind: 'struct';
|
|
39
|
-
fields:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
fields: StructTypeField[];
|
|
51
|
+
}
|
|
52
|
+
export declare type StructTypeField = StructTypePairField | StructTypeSpreadField;
|
|
53
|
+
export interface StructTypePairField {
|
|
54
|
+
kind: 'pair';
|
|
55
|
+
attributes?: Attribute[];
|
|
56
|
+
key: string | McdocType;
|
|
57
|
+
type: McdocType;
|
|
58
|
+
optional?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface StructTypeSpreadField {
|
|
61
|
+
kind: 'spread';
|
|
62
|
+
attributes?: Attribute[];
|
|
63
|
+
type: McdocType;
|
|
48
64
|
}
|
|
49
65
|
export interface EnumType extends TypeBase {
|
|
50
66
|
kind: 'enum';
|
|
51
|
-
enumKind
|
|
52
|
-
values:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
enumKind?: EnumKind;
|
|
68
|
+
values: EnumTypeField[];
|
|
69
|
+
}
|
|
70
|
+
export interface EnumTypeField {
|
|
71
|
+
attributes?: Attribute[];
|
|
72
|
+
identifier: string;
|
|
73
|
+
value: string | number | bigint;
|
|
56
74
|
}
|
|
57
75
|
export interface ReferenceType extends TypeBase {
|
|
58
76
|
kind: 'reference';
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
path?: string;
|
|
78
|
+
typeParameters?: McdocType[];
|
|
61
79
|
}
|
|
62
80
|
export interface UnionType<T extends McdocType = McdocType> extends TypeBase {
|
|
63
81
|
kind: 'union';
|
|
@@ -65,14 +83,14 @@ export interface UnionType<T extends McdocType = McdocType> extends TypeBase {
|
|
|
65
83
|
}
|
|
66
84
|
export declare const EmptyUnion: UnionType<never> & NoIndices;
|
|
67
85
|
export declare function createEmptyUnion(attributes?: Attribute[]): UnionType<never> & NoIndices;
|
|
68
|
-
interface KeywordType extends TypeBase {
|
|
86
|
+
export interface KeywordType extends TypeBase {
|
|
69
87
|
kind: 'any' | 'boolean';
|
|
70
88
|
}
|
|
71
|
-
interface StringType extends TypeBase {
|
|
89
|
+
export interface StringType extends TypeBase {
|
|
72
90
|
kind: 'string';
|
|
73
91
|
lengthRange?: NumericRange;
|
|
74
92
|
}
|
|
75
|
-
declare type LiteralValue = {
|
|
93
|
+
export declare type LiteralValue = {
|
|
76
94
|
kind: 'boolean';
|
|
77
95
|
value: boolean;
|
|
78
96
|
} | {
|
|
@@ -81,21 +99,35 @@ declare type LiteralValue = {
|
|
|
81
99
|
} | {
|
|
82
100
|
kind: 'number';
|
|
83
101
|
value: number;
|
|
84
|
-
suffix: 'b' | 's' | '
|
|
102
|
+
suffix: 'b' | 's' | 'l' | 'f' | 'd' | undefined;
|
|
85
103
|
};
|
|
86
|
-
interface LiteralType extends TypeBase {
|
|
104
|
+
export interface LiteralType extends TypeBase {
|
|
87
105
|
kind: 'literal';
|
|
88
106
|
value: LiteralValue;
|
|
89
107
|
}
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
|
|
109
|
+
export declare type LiteralNumberSuffix = typeof LiteralNumberSuffixes[number];
|
|
110
|
+
export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "B", "S", "L", "F", "D"];
|
|
111
|
+
export declare type LiteralNumberCaseInsensitiveSuffix = typeof LiteralNumberCaseInsensitiveSuffixes[number];
|
|
112
|
+
export interface NumericType extends TypeBase {
|
|
113
|
+
kind: NumericTypeKind;
|
|
92
114
|
valueRange?: NumericRange;
|
|
93
115
|
}
|
|
94
|
-
|
|
116
|
+
export declare const NumericTypeIntKinds: readonly ["byte", "short", "int", "long"];
|
|
117
|
+
export declare type NumericTypeIntKind = typeof NumericTypeIntKinds[number];
|
|
118
|
+
export declare const NumericTypeFloatKinds: readonly ["float", "double"];
|
|
119
|
+
export declare type NumericTypeFloatKind = typeof NumericTypeFloatKinds[number];
|
|
120
|
+
export declare const NumericTypeKinds: readonly ["byte", "short", "int", "long", "float", "double"];
|
|
121
|
+
export declare type NumericTypeKind = typeof NumericTypeKinds[number];
|
|
122
|
+
export interface PrimitiveArrayType extends TypeBase {
|
|
95
123
|
kind: 'byte_array' | 'int_array' | 'long_array';
|
|
96
124
|
valueRange?: NumericRange;
|
|
97
125
|
lengthRange?: NumericRange;
|
|
98
126
|
}
|
|
127
|
+
export declare const PrimitiveArrayValueKinds: readonly ["byte", "int", "long"];
|
|
128
|
+
export declare type PrimitiveArrayValueKind = typeof PrimitiveArrayValueKinds[number];
|
|
129
|
+
export declare const PrimitiveArrayKinds: readonly ("byte_array" | "int_array" | "long_array")[];
|
|
130
|
+
export declare type PrimitiveArrayKind = typeof PrimitiveArrayKinds[number];
|
|
99
131
|
export interface ListType extends TypeBase {
|
|
100
132
|
kind: 'list';
|
|
101
133
|
item: McdocType;
|
|
@@ -130,10 +162,7 @@ declare type NoIndices = {
|
|
|
130
162
|
};
|
|
131
163
|
export interface FlatStructType extends TypeBase {
|
|
132
164
|
kind: 'flat_struct';
|
|
133
|
-
fields: Record<string,
|
|
134
|
-
type: McdocType;
|
|
135
|
-
symbol: SymbolPath;
|
|
136
|
-
}>;
|
|
165
|
+
fields: Record<string, McdocType>;
|
|
137
166
|
}
|
|
138
167
|
export declare const flattenUnionType: (union: UnionType) => UnionType;
|
|
139
168
|
export declare const unionTypes: (a: McdocType, b: McdocType) => McdocType;
|
package/lib/type/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Arrayable } from '@spyglassmc/core';
|
|
2
2
|
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
import { getRangeDelimiter } from '../node/index.js';
|
|
4
|
+
export const StaticIndexKeywords = Object.freeze(['fallback', 'none', 'unknown']);
|
|
3
5
|
export const EmptyUnion = Object.freeze({ kind: 'union', members: [] });
|
|
4
6
|
export function createEmptyUnion(attributes) {
|
|
5
7
|
return {
|
|
@@ -7,6 +9,13 @@ export function createEmptyUnion(attributes) {
|
|
|
7
9
|
attributes,
|
|
8
10
|
};
|
|
9
11
|
}
|
|
12
|
+
export const LiteralNumberSuffixes = Object.freeze(['b', 's', 'l', 'f', 'd']);
|
|
13
|
+
export const LiteralNumberCaseInsensitiveSuffixes = Object.freeze([...LiteralNumberSuffixes, 'B', 'S', 'L', 'F', 'D']);
|
|
14
|
+
export const NumericTypeIntKinds = Object.freeze(['byte', 'short', 'int', 'long']);
|
|
15
|
+
export const NumericTypeFloatKinds = Object.freeze(['float', 'double']);
|
|
16
|
+
export const NumericTypeKinds = Object.freeze([...NumericTypeIntKinds, ...NumericTypeFloatKinds]);
|
|
17
|
+
export const PrimitiveArrayValueKinds = Object.freeze(['byte', 'int', 'long']);
|
|
18
|
+
export const PrimitiveArrayKinds = Object.freeze(PrimitiveArrayValueKinds.map(kind => `${kind}_array`));
|
|
10
19
|
export var McdocType;
|
|
11
20
|
(function (McdocType) {
|
|
12
21
|
function toString(type) {
|
|
@@ -14,8 +23,8 @@ export var McdocType;
|
|
|
14
23
|
if (!range) {
|
|
15
24
|
return '';
|
|
16
25
|
}
|
|
17
|
-
const
|
|
18
|
-
return min === max ? ` @ ${min}` : ` @ ${min ?? ''}
|
|
26
|
+
const { kind, min, max } = range;
|
|
27
|
+
return min === max ? ` @ ${min}` : ` @ ${min ?? ''}${getRangeDelimiter(kind)}${max ?? ''}`;
|
|
19
28
|
};
|
|
20
29
|
const indicesToString = (indices) => {
|
|
21
30
|
const strings = [];
|
|
@@ -63,7 +72,7 @@ export var McdocType;
|
|
|
63
72
|
case 'long_array':
|
|
64
73
|
return `long${rangeToString(type.valueRange)}[]${rangeToString(type.lengthRange)}`;
|
|
65
74
|
case 'reference':
|
|
66
|
-
return type.
|
|
75
|
+
return type.path ?? '<unknown_reference>';
|
|
67
76
|
case 'short':
|
|
68
77
|
return `short${rangeToString(type.valueRange)}`;
|
|
69
78
|
case 'string':
|
|
@@ -91,8 +100,8 @@ const areRangesMatch = (s, t) => {
|
|
|
91
100
|
if (!s) {
|
|
92
101
|
return false;
|
|
93
102
|
}
|
|
94
|
-
const
|
|
95
|
-
const
|
|
103
|
+
const { min: sMin, max: sMax } = s;
|
|
104
|
+
const { min: tMin, max: tMax } = t;
|
|
96
105
|
return (tMin === undefined || (sMin !== undefined && sMin >= tMin)) &&
|
|
97
106
|
(tMax === undefined || (sMax !== undefined && sMax <= tMax));
|
|
98
107
|
};
|
|
@@ -148,7 +157,7 @@ export const simplifyUnionType = (union) => {
|
|
|
148
157
|
export const simplifyListType = (list) => ({
|
|
149
158
|
kind: 'list',
|
|
150
159
|
item: simplifyType(list.item),
|
|
151
|
-
...list.lengthRange ? { lengthRange:
|
|
160
|
+
...list.lengthRange ? { lengthRange: { ...list.lengthRange } } : {},
|
|
152
161
|
});
|
|
153
162
|
export const simplifyType = (data) => {
|
|
154
163
|
if (data.kind === 'union') {
|
|
@@ -183,7 +192,7 @@ const check = (s, t, errors = []) => {
|
|
|
183
192
|
}
|
|
184
193
|
else if (s.kind === 'byte') {
|
|
185
194
|
if (t.kind === 'boolean') {
|
|
186
|
-
ans = check(s, { kind: 'byte', valueRange:
|
|
195
|
+
ans = check(s, { kind: 'byte', valueRange: { kind: 0b00, min: 0, max: 1 } }, errors);
|
|
187
196
|
}
|
|
188
197
|
else if (t.kind === 'byte') {
|
|
189
198
|
ans = strictlyAssignableIfTrue(areRangesMatch(s.valueRange, t.valueRange));
|
|
@@ -317,7 +326,7 @@ function navigateIndex(type, index, ctx, value) {
|
|
|
317
326
|
return createEmptyUnion(type.attributes);
|
|
318
327
|
}
|
|
319
328
|
const flatStruct = flattenStruct(type, ctx, value);
|
|
320
|
-
return resolveType(flatStruct.fields[key]
|
|
329
|
+
return resolveType(flatStruct.fields[key], ctx, value);
|
|
321
330
|
}
|
|
322
331
|
else if (type.kind === 'union') {
|
|
323
332
|
return mapUnion(type, t => navigateIndex(t, index, ctx, value));
|
|
@@ -371,7 +380,12 @@ function flattenStruct(type, ctx, value) {
|
|
|
371
380
|
}
|
|
372
381
|
}
|
|
373
382
|
else {
|
|
374
|
-
|
|
383
|
+
if (typeof field.key === 'string') {
|
|
384
|
+
ans.fields[field.key] = field.type;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
// TODO: Handle map keys
|
|
388
|
+
}
|
|
375
389
|
}
|
|
376
390
|
}
|
|
377
391
|
return ans;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileUtil } from '@spyglassmc/core';
|
|
2
|
-
import { segToIdentifier } from './
|
|
2
|
+
import { segToIdentifier } from './common.js';
|
|
3
3
|
const Extension = '.mcdoc';
|
|
4
4
|
const McdocRootPrefix = 'mcdoc/';
|
|
5
5
|
export const uriBinder = (uris, ctx) => {
|
|
@@ -34,13 +34,20 @@ export const uriBinder = (uris, ctx) => {
|
|
|
34
34
|
.query(uri, 'mcdoc', segToIdentifier(rel.split('/')))
|
|
35
35
|
.ifKnown(() => { })
|
|
36
36
|
.elseEnter({
|
|
37
|
-
data: {
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
usage: {
|
|
41
|
-
type: 'implementation',
|
|
42
|
-
},
|
|
37
|
+
data: { subcategory: 'module' },
|
|
38
|
+
usage: { type: 'definition' },
|
|
43
39
|
});
|
|
44
40
|
}
|
|
45
41
|
};
|
|
46
|
-
|
|
42
|
+
export const uriSorter = (a, b, next) => {
|
|
43
|
+
if (a.endsWith(Extension) && !b.endsWith(Extension)) {
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
else if (!a.endsWith(Extension) && b.endsWith(Extension)) {
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return next(a, b);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=uri_processors.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcdoc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.
|
|
29
|
-
"@spyglassmc/locales": "0.
|
|
28
|
+
"@spyglassmc/core": "0.3.0",
|
|
29
|
+
"@spyglassmc/locales": "0.3.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as core from '@spyglassmc/core';
|
|
2
|
-
import type { Symbol } from '@spyglassmc/core';
|
|
3
|
-
import type { Segments } from '../binder/index.js';
|
|
4
|
-
export interface CheckerContext extends core.CheckerContext {
|
|
5
|
-
/**
|
|
6
|
-
* The current module's identifier.
|
|
7
|
-
*/
|
|
8
|
-
modIdentifier: string;
|
|
9
|
-
/**
|
|
10
|
-
* The current module's segments.
|
|
11
|
-
*/
|
|
12
|
-
modSeg: Segments;
|
|
13
|
-
/**
|
|
14
|
-
* The current module's symbol.
|
|
15
|
-
*/
|
|
16
|
-
modSymbol: Symbol;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=CheckerContext.d.ts.map
|
package/lib/checker/entry.d.ts
DELETED