@spyglassmc/mcdoc 0.3.2 → 0.3.3
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.js +7 -2
- package/lib/common.d.ts +1 -1
- package/lib/node/index.d.ts +14 -14
- package/lib/node/index.js +20 -10
- package/lib/parser/index.js +6 -1
- package/lib/type/index.d.ts +21 -21
- package/package.json +3 -3
package/lib/binder/index.js
CHANGED
|
@@ -340,7 +340,11 @@ function bindEnumBlock(node, ctx, query, options = {}) {
|
|
|
340
340
|
query.member(identifier.value, (fieldQuery) => fieldQuery
|
|
341
341
|
.ifDeclared((symbol) => reportDuplicatedDeclaration(ctx, symbol, identifier))
|
|
342
342
|
.elseEnter({
|
|
343
|
-
usage: {
|
|
343
|
+
usage: {
|
|
344
|
+
type: 'definition',
|
|
345
|
+
node: identifier,
|
|
346
|
+
fullRange: field,
|
|
347
|
+
},
|
|
344
348
|
}));
|
|
345
349
|
}
|
|
346
350
|
}
|
|
@@ -755,7 +759,8 @@ function convertNumericType(node, ctx) {
|
|
|
755
759
|
}, ctx);
|
|
756
760
|
}
|
|
757
761
|
function convertPrimitiveArray(node, ctx) {
|
|
758
|
-
const { arrayKind, lengthRange, valueRange } = PrimitiveArrayTypeNode
|
|
762
|
+
const { arrayKind, lengthRange, valueRange } = PrimitiveArrayTypeNode
|
|
763
|
+
.destruct(node);
|
|
759
764
|
return wrapType(node, {
|
|
760
765
|
kind: `${arrayKind.value}_array`,
|
|
761
766
|
lengthRange: convertRange(lengthRange, ctx),
|
package/lib/common.d.ts
CHANGED
package/lib/node/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface ModuleNode extends AstNode {
|
|
|
7
7
|
export declare const ModuleNode: Readonly<{
|
|
8
8
|
is(node: AstNode | undefined): node is ModuleNode;
|
|
9
9
|
}>;
|
|
10
|
-
export
|
|
10
|
+
export type TopLevelNode = CommentNode | DispatchStatementNode | EnumNode | InjectionNode | StructNode | TypeAliasNode | UseStatementNode;
|
|
11
11
|
export declare const TopLevelNode: Readonly<{
|
|
12
12
|
is(node: AstNode | undefined): node is TopLevelNode;
|
|
13
13
|
}>;
|
|
@@ -43,11 +43,11 @@ export declare const IndexBodyNode: Readonly<{
|
|
|
43
43
|
};
|
|
44
44
|
is(node: AstNode | undefined): node is IndexBodyNode;
|
|
45
45
|
}>;
|
|
46
|
-
export
|
|
46
|
+
export type IndexNode = StaticIndexNode | DynamicIndexNode;
|
|
47
47
|
export declare const IndexNode: Readonly<{
|
|
48
48
|
is(node: AstNode | undefined): node is IndexNode;
|
|
49
49
|
}>;
|
|
50
|
-
export
|
|
50
|
+
export type StaticIndexNode = LiteralNode | IdentifierNode | StringNode | ResourceLocationNode;
|
|
51
51
|
export declare const StaticIndexNode: Readonly<{
|
|
52
52
|
is(node: AstNode | undefined): node is StaticIndexNode;
|
|
53
53
|
}>;
|
|
@@ -67,11 +67,11 @@ export declare const DynamicIndexNode: Readonly<{
|
|
|
67
67
|
};
|
|
68
68
|
is(node: AstNode | undefined): node is DynamicIndexNode;
|
|
69
69
|
}>;
|
|
70
|
-
export
|
|
70
|
+
export type AccessorKeyNode = LiteralNode | IdentifierNode | StringNode;
|
|
71
71
|
export declare const AccessorKeyNode: Readonly<{
|
|
72
72
|
is(node: AstNode | undefined): node is AccessorKeyNode;
|
|
73
73
|
}>;
|
|
74
|
-
export
|
|
74
|
+
export type TypeNode = AnyTypeNode | BooleanTypeNode | StringTypeNode | LiteralTypeNode | NumericTypeNode | PrimitiveArrayTypeNode | ListTypeNode | TupleTypeNode | EnumNode | StructNode | ReferenceTypeNode | DispatcherTypeNode | UnionTypeNode;
|
|
75
75
|
export declare const TypeNode: Readonly<{
|
|
76
76
|
is(node: AstNode | undefined): node is TypeNode;
|
|
77
77
|
}>;
|
|
@@ -96,7 +96,7 @@ export declare const AttributeNode: Readonly<{
|
|
|
96
96
|
};
|
|
97
97
|
is(node: AstNode | undefined): node is AttributeNode;
|
|
98
98
|
}>;
|
|
99
|
-
export
|
|
99
|
+
export type AttributeValueNode = TypeNode | AttributeTreeNode;
|
|
100
100
|
export declare const AttributeValueNode: Readonly<{
|
|
101
101
|
is(node: AstNode | undefined): node is AttributeValueNode;
|
|
102
102
|
}>;
|
|
@@ -179,7 +179,7 @@ export declare const LiteralTypeNode: Readonly<{
|
|
|
179
179
|
};
|
|
180
180
|
is(node: AstNode | undefined): node is LiteralTypeNode;
|
|
181
181
|
}>;
|
|
182
|
-
export
|
|
182
|
+
export type LiteralTypeValueNode = LiteralNode | TypedNumberNode | StringNode;
|
|
183
183
|
export declare const LiteralTypeValueNode: Readonly<{
|
|
184
184
|
is(node: AstNode | undefined): node is LiteralTypeValueNode;
|
|
185
185
|
}>;
|
|
@@ -210,7 +210,7 @@ export declare const RangeExclusiveChar = "<";
|
|
|
210
210
|
* The first bit from the left represents the start, the second bit from the left represents the end.
|
|
211
211
|
* The bit is turned on if the range is exclusive on that end.
|
|
212
212
|
*/
|
|
213
|
-
export
|
|
213
|
+
export type RangeKind = 0b00 | 0b01 | 0b10 | 0b11;
|
|
214
214
|
export declare function getRangeDelimiter(kind: RangeKind): string;
|
|
215
215
|
export interface FloatRangeNode extends AstNode {
|
|
216
216
|
type: 'mcdoc:float_range';
|
|
@@ -267,7 +267,7 @@ export interface EnumNode extends TypeBaseNode<DocCommentsNode | LiteralNode | I
|
|
|
267
267
|
type: 'mcdoc:enum';
|
|
268
268
|
}
|
|
269
269
|
declare const EnumKinds: Set<"string" | "float" | "byte" | "short" | "int" | "long" | "double">;
|
|
270
|
-
export
|
|
270
|
+
export type EnumKind = typeof EnumKinds extends Set<infer V> ? V : never;
|
|
271
271
|
export declare const EnumNode: Readonly<{
|
|
272
272
|
kinds: Set<"string" | "float" | "byte" | "short" | "int" | "long" | "double">;
|
|
273
273
|
destruct(node: EnumNode): {
|
|
@@ -312,11 +312,11 @@ export declare const EnumFieldNode: Readonly<{
|
|
|
312
312
|
};
|
|
313
313
|
is(node: AstNode | undefined): node is EnumFieldNode;
|
|
314
314
|
}>;
|
|
315
|
-
export
|
|
315
|
+
export type EnumValueNode = TypedNumberNode | StringNode;
|
|
316
316
|
export declare const EnumValueNode: Readonly<{
|
|
317
317
|
is(node: AstNode | undefined): node is EnumValueNode;
|
|
318
318
|
}>;
|
|
319
|
-
export
|
|
319
|
+
export type PrelimNode = AttributeNode | DocCommentsNode;
|
|
320
320
|
export declare const PrelimNode: Readonly<{
|
|
321
321
|
is(node: AstNode | undefined): node is PrelimNode;
|
|
322
322
|
}>;
|
|
@@ -384,7 +384,7 @@ export declare const StructBlockNode: Readonly<{
|
|
|
384
384
|
};
|
|
385
385
|
is(node: AstNode | undefined): node is StructBlockNode;
|
|
386
386
|
}>;
|
|
387
|
-
export
|
|
387
|
+
export type StructFieldNode = StructPairFieldNode | StructSpreadFieldNode;
|
|
388
388
|
export declare const StructFieldNode: Readonly<{
|
|
389
389
|
is(node: AstNode | undefined): node is StructFieldNode;
|
|
390
390
|
}>;
|
|
@@ -402,7 +402,7 @@ export declare const StructPairFieldNode: Readonly<{
|
|
|
402
402
|
};
|
|
403
403
|
is(node: AstNode | undefined): node is StructPairFieldNode;
|
|
404
404
|
}>;
|
|
405
|
-
export
|
|
405
|
+
export type StructKeyNode = StringNode | IdentifierNode | StructMapKeyNode;
|
|
406
406
|
export declare const StructKeyNode: Readonly<{
|
|
407
407
|
is(node: AstNode | undefined): node is StructKeyNode;
|
|
408
408
|
}>;
|
|
@@ -456,7 +456,7 @@ export declare const InjectionNode: Readonly<{
|
|
|
456
456
|
};
|
|
457
457
|
is(node: AstNode | undefined): node is InjectionNode;
|
|
458
458
|
}>;
|
|
459
|
-
export
|
|
459
|
+
export type InjectionContentNode = EnumInjectionNode | StructInjectionNode;
|
|
460
460
|
export declare const InjectionContentNode: Readonly<{
|
|
461
461
|
is(node: AstNode | undefined): node is InjectionContentNode;
|
|
462
462
|
}>;
|
package/lib/node/index.js
CHANGED
|
@@ -127,7 +127,8 @@ export const AttributeTreeNode = Object.freeze({
|
|
|
127
127
|
};
|
|
128
128
|
},
|
|
129
129
|
is(node) {
|
|
130
|
-
return (node?.type ===
|
|
130
|
+
return (node?.type ===
|
|
131
|
+
'mcdoc:attribute/tree');
|
|
131
132
|
},
|
|
132
133
|
});
|
|
133
134
|
export const AttributeTreePosValuesNode = Object.freeze({
|
|
@@ -183,7 +184,8 @@ export const AnyTypeNode = Object.freeze({
|
|
|
183
184
|
});
|
|
184
185
|
export const BooleanTypeNode = Object.freeze({
|
|
185
186
|
is(node) {
|
|
186
|
-
return node?.type ===
|
|
187
|
+
return node?.type ===
|
|
188
|
+
'mcdoc:type/boolean';
|
|
187
189
|
},
|
|
188
190
|
});
|
|
189
191
|
export const IntRangeNode = Object.freeze({
|
|
@@ -201,7 +203,8 @@ export const LiteralTypeNode = Object.freeze({
|
|
|
201
203
|
};
|
|
202
204
|
},
|
|
203
205
|
is(node) {
|
|
204
|
-
return node?.type ===
|
|
206
|
+
return node?.type ===
|
|
207
|
+
'mcdoc:type/literal';
|
|
205
208
|
},
|
|
206
209
|
});
|
|
207
210
|
export const LiteralTypeValueNode = Object.freeze({
|
|
@@ -217,7 +220,8 @@ export const TypedNumberNode = Object.freeze({
|
|
|
217
220
|
};
|
|
218
221
|
},
|
|
219
222
|
is(node) {
|
|
220
|
-
return node?.type ===
|
|
223
|
+
return node?.type ===
|
|
224
|
+
'mcdoc:typed_number';
|
|
221
225
|
},
|
|
222
226
|
});
|
|
223
227
|
export const NumericTypeNode = Object.freeze({
|
|
@@ -229,7 +233,8 @@ export const NumericTypeNode = Object.freeze({
|
|
|
229
233
|
};
|
|
230
234
|
},
|
|
231
235
|
is(node) {
|
|
232
|
-
return (node?.type ===
|
|
236
|
+
return (node?.type ===
|
|
237
|
+
'mcdoc:type/numeric_type');
|
|
233
238
|
},
|
|
234
239
|
});
|
|
235
240
|
export const RangeExclusiveChar = '<';
|
|
@@ -399,7 +404,8 @@ export const DocCommentsNode = Object.freeze({
|
|
|
399
404
|
return comments.join('\n');
|
|
400
405
|
},
|
|
401
406
|
is(node) {
|
|
402
|
-
return node?.type ===
|
|
407
|
+
return node?.type ===
|
|
408
|
+
'mcdoc:doc_comments';
|
|
403
409
|
},
|
|
404
410
|
});
|
|
405
411
|
export const EnumBlockNode = Object.freeze({
|
|
@@ -454,7 +460,8 @@ export const ReferenceTypeNode = Object.freeze({
|
|
|
454
460
|
};
|
|
455
461
|
},
|
|
456
462
|
is(node) {
|
|
457
|
-
return (node?.type ===
|
|
463
|
+
return (node?.type ===
|
|
464
|
+
'mcdoc:type/reference');
|
|
458
465
|
},
|
|
459
466
|
});
|
|
460
467
|
export const TypeParamBlockNode = Object.freeze({
|
|
@@ -499,7 +506,8 @@ export const StructBlockNode = Object.freeze({
|
|
|
499
506
|
};
|
|
500
507
|
},
|
|
501
508
|
is(node) {
|
|
502
|
-
return node?.type ===
|
|
509
|
+
return node?.type ===
|
|
510
|
+
'mcdoc:struct/block';
|
|
503
511
|
},
|
|
504
512
|
});
|
|
505
513
|
export const StructFieldNode = Object.freeze({
|
|
@@ -558,7 +566,8 @@ export const DispatcherTypeNode = Object.freeze({
|
|
|
558
566
|
};
|
|
559
567
|
},
|
|
560
568
|
is(node) {
|
|
561
|
-
return (node?.type ===
|
|
569
|
+
return (node?.type ===
|
|
570
|
+
'mcdoc:type/dispatcher');
|
|
562
571
|
},
|
|
563
572
|
});
|
|
564
573
|
export const UnionTypeNode = Object.freeze({
|
|
@@ -588,7 +597,8 @@ export const InjectionContentNode = Object.freeze({
|
|
|
588
597
|
});
|
|
589
598
|
export const EnumInjectionNode = Object.freeze({
|
|
590
599
|
is(node) {
|
|
591
|
-
return (node?.type ===
|
|
600
|
+
return (node?.type ===
|
|
601
|
+
'mcdoc:injection/enum');
|
|
592
602
|
},
|
|
593
603
|
});
|
|
594
604
|
export const StructInjectionNode = Object.freeze({
|
package/lib/parser/index.js
CHANGED
|
@@ -425,7 +425,12 @@ const structBlock = setType('mcdoc:struct/block', syntax([
|
|
|
425
425
|
},
|
|
426
426
|
]),
|
|
427
427
|
], true));
|
|
428
|
-
export const struct = setType('mcdoc:struct', syntax([
|
|
428
|
+
export const struct = setType('mcdoc:struct', syntax([
|
|
429
|
+
prelim,
|
|
430
|
+
keyword('struct'),
|
|
431
|
+
optional(failOnEmpty(identifier)),
|
|
432
|
+
structBlock,
|
|
433
|
+
], true));
|
|
429
434
|
const enumInjection = setType('mcdoc:injection/enum', syntax([
|
|
430
435
|
literal('enum'),
|
|
431
436
|
punctuation('('),
|
package/lib/type/index.d.ts
CHANGED
|
@@ -4,20 +4,20 @@ export interface Attribute {
|
|
|
4
4
|
name: string;
|
|
5
5
|
value?: AttributeValue;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type AttributeValue = McdocType | {
|
|
8
8
|
kind: 'tree';
|
|
9
9
|
values: AttributeTree;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type AttributeTree = {
|
|
12
12
|
[key: string | number]: AttributeValue;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type NumericRange = {
|
|
15
15
|
kind: RangeKind;
|
|
16
16
|
min?: number;
|
|
17
17
|
max?: number;
|
|
18
18
|
};
|
|
19
19
|
export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown"];
|
|
20
|
-
export
|
|
20
|
+
export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number];
|
|
21
21
|
export interface StaticIndex {
|
|
22
22
|
kind: 'static';
|
|
23
23
|
value: string;
|
|
@@ -28,11 +28,11 @@ export interface DynamicIndex {
|
|
|
28
28
|
keyword: 'key' | 'parent';
|
|
29
29
|
})[];
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export type Index = StaticIndex | DynamicIndex;
|
|
32
32
|
/**
|
|
33
33
|
* Corresponds to the IndexBodyNode
|
|
34
34
|
*/
|
|
35
|
-
export
|
|
35
|
+
export type ParallelIndices = Index[];
|
|
36
36
|
export interface DispatcherData {
|
|
37
37
|
registry: FullResourceLocation;
|
|
38
38
|
parallelIndices: ParallelIndices;
|
|
@@ -44,7 +44,7 @@ export interface StructType {
|
|
|
44
44
|
kind: 'struct';
|
|
45
45
|
fields: StructTypeField[];
|
|
46
46
|
}
|
|
47
|
-
export
|
|
47
|
+
export type StructTypeField = StructTypePairField | StructTypeSpreadField;
|
|
48
48
|
export interface StructTypePairField {
|
|
49
49
|
kind: 'pair';
|
|
50
50
|
attributes?: Attribute[];
|
|
@@ -106,7 +106,7 @@ export interface StringType {
|
|
|
106
106
|
kind: 'string';
|
|
107
107
|
lengthRange?: NumericRange;
|
|
108
108
|
}
|
|
109
|
-
export
|
|
109
|
+
export type LiteralValue = {
|
|
110
110
|
kind: 'boolean';
|
|
111
111
|
value: boolean;
|
|
112
112
|
} | {
|
|
@@ -122,28 +122,28 @@ export interface LiteralType {
|
|
|
122
122
|
value: LiteralValue;
|
|
123
123
|
}
|
|
124
124
|
export declare const LiteralNumberSuffixes: readonly ["b", "s", "l", "f", "d"];
|
|
125
|
-
export
|
|
125
|
+
export type LiteralNumberSuffix = (typeof LiteralNumberSuffixes)[number];
|
|
126
126
|
export declare const LiteralNumberCaseInsensitiveSuffixes: readonly ["b", "s", "l", "f", "d", "B", "S", "L", "F", "D"];
|
|
127
|
-
export
|
|
127
|
+
export type LiteralNumberCaseInsensitiveSuffix = (typeof LiteralNumberCaseInsensitiveSuffixes)[number];
|
|
128
128
|
export interface NumericType {
|
|
129
129
|
kind: NumericTypeKind;
|
|
130
130
|
valueRange?: NumericRange;
|
|
131
131
|
}
|
|
132
132
|
export declare const NumericTypeIntKinds: readonly ["byte", "short", "int", "long"];
|
|
133
|
-
export
|
|
133
|
+
export type NumericTypeIntKind = (typeof NumericTypeIntKinds)[number];
|
|
134
134
|
export declare const NumericTypeFloatKinds: readonly ["float", "double"];
|
|
135
|
-
export
|
|
135
|
+
export type NumericTypeFloatKind = (typeof NumericTypeFloatKinds)[number];
|
|
136
136
|
export declare const NumericTypeKinds: readonly ["byte", "short", "int", "long", "float", "double"];
|
|
137
|
-
export
|
|
137
|
+
export type NumericTypeKind = (typeof NumericTypeKinds)[number];
|
|
138
138
|
export interface PrimitiveArrayType {
|
|
139
139
|
kind: 'byte_array' | 'int_array' | 'long_array';
|
|
140
140
|
valueRange?: NumericRange;
|
|
141
141
|
lengthRange?: NumericRange;
|
|
142
142
|
}
|
|
143
143
|
export declare const PrimitiveArrayValueKinds: readonly ["byte", "int", "long"];
|
|
144
|
-
export
|
|
144
|
+
export type PrimitiveArrayValueKind = (typeof PrimitiveArrayValueKinds)[number];
|
|
145
145
|
export declare const PrimitiveArrayKinds: readonly ("byte_array" | "int_array" | "long_array")[];
|
|
146
|
-
export
|
|
146
|
+
export type PrimitiveArrayKind = (typeof PrimitiveArrayKinds)[number];
|
|
147
147
|
export interface ListType {
|
|
148
148
|
kind: 'list';
|
|
149
149
|
item: McdocType;
|
|
@@ -153,27 +153,27 @@ export interface TupleType {
|
|
|
153
153
|
kind: 'tuple';
|
|
154
154
|
items: McdocType[];
|
|
155
155
|
}
|
|
156
|
-
export
|
|
156
|
+
export type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType | AttributedType | IndexedType | TemplateType | ConcreteType;
|
|
157
157
|
export declare namespace McdocType {
|
|
158
158
|
function toString(type: McdocType | undefined): string;
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* A type that doesn't include a dispatcher type.
|
|
162
162
|
*/
|
|
163
|
-
export
|
|
163
|
+
export type DispatchedType = Exclude<McdocType, DispatcherType | UnionType> | UnionType<DispatchedType>;
|
|
164
164
|
/**
|
|
165
165
|
* A type that doesn't include a reference type.
|
|
166
166
|
*/
|
|
167
|
-
export
|
|
167
|
+
export type DereferencedType = Exclude<McdocType, ReferenceType | UnionType> | UnionType<DereferencedType>;
|
|
168
168
|
/**
|
|
169
169
|
* A type that doesn't include a dispatcher type or a reference type.
|
|
170
170
|
*/
|
|
171
|
-
export
|
|
171
|
+
export type TangibleType = Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<TangibleType>;
|
|
172
172
|
/**
|
|
173
173
|
* A type that is {@link TangibleType} and doesn't have any indices.
|
|
174
174
|
*/
|
|
175
|
-
export
|
|
176
|
-
|
|
175
|
+
export type ResolvedType = (Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<ResolvedType>) & NoIndices;
|
|
176
|
+
type NoIndices = {
|
|
177
177
|
indices?: undefined;
|
|
178
178
|
};
|
|
179
179
|
export interface FlatStructType {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcdoc",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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.4.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.2",
|
|
29
|
+
"@spyglassmc/locales": "0.3.2"
|
|
30
30
|
}
|
|
31
31
|
}
|