@spyglassmc/nbt 0.1.0 → 0.1.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/checker/index.d.ts +10 -15
- package/lib/checker/index.js +189 -377
- package/lib/checker/mcdocUtil.d.ts +9 -0
- package/lib/checker/{nbtdocUtil.js → mcdocUtil.js} +9 -8
- package/lib/colorizer/index.js +5 -1
- package/lib/index.js +5 -1
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +5 -1
- package/lib/parser/collection.js +5 -1
- package/lib/parser/compound.js +5 -1
- package/lib/parser/entry.js +12 -8
- package/lib/parser/index.js +5 -1
- package/lib/parser/path.js +5 -1
- package/lib/parser/primitive.js +18 -14
- package/package.json +4 -4
- package/lib/checker/nbtdocUtil.d.ts +0 -9
package/lib/checker/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import * as
|
|
3
|
-
import type { NbtNode, NbtPathNode } from '../node';
|
|
4
|
-
import { NbtCompoundNode, NbtPrimitiveNode } from '../node';
|
|
2
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
+
import type { NbtCompoundNode, NbtNode, NbtPathNode, NbtPrimitiveNode } from '../node';
|
|
5
4
|
interface Options {
|
|
6
5
|
allowUnknownKey?: boolean;
|
|
7
6
|
isPredicate?: boolean;
|
|
@@ -13,28 +12,24 @@ declare global {
|
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* @param id If the registry is under the `custom` namespace, `id` can only be a string. Otherwise it can be a string, string array, or `undefined`.
|
|
16
|
-
* If set to `undefined` or an empty array, all
|
|
15
|
+
* If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
|
|
17
16
|
*/
|
|
18
|
-
export declare function index(registry:
|
|
19
|
-
export declare function index(registry:
|
|
17
|
+
export declare function index(registry: string, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined, options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
18
|
+
export declare function index(registry: string, id: core.FullResourceLocation, options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
20
19
|
/**
|
|
21
|
-
* @param identifier An identifier of
|
|
20
|
+
* @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
|
|
22
21
|
*/
|
|
23
22
|
export declare function definition(identifier: `::${string}::${string}`, options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
24
23
|
export declare function blockStates(blocks: string[], _options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
25
24
|
/**
|
|
26
25
|
* @param path The {@link core.SymbolPath} to the compound definition.
|
|
27
26
|
*/
|
|
28
|
-
export declare function compound(data:
|
|
27
|
+
export declare function compound(data: any, options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
29
28
|
export declare function enum_(path: core.SymbolPath | undefined, _options?: Options): core.SyncChecker<NbtPrimitiveNode>;
|
|
30
29
|
/**
|
|
31
|
-
* @param id If set to `undefined` or an empty array, all
|
|
30
|
+
* @param id If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
|
|
32
31
|
*/
|
|
33
|
-
export declare function path(registry:
|
|
34
|
-
export declare function fieldValue(type:
|
|
35
|
-
declare type ResolvedCompoundData = Record<string, {
|
|
36
|
-
data: nbtdoc.NbtdocType;
|
|
37
|
-
query?: core.SymbolQuery;
|
|
38
|
-
}>;
|
|
32
|
+
export declare function path(registry: string, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined): core.SyncChecker<NbtPathNode>;
|
|
33
|
+
export declare function fieldValue(type: mcdoc.McdocType, options: Options): core.SyncChecker<NbtNode>;
|
|
39
34
|
export {};
|
|
40
35
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/checker/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -21,46 +25,46 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.fieldValue = exports.path = exports.enum_ = exports.compound = exports.blockStates = exports.definition = exports.index = void 0;
|
|
23
27
|
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
-
const
|
|
28
|
+
const mcdoc = __importStar(require("@spyglassmc/mcdoc"));
|
|
25
29
|
const lib_1 = require("../../../locales/lib");
|
|
26
30
|
const node_1 = require("../node");
|
|
27
31
|
const util_1 = require("../util");
|
|
28
|
-
const
|
|
32
|
+
const mcdocUtil_1 = require("./mcdocUtil");
|
|
29
33
|
function index(registry, id, options = {}) {
|
|
30
34
|
switch (registry) {
|
|
31
35
|
case 'custom:blockitemstates':
|
|
32
|
-
const blockIds = (0,
|
|
36
|
+
const blockIds = (0, mcdocUtil_1.getBlocksFromItem)(id);
|
|
33
37
|
return blockIds
|
|
34
38
|
? blockStates(blockIds, options)
|
|
35
39
|
: core.checker.noop;
|
|
36
40
|
case 'custom:blockstates':
|
|
37
41
|
return blockStates([id], options);
|
|
38
42
|
case 'custom:spawnitemtag':
|
|
39
|
-
const entityId = (0,
|
|
43
|
+
const entityId = (0, mcdocUtil_1.getEntityFromItem)(id);
|
|
40
44
|
return entityId
|
|
41
45
|
? index('entity_type', entityId, options)
|
|
42
46
|
: core.checker.noop;
|
|
43
47
|
default:
|
|
44
48
|
return (node, ctx) => {
|
|
45
|
-
const { allowUnknownKey, value } = resolveRootRegistry(registry, id, ctx, node)
|
|
46
|
-
|
|
47
|
-
compound(value, options)(node, ctx)
|
|
49
|
+
// const { allowUnknownKey, value } = resolveRootRegistry(registry, id, ctx, node)
|
|
50
|
+
// options.allowUnknownKey ||= allowUnknownKey
|
|
51
|
+
// compound(value, options)(node, ctx)
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
exports.index = index;
|
|
52
56
|
/**
|
|
53
|
-
* @param identifier An identifier of
|
|
57
|
+
* @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
|
|
54
58
|
*/
|
|
55
59
|
function definition(identifier, options = {}) {
|
|
56
60
|
const index = identifier.lastIndexOf('::');
|
|
57
61
|
const module = identifier.slice(0, index);
|
|
58
62
|
const compoundDef = identifier.slice(index + 2);
|
|
59
|
-
const path = { category: '
|
|
63
|
+
const path = { category: 'mcdoc', path: [module, compoundDef] };
|
|
60
64
|
return (node, ctx) => {
|
|
61
|
-
const { allowUnknownKey, value } = resolveSymbolPaths([path], ctx, node)
|
|
62
|
-
|
|
63
|
-
compound(value, options)(node, ctx)
|
|
65
|
+
// const { allowUnknownKey, value } = resolveSymbolPaths([path], ctx, node)
|
|
66
|
+
// options.allowUnknownKey ||= allowUnknownKey
|
|
67
|
+
// compound(value, options)(node, ctx)
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
70
|
exports.definition = definition;
|
|
@@ -73,23 +77,23 @@ function blockStates(blocks, _options = {}) {
|
|
|
73
77
|
}
|
|
74
78
|
// Type check.
|
|
75
79
|
if (valueNode.type === 'nbt:byte' && (ctx.src.slice(valueNode.range).toLowerCase() === 'false' || ctx.src.slice(valueNode.range).toLowerCase() === 'true')) {
|
|
76
|
-
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.fake-boolean'), valueNode, 2 /* Warning */);
|
|
80
|
+
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.fake-boolean'), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
77
81
|
continue;
|
|
78
82
|
}
|
|
79
83
|
else if (valueNode.type !== 'string' && valueNode.type !== 'nbt:int') {
|
|
80
|
-
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unexpected-value-type'), valueNode, 2 /* Warning */);
|
|
84
|
+
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unexpected-value-type'), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
81
85
|
continue;
|
|
82
86
|
}
|
|
83
87
|
if (Object.keys(states).includes(keyNode.value)) {
|
|
84
88
|
// The current state exists. Check the value.
|
|
85
89
|
const stateValues = states[keyNode.value];
|
|
86
90
|
if (!stateValues.includes(valueNode.value.toString())) {
|
|
87
|
-
ctx.err.report((0, lib_1.localize)('expected-got', stateValues, (0, lib_1.localeQuote)(valueNode.value.toString())), valueNode, 2 /* Warning */);
|
|
91
|
+
ctx.err.report((0, lib_1.localize)('expected-got', stateValues, (0, lib_1.localeQuote)(valueNode.value.toString())), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
else {
|
|
91
95
|
// The current state doesn't exist.
|
|
92
|
-
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unknown-state', (0, lib_1.localeQuote)(keyNode.value), blocks), keyNode, 2 /* Warning */);
|
|
96
|
+
ctx.err.report((0, lib_1.localize)('nbt.checker.block-states.unknown-state', (0, lib_1.localeQuote)(keyNode.value), blocks), keyNode, 2 /* core.ErrorSeverity.Warning */);
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
};
|
|
@@ -107,11 +111,11 @@ function compound(data, options = {}) {
|
|
|
107
111
|
const key = keyNode.value;
|
|
108
112
|
const fieldData = data[key];
|
|
109
113
|
if (fieldData) {
|
|
110
|
-
fieldData.query
|
|
114
|
+
fieldData.query.enter({ usage: { type: 'reference', node: keyNode } });
|
|
111
115
|
fieldValue(fieldData.data, options)(valueNode, ctx);
|
|
112
116
|
}
|
|
113
117
|
else if (!options.allowUnknownKey) {
|
|
114
|
-
ctx.err.report((0, lib_1.localize)('unknown-key', (0, lib_1.localeQuote)(key)), keyNode, 2 /* Warning */);
|
|
118
|
+
ctx.err.report((0, lib_1.localize)('unknown-key', (0, lib_1.localeQuote)(key)), keyNode, 2 /* core.ErrorSeverity.Warning */);
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
};
|
|
@@ -122,143 +126,149 @@ function enum_(path, _options = {}) {
|
|
|
122
126
|
return core.checker.noop;
|
|
123
127
|
}
|
|
124
128
|
return (node, ctx) => {
|
|
125
|
-
const query = ctx.symbols.query(ctx.doc, path.category, ...path.path)
|
|
126
|
-
const data = query.symbol?.data
|
|
127
|
-
// Check type.
|
|
128
|
-
if (data?.
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
// Get all enum members.
|
|
132
|
-
const enumMembers = {}
|
|
133
|
-
query.forEachMember((name, memberQuery) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
-
// Check value.
|
|
140
|
-
if (!Object.values(enumMembers).includes(node.value.toString())) {
|
|
141
|
-
|
|
142
|
-
}
|
|
129
|
+
// const query = ctx.symbols.query(ctx.doc, path.category, ...path.path)
|
|
130
|
+
// const data = query.symbol?.data as mcdoc.EnumNode.SymbolData | undefined
|
|
131
|
+
// // Check type.
|
|
132
|
+
// if (data?.enumKind && node.type !== data.enumKind && node.type !== `nbt:${data.enumKind}`) {
|
|
133
|
+
// ctx.err.report(localize('expected', localize(`nbt.node.${data.enumKind}`)), node, core.ErrorSeverity.Warning)
|
|
134
|
+
// }
|
|
135
|
+
// // Get all enum members.
|
|
136
|
+
// const enumMembers: Record<string, string> = {}
|
|
137
|
+
// query.forEachMember((name, memberQuery) => {
|
|
138
|
+
// const value = (memberQuery.symbol?.data as mcdoc.EnumFieldNode.SymbolData | undefined)?.value
|
|
139
|
+
// if (value !== undefined) {
|
|
140
|
+
// enumMembers[name] = value.toString()
|
|
141
|
+
// }
|
|
142
|
+
// })
|
|
143
|
+
// // Check value.
|
|
144
|
+
// if (!Object.values(enumMembers).includes(node.value.toString())) {
|
|
145
|
+
// ctx.err.report(localize('expected',
|
|
146
|
+
// Object.entries(enumMembers).map(([k, v]) => `${k} = ${v}`)
|
|
147
|
+
// ), node, core.ErrorSeverity.Warning)
|
|
148
|
+
// }
|
|
143
149
|
};
|
|
144
150
|
}
|
|
145
151
|
exports.enum_ = enum_;
|
|
146
152
|
/**
|
|
147
|
-
* @param id If set to `undefined` or an empty array, all
|
|
153
|
+
* @param id If set to `undefined` or an empty array, all mcdoc compound definitions for this registry will be merged for checking, and unknown keys are allowed.
|
|
148
154
|
*/
|
|
149
155
|
function path(registry, id) {
|
|
150
156
|
return (node, ctx) => {
|
|
151
|
-
const resolveResult = resolveRootRegistry(registry, id, ctx, undefined)
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
157
|
+
// const resolveResult = resolveRootRegistry(registry, id, ctx, undefined)
|
|
158
|
+
// let targetType: mcdoc.McdocType | undefined = {
|
|
159
|
+
// kind: 'dispatcher',
|
|
160
|
+
// registry,
|
|
161
|
+
// index: ((): mcdoc.DispatcherData['index'] => {
|
|
162
|
+
// if (id === undefined) {
|
|
163
|
+
// return { kind: 'static', value: { keyword: '()' } }
|
|
164
|
+
// } else if (typeof id === 'string') {
|
|
165
|
+
// return { kind: 'static', value: id }
|
|
166
|
+
// } else {
|
|
167
|
+
// return id.map(v => ({ kind: 'static', value: v }))
|
|
168
|
+
// }
|
|
169
|
+
// })(),
|
|
170
|
+
// }
|
|
171
|
+
// const options: Options = { allowUnknownKey: resolveResult.allowUnknownKey, isPredicate: true }
|
|
172
|
+
// let currentCompound: NbtCompoundNode | undefined
|
|
173
|
+
// for (const child of node.children) {
|
|
174
|
+
// if (NbtCompoundNode.is(child)) {
|
|
175
|
+
// // Compound filter.
|
|
176
|
+
// currentCompound = child
|
|
177
|
+
// if (data?.type === 'union') {
|
|
178
|
+
// }
|
|
179
|
+
// if (data?.type === 'resolved_compound') {
|
|
180
|
+
// compound(data.data, options)(child, ctx)
|
|
181
|
+
// } else {
|
|
182
|
+
// ctx.err.report(localize('nbt.checker.path.unexpected-filter'), child, core.ErrorSeverity.Warning)
|
|
183
|
+
// }
|
|
184
|
+
// } else if (core.StringNode.is(child)) {
|
|
185
|
+
// // Key.
|
|
186
|
+
// if (data?.type === 'union') {
|
|
187
|
+
// }
|
|
188
|
+
// if (data?.type === 'resolved_compound') {
|
|
189
|
+
// const fieldData: ResolvedCompoundData[string] = data.data[child.value]
|
|
190
|
+
// if (fieldData) {
|
|
191
|
+
// fieldData.query.enter({ usage: { type: 'reference', node: child } })
|
|
192
|
+
// if (fieldData.data.type === 'byte_array' || fieldData.data.type === 'int_array' || fieldData.data.type === 'long_array' || fieldData.data.type === 'list' || fieldData.data.type === 'union') {
|
|
193
|
+
// data = fieldData.data
|
|
194
|
+
// } else {
|
|
195
|
+
// const resolveResult = resolveSymbolData(fieldData.data, ctx, currentCompound)
|
|
196
|
+
// if (resolveResult.value) {
|
|
197
|
+
// options.allowUnknownKey ||= resolveResult.allowUnknownKey
|
|
198
|
+
// data.data = resolveResult.value
|
|
199
|
+
// } else {
|
|
200
|
+
// data = undefined
|
|
201
|
+
// }
|
|
202
|
+
// }
|
|
203
|
+
// targetType = fieldData.data
|
|
204
|
+
// } else {
|
|
205
|
+
// if (!options.allowUnknownKey) {
|
|
206
|
+
// ctx.err.report(localize('unknown-key', localeQuote(child.value)), child, core.ErrorSeverity.Warning)
|
|
207
|
+
// }
|
|
208
|
+
// targetType = undefined
|
|
209
|
+
// break
|
|
210
|
+
// }
|
|
211
|
+
// } else {
|
|
212
|
+
// ctx.err.report(localize('nbt.checker.path.unexpected-key'), child, core.ErrorSeverity.Warning)
|
|
213
|
+
// targetType = undefined
|
|
214
|
+
// break
|
|
215
|
+
// }
|
|
216
|
+
// currentCompound = undefined
|
|
217
|
+
// } else {
|
|
218
|
+
// // Index.
|
|
219
|
+
// if (data?.type === 'byte_array' || data?.type === 'int_array' || data?.type === 'long_array' || data?.type === 'list') {
|
|
220
|
+
// // Check content.
|
|
221
|
+
// if (child.children !== undefined) {
|
|
222
|
+
// const [content] = child.children
|
|
223
|
+
// if (content.type === 'integer') {
|
|
224
|
+
// const absIndex = content.value < 0 ? -1 - content.value : content.value
|
|
225
|
+
// const [, maxLength] = data.lengthRange ?? [undefined, undefined]
|
|
226
|
+
// if (maxLength !== undefined && absIndex >= maxLength) {
|
|
227
|
+
// ctx.err.report(localize('nbt.checker.path.index-out-of-bound', content.value, maxLength), content, core.ErrorSeverity.Warning)
|
|
228
|
+
// }
|
|
229
|
+
// } else {
|
|
230
|
+
// let isUnexpectedFilter = true
|
|
231
|
+
// if (data.type === 'list') {
|
|
232
|
+
// const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound)
|
|
233
|
+
// options.allowUnknownKey ||= allowUnknownKey
|
|
234
|
+
// if (value) {
|
|
235
|
+
// isUnexpectedFilter = false
|
|
236
|
+
// compound(value, options)(content, ctx)
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
// if (isUnexpectedFilter) {
|
|
240
|
+
// ctx.err.report(localize('nbt.checker.path.unexpected-filter'), content, core.ErrorSeverity.Warning)
|
|
241
|
+
// targetType = undefined
|
|
242
|
+
// break
|
|
243
|
+
// }
|
|
244
|
+
// currentCompound = content
|
|
245
|
+
// }
|
|
246
|
+
// }
|
|
247
|
+
// // Set data for the next iteration.
|
|
248
|
+
// if (data.type === 'list') {
|
|
249
|
+
// const { allowUnknownKey, value } = resolveSymbolData(data.item, ctx, currentCompound)
|
|
250
|
+
// options.allowUnknownKey ||= allowUnknownKey
|
|
251
|
+
// targetType = data.item
|
|
252
|
+
// if (value) {
|
|
253
|
+
// data = { type: 'resolved_compound', data: value }
|
|
254
|
+
// } else {
|
|
255
|
+
// data = undefined
|
|
256
|
+
// }
|
|
257
|
+
// } else {
|
|
258
|
+
// targetType = {
|
|
259
|
+
// type: data.type.split('_')[0] as 'byte' | 'int' | 'long',
|
|
260
|
+
// valueRange: data.valueRange,
|
|
261
|
+
// }
|
|
262
|
+
// data = undefined
|
|
263
|
+
// }
|
|
264
|
+
// } else {
|
|
265
|
+
// ctx.err.report(localize('nbt.checker.path.unexpected-index'), child, core.ErrorSeverity.Warning)
|
|
266
|
+
// targetType = undefined
|
|
267
|
+
// break
|
|
268
|
+
// }
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
// ctx.ops.set(node, 'targetType', targetType)
|
|
262
272
|
};
|
|
263
273
|
}
|
|
264
274
|
exports.path = path;
|
|
@@ -268,11 +278,8 @@ function fieldValue(type, options) {
|
|
|
268
278
|
boolean: 'nbt:byte',
|
|
269
279
|
byte: 'nbt:byte',
|
|
270
280
|
byte_array: 'nbt:byte_array',
|
|
271
|
-
compound: 'nbt:compound',
|
|
272
281
|
double: 'nbt:double',
|
|
273
282
|
float: 'nbt:float',
|
|
274
|
-
id: 'string',
|
|
275
|
-
index: 'nbt:compound',
|
|
276
283
|
int: 'nbt:int',
|
|
277
284
|
int_array: 'nbt:int_array',
|
|
278
285
|
list: 'nbt:list',
|
|
@@ -280,18 +287,20 @@ function fieldValue(type, options) {
|
|
|
280
287
|
long_array: 'nbt:long_array',
|
|
281
288
|
short: 'nbt:short',
|
|
282
289
|
string: 'string',
|
|
290
|
+
struct: 'nbt:compound',
|
|
291
|
+
tuple: 'nbt:list',
|
|
283
292
|
};
|
|
284
293
|
return (node, ctx) => {
|
|
285
294
|
// Rough type check.
|
|
286
|
-
if (type.type !== 'enum' && type.type !== 'union' && node.type !== ExpectedTypes[type.
|
|
287
|
-
ctx.err.report((0, lib_1.localize)('expected', (0, util_1.localizeTag)(ExpectedTypes[type.
|
|
295
|
+
if (type.kind !== 'any' && type.kind !== 'dispatcher' && type.kind !== 'enum' && type.kind !== 'literal' && type.kind !== 'reference' && type.kind !== 'union' && node.type !== ExpectedTypes[type.kind]) {
|
|
296
|
+
ctx.err.report((0, lib_1.localize)('expected', (0, util_1.localizeTag)(ExpectedTypes[type.kind])), node, 2 /* core.ErrorSeverity.Warning */);
|
|
288
297
|
return;
|
|
289
298
|
}
|
|
290
|
-
switch (type.
|
|
299
|
+
switch (type.kind) {
|
|
291
300
|
case 'boolean':
|
|
292
301
|
node = node;
|
|
293
302
|
if (node.value !== 0 && node.value !== 1) {
|
|
294
|
-
ctx.err.report((0, lib_1.localize)('nbt.checker.boolean.out-of-range', (0, lib_1.localeQuote)('0b'), (0, lib_1.localeQuote)('1b')), node, 2 /* Warning */);
|
|
303
|
+
ctx.err.report((0, lib_1.localize)('nbt.checker.boolean.out-of-range', (0, lib_1.localeQuote)('0b'), (0, lib_1.localeQuote)('1b')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
295
304
|
}
|
|
296
305
|
break;
|
|
297
306
|
case 'byte_array':
|
|
@@ -299,12 +308,12 @@ function fieldValue(type, options) {
|
|
|
299
308
|
case 'long_array':
|
|
300
309
|
node = node;
|
|
301
310
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
302
|
-
ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* Warning */);
|
|
311
|
+
ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
303
312
|
}
|
|
304
313
|
if (type.valueRange) {
|
|
305
314
|
for (const { value: childNode } of node.children) {
|
|
306
315
|
if (childNode && !isInRange(Number(childNode.value), type.valueRange)) {
|
|
307
|
-
ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* Warning */);
|
|
316
|
+
ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
308
317
|
}
|
|
309
318
|
}
|
|
310
319
|
}
|
|
@@ -317,27 +326,25 @@ function fieldValue(type, options) {
|
|
|
317
326
|
case 'double':
|
|
318
327
|
node = node;
|
|
319
328
|
if (type.valueRange && !isInRange(Number(node.value), type.valueRange)) {
|
|
320
|
-
ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* Warning */);
|
|
329
|
+
ctx.err.report((0, lib_1.localize)('number.between', type.valueRange[0] ?? '-∞', type.valueRange[1] ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
321
330
|
}
|
|
322
331
|
break;
|
|
323
|
-
case '
|
|
332
|
+
case 'dispatcher':
|
|
324
333
|
node = node;
|
|
325
|
-
const id = resolveFieldPath(node.parent?.parent, type.index.path)
|
|
326
|
-
if (type.index.registry
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
? { category: type.registry, isPredicate: options.isPredicate }
|
|
334
|
-
: { allowUnknown: true, pool: [], isPredicate: options.isPredicate }), node.value, node.valueMap, ctx);
|
|
334
|
+
// const id = resolveFieldPath(node.parent?.parent, type.index.path)
|
|
335
|
+
// if (type.index.registry) {
|
|
336
|
+
// if (ExtendableRootRegistry.is(type.index.registry)) {
|
|
337
|
+
// index(type.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, options)(node, ctx)
|
|
338
|
+
// } else if (id) {
|
|
339
|
+
// index(type.index.registry, core.ResourceLocation.lengthen(id), options)(node, ctx)
|
|
340
|
+
// }
|
|
341
|
+
// }
|
|
335
342
|
break;
|
|
336
343
|
case 'list':
|
|
337
344
|
node = node;
|
|
338
|
-
type =
|
|
345
|
+
type = mcdoc.simplifyListType(type);
|
|
339
346
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
340
|
-
ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* Warning */);
|
|
347
|
+
ctx.err.report((0, lib_1.localize)('expected', (0, lib_1.localize)('nbt.checker.collection.length-between', (0, util_1.localizeTag)(node.type), type.lengthRange[0] ?? '-∞', type.lengthRange[1] ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
341
348
|
}
|
|
342
349
|
for (const { value: childNode } of node.children) {
|
|
343
350
|
if (childNode) {
|
|
@@ -354,10 +361,10 @@ function fieldValue(type, options) {
|
|
|
354
361
|
valueNode = node.parent.parent;
|
|
355
362
|
}
|
|
356
363
|
if (core.PairNode.is(valueNode.parent)) {
|
|
357
|
-
const
|
|
364
|
+
const structMcdocPath = valueNode.parent.key?.symbol?.parentSymbol?.path.join('::');
|
|
358
365
|
const key = valueNode.parent.key?.value;
|
|
359
|
-
const path = `${
|
|
360
|
-
const parserName = (0,
|
|
366
|
+
const path = `${structMcdocPath}.${key}${suffix}`;
|
|
367
|
+
const parserName = (0, mcdocUtil_1.getSpecialStringParser)(path);
|
|
361
368
|
if (parserName) {
|
|
362
369
|
try {
|
|
363
370
|
const parser = ctx.meta.getParser(parserName);
|
|
@@ -373,23 +380,19 @@ function fieldValue(type, options) {
|
|
|
373
380
|
}
|
|
374
381
|
}
|
|
375
382
|
break;
|
|
376
|
-
case '
|
|
377
|
-
node = node;
|
|
378
|
-
if (type.symbol) {
|
|
379
|
-
const { allowUnknownKey, value } = resolveSymbolPaths([type.symbol], ctx, node);
|
|
380
|
-
compound(value, { ...options, allowUnknownKey: options.allowUnknownKey || allowUnknownKey })(node, ctx);
|
|
381
|
-
}
|
|
382
|
-
break;
|
|
383
|
-
case 'enum':
|
|
383
|
+
case 'reference':
|
|
384
384
|
node = node;
|
|
385
|
-
|
|
385
|
+
// if (type.symbol) {
|
|
386
|
+
// const { allowUnknownKey, value } = resolveSymbolPaths([type.symbol], ctx, node)
|
|
387
|
+
// compound(value, { ...options, allowUnknownKey: options.allowUnknownKey || allowUnknownKey })(node, ctx)
|
|
388
|
+
// }
|
|
386
389
|
break;
|
|
387
390
|
case 'union':
|
|
388
|
-
type =
|
|
391
|
+
type = mcdoc.flattenUnionType(type);
|
|
389
392
|
if (type.members.length === 0) {
|
|
390
393
|
ctx.err.report((0, lib_1.localize)('nbt.checker.compound.field.union-empty-members'), core.PairNode.is(node.parent)
|
|
391
394
|
? (node.parent.key ?? node.parent)
|
|
392
|
-
: node, 2 /* Warning */);
|
|
395
|
+
: node, 2 /* core.ErrorSeverity.Warning */);
|
|
393
396
|
}
|
|
394
397
|
else {
|
|
395
398
|
core.checker.any(type.members.map(t => fieldValue(t, options)))(node, ctx);
|
|
@@ -399,195 +402,4 @@ function fieldValue(type, options) {
|
|
|
399
402
|
};
|
|
400
403
|
}
|
|
401
404
|
exports.fieldValue = fieldValue;
|
|
402
|
-
function resolveFieldPath(compound, fieldPath) {
|
|
403
|
-
let node = compound;
|
|
404
|
-
for (const path of fieldPath) {
|
|
405
|
-
if (!node) {
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
if (typeof path === 'object') {
|
|
409
|
-
// Super.
|
|
410
|
-
node = node.parent;
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
// Field key.
|
|
414
|
-
if (!node_1.NbtCompoundNode.is(node)) {
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
node = node.children.find(({ key }) => key?.value === path)?.value;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return node && node_1.NbtPrimitiveNode.is(node)
|
|
421
|
-
? node.value.toString()
|
|
422
|
-
: undefined;
|
|
423
|
-
}
|
|
424
|
-
const getUnwrapper = (out) => (result) => {
|
|
425
|
-
out.allowUnknownKey || (out.allowUnknownKey = result.allowUnknownKey);
|
|
426
|
-
return result.value;
|
|
427
|
-
};
|
|
428
|
-
const map = (result, cb) => {
|
|
429
|
-
const ans = cb(result.value);
|
|
430
|
-
return {
|
|
431
|
-
allowUnknownKey: result.allowUnknownKey || ans.allowUnknownKey,
|
|
432
|
-
value: ans.value,
|
|
433
|
-
};
|
|
434
|
-
};
|
|
435
|
-
function getPathsFromRootRegistry(registry, inputIds, ctx) {
|
|
436
|
-
if (!registry) {
|
|
437
|
-
return { allowUnknownKey: true, value: [] };
|
|
438
|
-
}
|
|
439
|
-
const normalizeIds = (input, descriptionQuery) => {
|
|
440
|
-
let allowUnknownKey = false;
|
|
441
|
-
let ids;
|
|
442
|
-
if (input === undefined || (Array.isArray(input) && input.length === 0)) {
|
|
443
|
-
ids = Object.keys(descriptionQuery.visibleMembers);
|
|
444
|
-
allowUnknownKey = true;
|
|
445
|
-
}
|
|
446
|
-
else if (!Array.isArray(input)) {
|
|
447
|
-
ids = [input];
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
ids = input;
|
|
451
|
-
}
|
|
452
|
-
return { allowUnknownKey, value: ids };
|
|
453
|
-
};
|
|
454
|
-
const collectPaths = (ids, descriptionQuery) => {
|
|
455
|
-
let allowUnknownKey = false;
|
|
456
|
-
const paths = new core.SymbolPathCollector();
|
|
457
|
-
descriptionQuery.ifKnown(() => {
|
|
458
|
-
for (const id of ids) {
|
|
459
|
-
descriptionQuery.member(id, member => member
|
|
460
|
-
.ifKnown(symbol => paths.add(symbol.relations?.describedBy))
|
|
461
|
-
.else(() => descriptionQuery.member('@default', defaultMember => {
|
|
462
|
-
allowUnknownKey = true;
|
|
463
|
-
paths.add(defaultMember.symbol?.relations?.describedBy);
|
|
464
|
-
})));
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
return { allowUnknownKey, value: paths.collect() };
|
|
468
|
-
};
|
|
469
|
-
const descriptionQuery = ctx.symbols.query(ctx.doc, 'nbtdoc/description', registry);
|
|
470
|
-
return map(normalizeIds(inputIds, descriptionQuery), ids => collectPaths(ids, descriptionQuery));
|
|
471
|
-
}
|
|
472
|
-
function resolveSymbolPaths(paths, ctx, compound) {
|
|
473
|
-
if (paths.length === 0) {
|
|
474
|
-
return { allowUnknownKey: true, value: {} };
|
|
475
|
-
}
|
|
476
|
-
const getDefinitionQuery = (path) => {
|
|
477
|
-
return {
|
|
478
|
-
allowUnknownKey: (0, nbtdocUtil_1.isExpandableCompound)(path.path.join('::')),
|
|
479
|
-
value: ctx.symbols.query(ctx.doc, path.category, ...path.path),
|
|
480
|
-
};
|
|
481
|
-
};
|
|
482
|
-
const getPathsFromSuper = (extendable) => {
|
|
483
|
-
if (extendable.type === 'compound') {
|
|
484
|
-
return { allowUnknownKey: false, value: extendable.symbol ? [extendable.symbol] : [] };
|
|
485
|
-
}
|
|
486
|
-
else {
|
|
487
|
-
const id = resolveFieldPath(compound, extendable.index.path);
|
|
488
|
-
return getPathsFromRootRegistry(extendable.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, ctx);
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
const getPathsRecursively = (paths) => {
|
|
492
|
-
const collector = new core.SymbolPathCollector();
|
|
493
|
-
const out = { allowUnknownKey: false };
|
|
494
|
-
const unwrap = getUnwrapper(out);
|
|
495
|
-
const iterate = (paths) => {
|
|
496
|
-
for (const path of paths) {
|
|
497
|
-
if (collector.has(path)) {
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
collector.add(path);
|
|
501
|
-
const query = unwrap(getDefinitionQuery(path));
|
|
502
|
-
const data = query.symbol?.data;
|
|
503
|
-
if (data) {
|
|
504
|
-
const superPaths = data.extends ? unwrap(getPathsFromSuper(data.extends)) : [];
|
|
505
|
-
iterate(superPaths);
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
out.allowUnknownKey = true;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
iterate(paths);
|
|
513
|
-
return { allowUnknownKey: out.allowUnknownKey, value: collector.collect() };
|
|
514
|
-
};
|
|
515
|
-
const ans = Object.create(null);
|
|
516
|
-
const out = { allowUnknownKey: false };
|
|
517
|
-
const unwrap = getUnwrapper(out);
|
|
518
|
-
const allPaths = unwrap(getPathsRecursively(paths));
|
|
519
|
-
for (const path of allPaths) {
|
|
520
|
-
const query = unwrap(getDefinitionQuery(path));
|
|
521
|
-
query.forEachMember((key, keyQuery) => {
|
|
522
|
-
const data = keyQuery.symbol?.data;
|
|
523
|
-
if (!data) {
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
if (ans[key]) {
|
|
527
|
-
delete ans[key].query;
|
|
528
|
-
const existingData = ans[key].data;
|
|
529
|
-
if (existingData.type === 'union') {
|
|
530
|
-
existingData.members.push(data.fieldType);
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
ans[key].data = { type: 'union', members: [existingData, data.fieldType] };
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
ans[key] = { data: data.fieldType, query: keyQuery };
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
return { allowUnknownKey: out.allowUnknownKey, value: ans };
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* @param registry If `undefined`, allows unknown key.
|
|
545
|
-
* @param id If `undefined` or an empty array, merges all available definitions and allows unknown key.
|
|
546
|
-
*/
|
|
547
|
-
function resolveRootRegistry(registry, inputIds, ctx, compound) {
|
|
548
|
-
const out = { allowUnknownKey: false };
|
|
549
|
-
const unwrap = getUnwrapper(out);
|
|
550
|
-
const paths = unwrap(getPathsFromRootRegistry(registry, inputIds, ctx));
|
|
551
|
-
const data = unwrap(resolveSymbolPaths(paths, ctx, compound));
|
|
552
|
-
return { allowUnknownKey: out.allowUnknownKey, value: data };
|
|
553
|
-
}
|
|
554
|
-
function resolveSymbolData(data, ctx, compound) {
|
|
555
|
-
const out = { allowUnknownKey: false };
|
|
556
|
-
const unwrap = getUnwrapper(out);
|
|
557
|
-
const paths = unwrap(getPathsFromSymbolData(data, ctx, compound));
|
|
558
|
-
if (!paths) {
|
|
559
|
-
return { allowUnknownKey: out.allowUnknownKey, value: undefined };
|
|
560
|
-
}
|
|
561
|
-
const ans = unwrap(resolveSymbolPaths(paths, ctx, compound));
|
|
562
|
-
return { allowUnknownKey: out.allowUnknownKey, value: ans };
|
|
563
|
-
}
|
|
564
|
-
function getPathsFromSymbolData(data, ctx, compound) {
|
|
565
|
-
const collector = new core.SymbolPathCollector();
|
|
566
|
-
const out = { allowUnknownKey: false };
|
|
567
|
-
const unwrap = getUnwrapper(out);
|
|
568
|
-
const iterate = (data) => {
|
|
569
|
-
if (data.type === 'compound') {
|
|
570
|
-
collector.add(data.symbol);
|
|
571
|
-
return true;
|
|
572
|
-
}
|
|
573
|
-
else if (data.type === 'index') {
|
|
574
|
-
const id = resolveFieldPath(compound, data.index.path);
|
|
575
|
-
const paths = unwrap(getPathsFromRootRegistry(data.index.registry, id ? core.ResourceLocation.lengthen(id) : undefined, ctx));
|
|
576
|
-
for (const path of paths) {
|
|
577
|
-
collector.add(path);
|
|
578
|
-
}
|
|
579
|
-
return true;
|
|
580
|
-
}
|
|
581
|
-
else if (data.type === 'union') {
|
|
582
|
-
let ans = false;
|
|
583
|
-
for (const member of data.members) {
|
|
584
|
-
ans || (ans = iterate(member));
|
|
585
|
-
}
|
|
586
|
-
return ans;
|
|
587
|
-
}
|
|
588
|
-
return false;
|
|
589
|
-
};
|
|
590
|
-
const isCompoundData = iterate(data);
|
|
591
|
-
return { allowUnknownKey: out.allowUnknownKey, value: isCompoundData ? collector.collect() : undefined };
|
|
592
|
-
}
|
|
593
405
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as core from '@spyglassmc/core';
|
|
2
|
+
export declare function getBlocksFromItem(item: core.FullResourceLocation): core.FullResourceLocation[] | undefined;
|
|
3
|
+
export declare function getEntityFromItem(item: core.FullResourceLocation): core.FullResourceLocation | undefined;
|
|
4
|
+
export declare function getSpecialStringParser(mcdocPath: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* @param mcdocPath Path of the mcdoc compound definition.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isExpandableCompound(mcdocPath: string): boolean;
|
|
9
|
+
//# sourceMappingURL=mcdocUtil.d.ts.map
|
|
@@ -140,8 +140,7 @@ const SpecialStrings = {
|
|
|
140
140
|
'::minecraft::block::sign::Sign.Text2': 'mcfunction:component',
|
|
141
141
|
'::minecraft::block::sign::Sign.Text3': 'mcfunction:component',
|
|
142
142
|
'::minecraft::block::sign::Sign.Text4': 'mcfunction:component',
|
|
143
|
-
|
|
144
|
-
// '::minecraft::entity::effectcloud::EffectCloud.Particle': 'mcfunction:particle',
|
|
143
|
+
'::minecraft::entity::effectcloud::EffectCloud.Particle': 'mcfunction:particle',
|
|
145
144
|
'::minecraft::entity::minecart::CommandMinecart.Command': 'mcfunction:command',
|
|
146
145
|
'::minecraft::entity::mob::LivingEntity.Team': 'mcfunction:team',
|
|
147
146
|
'::minecraft::entity::EntityBase.Tags[]': 'mcfunction:tag',
|
|
@@ -149,19 +148,21 @@ const SpecialStrings = {
|
|
|
149
148
|
'::minecraft::item::book::WrittenBook.pages[]': 'mcfunction:component',
|
|
150
149
|
'::minecraft::item::ItemBase.CanDestroy[]': 'mcfunction:block_predicate',
|
|
151
150
|
};
|
|
152
|
-
function getSpecialStringParser(
|
|
153
|
-
return SpecialStrings[
|
|
151
|
+
function getSpecialStringParser(mcdocPath) {
|
|
152
|
+
return SpecialStrings[mcdocPath];
|
|
154
153
|
}
|
|
155
154
|
exports.getSpecialStringParser = getSpecialStringParser;
|
|
156
155
|
const ExpandableCompounds = [
|
|
157
156
|
'::minecraft::item::ItemBase',
|
|
158
157
|
'::minecraft::entity::marker::Any',
|
|
158
|
+
'::minecraft::util::any::Any',
|
|
159
|
+
'::minecraft::util::Any',
|
|
159
160
|
];
|
|
160
161
|
/**
|
|
161
|
-
* @param
|
|
162
|
+
* @param mcdocPath Path of the mcdoc compound definition.
|
|
162
163
|
*/
|
|
163
|
-
function isExpandableCompound(
|
|
164
|
-
return ExpandableCompounds.includes(
|
|
164
|
+
function isExpandableCompound(mcdocPath) {
|
|
165
|
+
return ExpandableCompounds.includes(mcdocPath);
|
|
165
166
|
}
|
|
166
167
|
exports.isExpandableCompound = isExpandableCompound;
|
|
167
|
-
//# sourceMappingURL=
|
|
168
|
+
//# sourceMappingURL=mcdocUtil.js.map
|
package/lib/colorizer/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type * as
|
|
2
|
+
import type * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
3
|
export declare type NbtNode = NbtPrimitiveNode | NbtCompoundNode | NbtCollectionNode;
|
|
4
4
|
export declare namespace NbtNode {
|
|
5
5
|
function is(node: core.AstNode | undefined): node is NbtNode;
|
|
@@ -98,7 +98,7 @@ export declare namespace NbtLongArrayNode {
|
|
|
98
98
|
export interface NbtPathNode extends core.AstNode {
|
|
99
99
|
type: 'nbt:path';
|
|
100
100
|
children: (core.StringNode | NbtCompoundNode | NbtPathIndexNode)[];
|
|
101
|
-
targetType?:
|
|
101
|
+
targetType?: mcdoc.McdocType | undefined;
|
|
102
102
|
}
|
|
103
103
|
export declare namespace NbtPathNode {
|
|
104
104
|
function is(node: core.AstNode | undefined): node is NbtPathNode;
|
package/lib/node/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/collection.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/compound.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/entry.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -24,13 +28,13 @@ const core = __importStar(require("@spyglassmc/core"));
|
|
|
24
28
|
const collection_1 = require("./collection");
|
|
25
29
|
const compound_1 = require("./compound");
|
|
26
30
|
const primitive_1 = require("./primitive");
|
|
27
|
-
const entry = (src, ctx) => core.failOnEmpty(core.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
collection_1.
|
|
31
|
-
collection_1.
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const entry = (src, ctx) => core.failOnEmpty(core.select([
|
|
32
|
+
{ predicate: src => src.tryPeek('[B;'), parser: collection_1.byteArray },
|
|
33
|
+
{ predicate: src => src.tryPeek('[I;'), parser: collection_1.intArray },
|
|
34
|
+
{ predicate: src => src.tryPeek('[L;'), parser: collection_1.longArray },
|
|
35
|
+
{ predicate: src => src.tryPeek('['), parser: collection_1.list },
|
|
36
|
+
{ predicate: src => src.tryPeek('{'), parser: compound_1.compound },
|
|
37
|
+
{ parser: primitive_1.primitive },
|
|
34
38
|
]))(src, ctx);
|
|
35
39
|
exports.entry = entry;
|
|
36
40
|
//# sourceMappingURL=entry.js.map
|
package/lib/parser/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/path.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/primitive.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -25,15 +29,15 @@ const locales_1 = require("@spyglassmc/locales");
|
|
|
25
29
|
const util_1 = require("../util");
|
|
26
30
|
const FloatMaximum = (2 - (2 ** -23)) * (2 ** 127);
|
|
27
31
|
const NumeralPatterns = [
|
|
28
|
-
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)b$/i, type: 'nbt:byte', hasSuffix: true, group: 2 /* IntegerAlike */, min: -128, max: 127 },
|
|
29
|
-
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)s$/i, type: 'nbt:short', hasSuffix: true, group: 2 /* IntegerAlike */, min: -32768, max: 32767 },
|
|
30
|
-
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)$/, type: 'nbt:int', hasSuffix: false, group: 2 /* IntegerAlike */, min: -2147483648, max: 2147483647 },
|
|
31
|
-
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)l$/i, type: 'nbt:long', hasSuffix: true, group: 3 /* LongAlike */, min: -9223372036854775808n, max: 9223372036854775807n },
|
|
32
|
-
{ pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?f$/i, type: 'nbt:float', hasSuffix: true, group: 1 /* FloatAlike */, min: -FloatMaximum, max: FloatMaximum },
|
|
33
|
-
{ pattern: /^[-+]?(?:[0-9]+\.|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?$/i, type: 'nbt:double', hasSuffix: false, group: 1 /* FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
|
|
34
|
-
{ pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?d$/i, type: 'nbt:double', hasSuffix: true, group: 1 /* FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
|
|
35
|
-
{ pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Boolean */ },
|
|
36
|
-
{ pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Boolean */ },
|
|
32
|
+
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)b$/i, type: 'nbt:byte', hasSuffix: true, group: 2 /* Group.IntegerAlike */, min: -128, max: 127 },
|
|
33
|
+
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)s$/i, type: 'nbt:short', hasSuffix: true, group: 2 /* Group.IntegerAlike */, min: -32768, max: 32767 },
|
|
34
|
+
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)$/, type: 'nbt:int', hasSuffix: false, group: 2 /* Group.IntegerAlike */, min: -2147483648, max: 2147483647 },
|
|
35
|
+
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)l$/i, type: 'nbt:long', hasSuffix: true, group: 3 /* Group.LongAlike */, min: -9223372036854775808n, max: 9223372036854775807n },
|
|
36
|
+
{ pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?f$/i, type: 'nbt:float', hasSuffix: true, group: 1 /* Group.FloatAlike */, min: -FloatMaximum, max: FloatMaximum },
|
|
37
|
+
{ pattern: /^[-+]?(?:[0-9]+\.|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?$/i, type: 'nbt:double', hasSuffix: false, group: 1 /* Group.FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
|
|
38
|
+
{ pattern: /^[-+]?(?:[0-9]+\.?|[0-9]*\.[0-9]+)(?:e[-+]?[0-9]+)?d$/i, type: 'nbt:double', hasSuffix: true, group: 1 /* Group.FloatAlike */, min: -Number.MAX_VALUE, max: Number.MAX_VALUE },
|
|
39
|
+
{ pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Group.Boolean */ },
|
|
40
|
+
{ pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Group.Boolean */ },
|
|
37
41
|
];
|
|
38
42
|
exports.string = core.brigadierString;
|
|
39
43
|
const primitive = (src, ctx) => {
|
|
@@ -43,7 +47,7 @@ const primitive = (src, ctx) => {
|
|
|
43
47
|
const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(exports.string, src, ctx);
|
|
44
48
|
for (const e of NumeralPatterns) {
|
|
45
49
|
if (e.pattern.test(unquotedResult.value)) {
|
|
46
|
-
if (e.group === 0 /* Boolean */) {
|
|
50
|
+
if (e.group === 0 /* Group.Boolean */) {
|
|
47
51
|
const ans = {
|
|
48
52
|
type: 'nbt:byte',
|
|
49
53
|
range: unquotedResult.range,
|
|
@@ -54,16 +58,16 @@ const primitive = (src, ctx) => {
|
|
|
54
58
|
}
|
|
55
59
|
let isOutOfRange = false;
|
|
56
60
|
const onOutOfRange = () => isOutOfRange = true;
|
|
57
|
-
const numeralParser = e.group === 2 /* IntegerAlike */
|
|
61
|
+
const numeralParser = e.group === 2 /* Group.IntegerAlike */
|
|
58
62
|
// As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
|
|
59
63
|
// it again here in the parser, therefore we just pass in a simple /./ regex.
|
|
60
64
|
? core.integer({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
|
|
61
|
-
: e.group === 3 /* LongAlike */
|
|
65
|
+
: e.group === 3 /* Group.LongAlike */
|
|
62
66
|
? core.long({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
|
|
63
67
|
: core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
|
|
64
68
|
const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
|
|
65
69
|
if (isOutOfRange) {
|
|
66
|
-
ctx.err.report((0, locales_1.localize)('nbt.parser.number.out-of-range', (0, util_1.localizeTag)(e.type), (0, locales_1.localize)('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* Warning */);
|
|
70
|
+
ctx.err.report((0, locales_1.localize)('nbt.parser.number.out-of-range', (0, util_1.localizeTag)(e.type), (0, locales_1.localize)('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* core.ErrorSeverity.Warning */);
|
|
67
71
|
break;
|
|
68
72
|
}
|
|
69
73
|
updateNumeral();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/nbt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "SPGoding",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@spyglassmc/core": "0.1.
|
|
28
|
-
"@spyglassmc/locales": "0.1.
|
|
29
|
-
"@spyglassmc/
|
|
27
|
+
"@spyglassmc/core": "0.1.2",
|
|
28
|
+
"@spyglassmc/locales": "0.1.2",
|
|
29
|
+
"@spyglassmc/mcdoc": "0.1.1"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type * as core from '../../../core/lib';
|
|
2
|
-
export declare function getBlocksFromItem(item: core.FullResourceLocation): core.FullResourceLocation[] | undefined;
|
|
3
|
-
export declare function getEntityFromItem(item: core.FullResourceLocation): core.FullResourceLocation | undefined;
|
|
4
|
-
export declare function getSpecialStringParser(nbtdocPath: string): string | undefined;
|
|
5
|
-
/**
|
|
6
|
-
* @param nbtdocPath Path of the nbtdoc compound definition.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isExpandableCompound(nbtdocPath: string): boolean;
|
|
9
|
-
//# sourceMappingURL=nbtdocUtil.d.ts.map
|