@spyglassmc/nbt 0.1.3 → 0.3.1
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 +1 -1
- package/lib/checker/index.js +34 -64
- package/lib/checker/mcdocUtil.js +4 -11
- package/lib/colorizer/index.js +2 -29
- package/lib/index.d.ts +5 -5
- package/lib/index.js +7 -37
- package/lib/node/index.d.ts +5 -5
- package/lib/node/index.js +41 -67
- package/lib/parser/collection.d.ts +1 -1
- package/lib/parser/collection.js +17 -47
- package/lib/parser/compound.d.ts +1 -1
- package/lib/parser/compound.js +4 -31
- package/lib/parser/entry.d.ts +1 -1
- package/lib/parser/entry.js +11 -38
- package/lib/parser/index.d.ts +5 -5
- package/lib/parser/index.js +5 -21
- package/lib/parser/path.d.ts +1 -1
- package/lib/parser/path.js +9 -36
- package/lib/parser/primitive.d.ts +1 -1
- package/lib/parser/primitive.js +8 -35
- package/lib/util.d.ts +1 -1
- package/lib/util.js +3 -7
- package/package.json +5 -4
package/lib/checker/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
-
import type { NbtCompoundNode, NbtNode, NbtPathNode, NbtPrimitiveNode } from '../node';
|
|
3
|
+
import type { NbtCompoundNode, NbtNode, NbtPathNode, NbtPrimitiveNode } from '../node/index.js';
|
|
4
4
|
interface Options {
|
|
5
5
|
allowUnknownKey?: boolean;
|
|
6
6
|
isPredicate?: boolean;
|
package/lib/checker/index.js
CHANGED
|
@@ -1,46 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.fieldValue = exports.path = exports.enum_ = exports.compound = exports.blockStates = exports.definition = exports.index = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const mcdoc = __importStar(require("@spyglassmc/mcdoc"));
|
|
29
|
-
const lib_1 = require("../../../locales/lib");
|
|
30
|
-
const node_1 = require("../node");
|
|
31
|
-
const util_1 = require("../util");
|
|
32
|
-
const mcdocUtil_1 = require("./mcdocUtil");
|
|
33
|
-
function index(registry, id, options = {}) {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
4
|
+
import { NbtListNode } from '../node/index.js';
|
|
5
|
+
import { localizeTag } from '../util.js';
|
|
6
|
+
import { getBlocksFromItem, getEntityFromItem, getSpecialStringParser } from './mcdocUtil.js';
|
|
7
|
+
export function index(registry, id, options = {}) {
|
|
34
8
|
switch (registry) {
|
|
35
9
|
case 'custom:blockitemstates':
|
|
36
|
-
const blockIds =
|
|
10
|
+
const blockIds = getBlocksFromItem(id);
|
|
37
11
|
return blockIds
|
|
38
12
|
? blockStates(blockIds, options)
|
|
39
13
|
: core.checker.noop;
|
|
40
14
|
case 'custom:blockstates':
|
|
41
15
|
return blockStates([id], options);
|
|
42
16
|
case 'custom:spawnitemtag':
|
|
43
|
-
const entityId =
|
|
17
|
+
const entityId = getEntityFromItem(id);
|
|
44
18
|
return entityId
|
|
45
19
|
? index('entity_type', entityId, options)
|
|
46
20
|
: core.checker.noop;
|
|
@@ -52,11 +26,10 @@ function index(registry, id, options = {}) {
|
|
|
52
26
|
};
|
|
53
27
|
}
|
|
54
28
|
}
|
|
55
|
-
exports.index = index;
|
|
56
29
|
/**
|
|
57
30
|
* @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
|
|
58
31
|
*/
|
|
59
|
-
function definition(identifier, options = {}) {
|
|
32
|
+
export function definition(identifier, options = {}) {
|
|
60
33
|
const index = identifier.lastIndexOf('::');
|
|
61
34
|
const module = identifier.slice(0, index);
|
|
62
35
|
const compoundDef = identifier.slice(index + 2);
|
|
@@ -67,8 +40,7 @@ function definition(identifier, options = {}) {
|
|
|
67
40
|
// compound(value, options)(node, ctx)
|
|
68
41
|
};
|
|
69
42
|
}
|
|
70
|
-
|
|
71
|
-
function blockStates(blocks, _options = {}) {
|
|
43
|
+
export function blockStates(blocks, _options = {}) {
|
|
72
44
|
return (node, ctx) => {
|
|
73
45
|
const states = core.getStates('block', blocks, ctx);
|
|
74
46
|
for (const { key: keyNode, value: valueNode } of node.children) {
|
|
@@ -77,32 +49,31 @@ function blockStates(blocks, _options = {}) {
|
|
|
77
49
|
}
|
|
78
50
|
// Type check.
|
|
79
51
|
if (valueNode.type === 'nbt:byte' && (ctx.src.slice(valueNode.range).toLowerCase() === 'false' || ctx.src.slice(valueNode.range).toLowerCase() === 'true')) {
|
|
80
|
-
ctx.err.report(
|
|
52
|
+
ctx.err.report(localize('nbt.checker.block-states.fake-boolean'), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
81
53
|
continue;
|
|
82
54
|
}
|
|
83
55
|
else if (valueNode.type !== 'string' && valueNode.type !== 'nbt:int') {
|
|
84
|
-
ctx.err.report(
|
|
56
|
+
ctx.err.report(localize('nbt.checker.block-states.unexpected-value-type'), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
85
57
|
continue;
|
|
86
58
|
}
|
|
87
59
|
if (Object.keys(states).includes(keyNode.value)) {
|
|
88
60
|
// The current state exists. Check the value.
|
|
89
61
|
const stateValues = states[keyNode.value];
|
|
90
62
|
if (!stateValues.includes(valueNode.value.toString())) {
|
|
91
|
-
ctx.err.report(
|
|
63
|
+
ctx.err.report(localize('expected-got', stateValues, localeQuote(valueNode.value.toString())), valueNode, 2 /* core.ErrorSeverity.Warning */);
|
|
92
64
|
}
|
|
93
65
|
}
|
|
94
66
|
else {
|
|
95
67
|
// The current state doesn't exist.
|
|
96
|
-
ctx.err.report(
|
|
68
|
+
ctx.err.report(localize('nbt.checker.block-states.unknown-state', localeQuote(keyNode.value), blocks), keyNode, 2 /* core.ErrorSeverity.Warning */);
|
|
97
69
|
}
|
|
98
70
|
}
|
|
99
71
|
};
|
|
100
72
|
}
|
|
101
|
-
exports.blockStates = blockStates;
|
|
102
73
|
/**
|
|
103
74
|
* @param path The {@link core.SymbolPath} to the compound definition.
|
|
104
75
|
*/
|
|
105
|
-
function compound(data, options = {}) {
|
|
76
|
+
export function compound(data, options = {}) {
|
|
106
77
|
return (node, ctx) => {
|
|
107
78
|
for (const { key: keyNode, value: valueNode } of node.children) {
|
|
108
79
|
if (!keyNode || !valueNode) {
|
|
@@ -115,13 +86,12 @@ function compound(data, options = {}) {
|
|
|
115
86
|
fieldValue(fieldData.data, options)(valueNode, ctx);
|
|
116
87
|
}
|
|
117
88
|
else if (!options.allowUnknownKey) {
|
|
118
|
-
ctx.err.report(
|
|
89
|
+
ctx.err.report(localize('unknown-key', localeQuote(key)), keyNode, 2 /* core.ErrorSeverity.Warning */);
|
|
119
90
|
}
|
|
120
91
|
}
|
|
121
92
|
};
|
|
122
93
|
}
|
|
123
|
-
|
|
124
|
-
function enum_(path, _options = {}) {
|
|
94
|
+
export function enum_(path, _options = {}) {
|
|
125
95
|
if (!path) {
|
|
126
96
|
return core.checker.noop;
|
|
127
97
|
}
|
|
@@ -148,11 +118,10 @@ function enum_(path, _options = {}) {
|
|
|
148
118
|
// }
|
|
149
119
|
};
|
|
150
120
|
}
|
|
151
|
-
exports.enum_ = enum_;
|
|
152
121
|
/**
|
|
153
122
|
* @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.
|
|
154
123
|
*/
|
|
155
|
-
function path(registry, id) {
|
|
124
|
+
export function path(registry, id) {
|
|
156
125
|
return (node, ctx) => {
|
|
157
126
|
// const resolveResult = resolveRootRegistry(registry, id, ctx, undefined)
|
|
158
127
|
// let targetType: mcdoc.McdocType | undefined = {
|
|
@@ -271,9 +240,11 @@ function path(registry, id) {
|
|
|
271
240
|
// ctx.ops.set(node, 'targetType', targetType)
|
|
272
241
|
};
|
|
273
242
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
243
|
+
export function fieldValue(type, options) {
|
|
244
|
+
const isInRange = (value, { kind, min = -Infinity, max = Infinity }) => {
|
|
245
|
+
const comparator = (a, b, exclusive) => exclusive ? a < b : a <= b;
|
|
246
|
+
return comparator(min, value, kind & 0b10) && comparator(value, max, kind & 0b01);
|
|
247
|
+
};
|
|
277
248
|
const ExpectedTypes = {
|
|
278
249
|
boolean: 'nbt:byte',
|
|
279
250
|
byte: 'nbt:byte',
|
|
@@ -293,14 +264,14 @@ function fieldValue(type, options) {
|
|
|
293
264
|
return (node, ctx) => {
|
|
294
265
|
// Rough type check.
|
|
295
266
|
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(
|
|
267
|
+
ctx.err.report(localize('expected', localizeTag(ExpectedTypes[type.kind])), node, 2 /* core.ErrorSeverity.Warning */);
|
|
297
268
|
return;
|
|
298
269
|
}
|
|
299
270
|
switch (type.kind) {
|
|
300
271
|
case 'boolean':
|
|
301
272
|
node = node;
|
|
302
273
|
if (node.value !== 0 && node.value !== 1) {
|
|
303
|
-
ctx.err.report(
|
|
274
|
+
ctx.err.report(localize('nbt.checker.boolean.out-of-range', localeQuote('0b'), localeQuote('1b')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
304
275
|
}
|
|
305
276
|
break;
|
|
306
277
|
case 'byte_array':
|
|
@@ -308,12 +279,12 @@ function fieldValue(type, options) {
|
|
|
308
279
|
case 'long_array':
|
|
309
280
|
node = node;
|
|
310
281
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
311
|
-
ctx.err.report(
|
|
282
|
+
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange.min ?? '-∞', type.lengthRange.max ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
312
283
|
}
|
|
313
284
|
if (type.valueRange) {
|
|
314
285
|
for (const { value: childNode } of node.children) {
|
|
315
286
|
if (childNode && !isInRange(Number(childNode.value), type.valueRange)) {
|
|
316
|
-
ctx.err.report(
|
|
287
|
+
ctx.err.report(localize('number.between', type.valueRange.min ?? '-∞', type.valueRange.max ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
317
288
|
}
|
|
318
289
|
}
|
|
319
290
|
}
|
|
@@ -326,7 +297,7 @@ function fieldValue(type, options) {
|
|
|
326
297
|
case 'double':
|
|
327
298
|
node = node;
|
|
328
299
|
if (type.valueRange && !isInRange(Number(node.value), type.valueRange)) {
|
|
329
|
-
ctx.err.report(
|
|
300
|
+
ctx.err.report(localize('number.between', type.valueRange.min ?? '-∞', type.valueRange.max ?? '+∞'), node, 2 /* core.ErrorSeverity.Warning */);
|
|
330
301
|
}
|
|
331
302
|
break;
|
|
332
303
|
case 'dispatcher':
|
|
@@ -344,7 +315,7 @@ function fieldValue(type, options) {
|
|
|
344
315
|
node = node;
|
|
345
316
|
type = mcdoc.simplifyListType(type);
|
|
346
317
|
if (type.lengthRange && !isInRange(node.children.length, type.lengthRange)) {
|
|
347
|
-
ctx.err.report(
|
|
318
|
+
ctx.err.report(localize('expected', localize('nbt.checker.collection.length-between', localizeTag(node.type), type.lengthRange.min ?? '-∞', type.lengthRange.max ?? '+∞')), node, 2 /* core.ErrorSeverity.Warning */);
|
|
348
319
|
}
|
|
349
320
|
for (const { value: childNode } of node.children) {
|
|
350
321
|
if (childNode) {
|
|
@@ -356,7 +327,7 @@ function fieldValue(type, options) {
|
|
|
356
327
|
node = node;
|
|
357
328
|
let suffix = '';
|
|
358
329
|
let valueNode = node;
|
|
359
|
-
if (core.ItemNode.is(node.parent) &&
|
|
330
|
+
if (core.ItemNode.is(node.parent) && NbtListNode.is(node.parent.parent)) {
|
|
360
331
|
suffix = '[]';
|
|
361
332
|
valueNode = node.parent.parent;
|
|
362
333
|
}
|
|
@@ -364,13 +335,13 @@ function fieldValue(type, options) {
|
|
|
364
335
|
const structMcdocPath = valueNode.parent.key?.symbol?.parentSymbol?.path.join('::');
|
|
365
336
|
const key = valueNode.parent.key?.value;
|
|
366
337
|
const path = `${structMcdocPath}.${key}${suffix}`;
|
|
367
|
-
const parserName =
|
|
338
|
+
const parserName = getSpecialStringParser(path);
|
|
368
339
|
if (parserName) {
|
|
369
340
|
try {
|
|
370
341
|
const parser = ctx.meta.getParser(parserName);
|
|
371
342
|
const result = core.parseStringValue(parser, node.value, node.valueMap, ctx);
|
|
372
343
|
if (result !== core.Failure) {
|
|
373
|
-
|
|
344
|
+
node.children = [result];
|
|
374
345
|
result.parent = node;
|
|
375
346
|
}
|
|
376
347
|
}
|
|
@@ -390,7 +361,7 @@ function fieldValue(type, options) {
|
|
|
390
361
|
case 'union':
|
|
391
362
|
type = mcdoc.flattenUnionType(type);
|
|
392
363
|
if (type.members.length === 0) {
|
|
393
|
-
ctx.err.report(
|
|
364
|
+
ctx.err.report(localize('nbt.checker.compound.field.union-empty-members'), core.PairNode.is(node.parent)
|
|
394
365
|
? (node.parent.key ?? node.parent)
|
|
395
366
|
: node, 2 /* core.ErrorSeverity.Warning */);
|
|
396
367
|
}
|
|
@@ -401,5 +372,4 @@ function fieldValue(type, options) {
|
|
|
401
372
|
}
|
|
402
373
|
};
|
|
403
374
|
}
|
|
404
|
-
exports.fieldValue = fieldValue;
|
|
405
375
|
//# sourceMappingURL=index.js.map
|
package/lib/checker/mcdocUtil.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExpandableCompound = exports.getSpecialStringParser = exports.getEntityFromItem = exports.getBlocksFromItem = void 0;
|
|
4
1
|
const BlockItems = {
|
|
5
2
|
// Coral fans.
|
|
6
3
|
'minecraft:brain_coral_fan': [
|
|
@@ -112,11 +109,10 @@ const BlockItems = {
|
|
|
112
109
|
'minecraft:wheat',
|
|
113
110
|
],
|
|
114
111
|
};
|
|
115
|
-
function getBlocksFromItem(item) {
|
|
112
|
+
export function getBlocksFromItem(item) {
|
|
116
113
|
return BlockItems[item];
|
|
117
114
|
}
|
|
118
|
-
|
|
119
|
-
function getEntityFromItem(item) {
|
|
115
|
+
export function getEntityFromItem(item) {
|
|
120
116
|
if (item === 'minecraft:armor_stand') {
|
|
121
117
|
return item;
|
|
122
118
|
}
|
|
@@ -126,7 +122,6 @@ function getEntityFromItem(item) {
|
|
|
126
122
|
}
|
|
127
123
|
return undefined;
|
|
128
124
|
}
|
|
129
|
-
exports.getEntityFromItem = getEntityFromItem;
|
|
130
125
|
const SpecialStrings = {
|
|
131
126
|
'::minecraft::block::banner::Banner.CustomName': 'mcfunction:component',
|
|
132
127
|
'::minecraft::block::brewingstand::BrewingStand.CustomName': 'mcfunction:component',
|
|
@@ -148,10 +143,9 @@ const SpecialStrings = {
|
|
|
148
143
|
'::minecraft::item::book::WrittenBook.pages[]': 'mcfunction:component',
|
|
149
144
|
'::minecraft::item::ItemBase.CanDestroy[]': 'mcfunction:block_predicate',
|
|
150
145
|
};
|
|
151
|
-
function getSpecialStringParser(mcdocPath) {
|
|
146
|
+
export function getSpecialStringParser(mcdocPath) {
|
|
152
147
|
return SpecialStrings[mcdocPath];
|
|
153
148
|
}
|
|
154
|
-
exports.getSpecialStringParser = getSpecialStringParser;
|
|
155
149
|
const ExpandableCompounds = [
|
|
156
150
|
'::minecraft::item::ItemBase',
|
|
157
151
|
'::minecraft::entity::marker::Any',
|
|
@@ -161,8 +155,7 @@ const ExpandableCompounds = [
|
|
|
161
155
|
/**
|
|
162
156
|
* @param mcdocPath Path of the mcdoc compound definition.
|
|
163
157
|
*/
|
|
164
|
-
function isExpandableCompound(mcdocPath) {
|
|
158
|
+
export function isExpandableCompound(mcdocPath) {
|
|
165
159
|
return ExpandableCompounds.includes(mcdocPath);
|
|
166
160
|
}
|
|
167
|
-
exports.isExpandableCompound = isExpandableCompound;
|
|
168
161
|
//# sourceMappingURL=mcdocUtil.js.map
|
package/lib/colorizer/index.js
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.register = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
function register(meta) {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
export function register(meta) {
|
|
29
3
|
meta.registerColorizer('nbt:byte', core.colorizer.number);
|
|
30
4
|
meta.registerColorizer('nbt:short', core.colorizer.number);
|
|
31
5
|
meta.registerColorizer('nbt:int', core.colorizer.number);
|
|
@@ -33,5 +7,4 @@ function register(meta) {
|
|
|
33
7
|
meta.registerColorizer('nbt:float', core.colorizer.number);
|
|
34
8
|
meta.registerColorizer('nbt:double', core.colorizer.number);
|
|
35
9
|
}
|
|
36
|
-
exports.register = register;
|
|
37
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as core from '@spyglassmc/core';
|
|
2
|
-
export * as checker from './checker';
|
|
3
|
-
export * as colorizer from './colorizer';
|
|
4
|
-
export * from './node';
|
|
5
|
-
export * as parser from './parser';
|
|
6
|
-
export declare const initialize: core.
|
|
2
|
+
export * as checker from './checker/index.js';
|
|
3
|
+
export * as colorizer from './colorizer/index.js';
|
|
4
|
+
export * from './node/index.js';
|
|
5
|
+
export * as parser from './parser/index.js';
|
|
6
|
+
export declare const initialize: core.SyncProjectInitializer;
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.initialize = exports.parser = exports.colorizer = exports.checker = void 0;
|
|
30
|
-
const colorizer = __importStar(require("./colorizer"));
|
|
31
|
-
const parser = __importStar(require("./parser"));
|
|
32
|
-
exports.checker = __importStar(require("./checker"));
|
|
33
|
-
exports.colorizer = __importStar(require("./colorizer"));
|
|
34
|
-
__exportStar(require("./node"), exports);
|
|
35
|
-
exports.parser = __importStar(require("./parser"));
|
|
1
|
+
import * as colorizer from './colorizer/index.js';
|
|
2
|
+
import * as parser from './parser/index.js';
|
|
3
|
+
export * as checker from './checker/index.js';
|
|
4
|
+
export * as colorizer from './colorizer/index.js';
|
|
5
|
+
export * from './node/index.js';
|
|
6
|
+
export * as parser from './parser/index.js';
|
|
36
7
|
/* istanbul ignore next */
|
|
37
|
-
const initialize = ({ meta }) => {
|
|
8
|
+
export const initialize = ({ meta }) => {
|
|
38
9
|
meta.registerLanguage('nbt', {
|
|
39
10
|
extensions: ['.snbt'],
|
|
40
11
|
parser: parser.entry,
|
|
@@ -44,5 +15,4 @@ const initialize = ({ meta }) => {
|
|
|
44
15
|
meta.registerParser('nbt:path', parser.path);
|
|
45
16
|
colorizer.register(meta);
|
|
46
17
|
};
|
|
47
|
-
exports.initialize = initialize;
|
|
48
18
|
//# sourceMappingURL=index.js.map
|
package/lib/node/index.d.ts
CHANGED
|
@@ -67,8 +67,8 @@ export declare namespace NbtCollectionNode {
|
|
|
67
67
|
function is(node: core.AstNode | undefined): node is NbtCollectionNode;
|
|
68
68
|
}
|
|
69
69
|
export interface NbtListNode extends core.ListNode<NbtNode> {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
type: 'nbt:list';
|
|
71
|
+
valueType?: NbtNode['type'];
|
|
72
72
|
}
|
|
73
73
|
export declare namespace NbtListNode {
|
|
74
74
|
function is(node: core.AstNode | undefined): node is NbtListNode;
|
|
@@ -78,19 +78,19 @@ export declare namespace NbtPrimitiveArrayNode {
|
|
|
78
78
|
function is(node: core.AstNode | undefined): node is NbtPrimitiveArrayNode;
|
|
79
79
|
}
|
|
80
80
|
export interface NbtByteArrayNode extends core.ListNode<NbtByteNode> {
|
|
81
|
-
|
|
81
|
+
type: 'nbt:byte_array';
|
|
82
82
|
}
|
|
83
83
|
export declare namespace NbtByteArrayNode {
|
|
84
84
|
function is(node: core.AstNode | undefined): node is NbtByteArrayNode;
|
|
85
85
|
}
|
|
86
86
|
export interface NbtIntArrayNode extends core.ListNode<NbtIntNode> {
|
|
87
|
-
|
|
87
|
+
type: 'nbt:int_array';
|
|
88
88
|
}
|
|
89
89
|
export declare namespace NbtIntArrayNode {
|
|
90
90
|
function is(node: core.AstNode | undefined): node is NbtIntArrayNode;
|
|
91
91
|
}
|
|
92
92
|
export interface NbtLongArrayNode extends core.ListNode<NbtLongNode> {
|
|
93
|
-
|
|
93
|
+
type: 'nbt:long_array';
|
|
94
94
|
}
|
|
95
95
|
export declare namespace NbtLongArrayNode {
|
|
96
96
|
function is(node: core.AstNode | undefined): node is NbtLongArrayNode;
|
package/lib/node/index.js
CHANGED
|
@@ -1,188 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.NbtPathIndexNode = exports.NbtPathNode = exports.NbtLongArrayNode = exports.NbtIntArrayNode = exports.NbtByteArrayNode = exports.NbtPrimitiveArrayNode = exports.NbtListNode = exports.NbtCollectionNode = exports.NbtCompoundNode = exports.NbtDoubleNode = exports.NbtFloatNode = exports.NbtFloatAlikeNode = exports.NbtLongNode = exports.NbtIntNode = exports.NbtShortNode = exports.NbtByteNode = exports.NbtIntegerAlikeNode = exports.NbtNumberNode = exports.NbtPrimitiveNode = exports.NbtNode = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
var NbtNode;
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
export var NbtNode;
|
|
29
3
|
(function (NbtNode) {
|
|
30
4
|
/* istanbul ignore next */
|
|
31
5
|
function is(node) {
|
|
32
6
|
return NbtPrimitiveNode.is(node) || NbtCompoundNode.is(node) || NbtCollectionNode.is(node);
|
|
33
7
|
}
|
|
34
8
|
NbtNode.is = is;
|
|
35
|
-
})(NbtNode
|
|
36
|
-
var NbtPrimitiveNode;
|
|
9
|
+
})(NbtNode || (NbtNode = {}));
|
|
10
|
+
export var NbtPrimitiveNode;
|
|
37
11
|
(function (NbtPrimitiveNode) {
|
|
38
12
|
/* istanbul ignore next */
|
|
39
13
|
function is(node) {
|
|
40
14
|
return NbtNumberNode.is(node) || core.StringNode.is(node);
|
|
41
15
|
}
|
|
42
16
|
NbtPrimitiveNode.is = is;
|
|
43
|
-
})(NbtPrimitiveNode
|
|
44
|
-
var NbtNumberNode;
|
|
17
|
+
})(NbtPrimitiveNode || (NbtPrimitiveNode = {}));
|
|
18
|
+
export var NbtNumberNode;
|
|
45
19
|
(function (NbtNumberNode) {
|
|
46
20
|
/* istanbul ignore next */
|
|
47
21
|
function is(node) {
|
|
48
22
|
return NbtIntegerAlikeNode.is(node) || NbtFloatAlikeNode.is(node);
|
|
49
23
|
}
|
|
50
24
|
NbtNumberNode.is = is;
|
|
51
|
-
})(NbtNumberNode
|
|
52
|
-
var NbtIntegerAlikeNode;
|
|
25
|
+
})(NbtNumberNode || (NbtNumberNode = {}));
|
|
26
|
+
export var NbtIntegerAlikeNode;
|
|
53
27
|
(function (NbtIntegerAlikeNode) {
|
|
54
28
|
/* istanbul ignore next */
|
|
55
29
|
function is(node) {
|
|
56
30
|
return NbtByteNode.is(node) || NbtShortNode.is(node) || NbtIntNode.is(node) || NbtLongNode.is(node);
|
|
57
31
|
}
|
|
58
32
|
NbtIntegerAlikeNode.is = is;
|
|
59
|
-
})(NbtIntegerAlikeNode
|
|
60
|
-
var NbtByteNode;
|
|
33
|
+
})(NbtIntegerAlikeNode || (NbtIntegerAlikeNode = {}));
|
|
34
|
+
export var NbtByteNode;
|
|
61
35
|
(function (NbtByteNode) {
|
|
62
36
|
/* istanbul ignore next */
|
|
63
37
|
function is(node) {
|
|
64
38
|
return node?.type === 'nbt:byte';
|
|
65
39
|
}
|
|
66
40
|
NbtByteNode.is = is;
|
|
67
|
-
})(NbtByteNode
|
|
68
|
-
var NbtShortNode;
|
|
41
|
+
})(NbtByteNode || (NbtByteNode = {}));
|
|
42
|
+
export var NbtShortNode;
|
|
69
43
|
(function (NbtShortNode) {
|
|
70
44
|
/* istanbul ignore next */
|
|
71
45
|
function is(node) {
|
|
72
46
|
return node?.type === 'nbt:short';
|
|
73
47
|
}
|
|
74
48
|
NbtShortNode.is = is;
|
|
75
|
-
})(NbtShortNode
|
|
76
|
-
var NbtIntNode;
|
|
49
|
+
})(NbtShortNode || (NbtShortNode = {}));
|
|
50
|
+
export var NbtIntNode;
|
|
77
51
|
(function (NbtIntNode) {
|
|
78
52
|
/* istanbul ignore next */
|
|
79
53
|
function is(node) {
|
|
80
54
|
return node?.type === 'nbt:int';
|
|
81
55
|
}
|
|
82
56
|
NbtIntNode.is = is;
|
|
83
|
-
})(NbtIntNode
|
|
84
|
-
var NbtLongNode;
|
|
57
|
+
})(NbtIntNode || (NbtIntNode = {}));
|
|
58
|
+
export var NbtLongNode;
|
|
85
59
|
(function (NbtLongNode) {
|
|
86
60
|
/* istanbul ignore next */
|
|
87
61
|
function is(node) {
|
|
88
62
|
return node?.type === 'nbt:long';
|
|
89
63
|
}
|
|
90
64
|
NbtLongNode.is = is;
|
|
91
|
-
})(NbtLongNode
|
|
92
|
-
var NbtFloatAlikeNode;
|
|
65
|
+
})(NbtLongNode || (NbtLongNode = {}));
|
|
66
|
+
export var NbtFloatAlikeNode;
|
|
93
67
|
(function (NbtFloatAlikeNode) {
|
|
94
68
|
/* istanbul ignore next */
|
|
95
69
|
function is(node) {
|
|
96
70
|
return NbtFloatNode.is(node) || NbtDoubleNode.is(node);
|
|
97
71
|
}
|
|
98
72
|
NbtFloatAlikeNode.is = is;
|
|
99
|
-
})(NbtFloatAlikeNode
|
|
100
|
-
var NbtFloatNode;
|
|
73
|
+
})(NbtFloatAlikeNode || (NbtFloatAlikeNode = {}));
|
|
74
|
+
export var NbtFloatNode;
|
|
101
75
|
(function (NbtFloatNode) {
|
|
102
76
|
/* istanbul ignore next */
|
|
103
77
|
function is(node) {
|
|
104
78
|
return node?.type === 'nbt:float';
|
|
105
79
|
}
|
|
106
80
|
NbtFloatNode.is = is;
|
|
107
|
-
})(NbtFloatNode
|
|
108
|
-
var NbtDoubleNode;
|
|
81
|
+
})(NbtFloatNode || (NbtFloatNode = {}));
|
|
82
|
+
export var NbtDoubleNode;
|
|
109
83
|
(function (NbtDoubleNode) {
|
|
110
84
|
/* istanbul ignore next */
|
|
111
85
|
function is(node) {
|
|
112
86
|
return node?.type === 'nbt:double';
|
|
113
87
|
}
|
|
114
88
|
NbtDoubleNode.is = is;
|
|
115
|
-
})(NbtDoubleNode
|
|
116
|
-
var NbtCompoundNode;
|
|
89
|
+
})(NbtDoubleNode || (NbtDoubleNode = {}));
|
|
90
|
+
export var NbtCompoundNode;
|
|
117
91
|
(function (NbtCompoundNode) {
|
|
118
92
|
/* istanbul ignore next */
|
|
119
93
|
function is(node) {
|
|
120
94
|
return node?.type === 'nbt:compound';
|
|
121
95
|
}
|
|
122
96
|
NbtCompoundNode.is = is;
|
|
123
|
-
})(NbtCompoundNode
|
|
124
|
-
var NbtCollectionNode;
|
|
97
|
+
})(NbtCompoundNode || (NbtCompoundNode = {}));
|
|
98
|
+
export var NbtCollectionNode;
|
|
125
99
|
(function (NbtCollectionNode) {
|
|
126
100
|
/* istanbul ignore next */
|
|
127
101
|
function is(node) {
|
|
128
102
|
return NbtListNode.is(node) || NbtPrimitiveArrayNode.is(node);
|
|
129
103
|
}
|
|
130
104
|
NbtCollectionNode.is = is;
|
|
131
|
-
})(NbtCollectionNode
|
|
132
|
-
var NbtListNode;
|
|
105
|
+
})(NbtCollectionNode || (NbtCollectionNode = {}));
|
|
106
|
+
export var NbtListNode;
|
|
133
107
|
(function (NbtListNode) {
|
|
134
108
|
/* istanbul ignore next */
|
|
135
109
|
function is(node) {
|
|
136
110
|
return node?.type === 'nbt:list';
|
|
137
111
|
}
|
|
138
112
|
NbtListNode.is = is;
|
|
139
|
-
})(NbtListNode
|
|
140
|
-
var NbtPrimitiveArrayNode;
|
|
113
|
+
})(NbtListNode || (NbtListNode = {}));
|
|
114
|
+
export var NbtPrimitiveArrayNode;
|
|
141
115
|
(function (NbtPrimitiveArrayNode) {
|
|
142
116
|
/* istanbul ignore next */
|
|
143
117
|
function is(node) {
|
|
144
118
|
return NbtByteArrayNode.is(node) || NbtIntArrayNode.is(node) || NbtLongArrayNode.is(node);
|
|
145
119
|
}
|
|
146
120
|
NbtPrimitiveArrayNode.is = is;
|
|
147
|
-
})(NbtPrimitiveArrayNode
|
|
148
|
-
var NbtByteArrayNode;
|
|
121
|
+
})(NbtPrimitiveArrayNode || (NbtPrimitiveArrayNode = {}));
|
|
122
|
+
export var NbtByteArrayNode;
|
|
149
123
|
(function (NbtByteArrayNode) {
|
|
150
124
|
/* istanbul ignore next */
|
|
151
125
|
function is(node) {
|
|
152
126
|
return node?.type === 'nbt:byte_array';
|
|
153
127
|
}
|
|
154
128
|
NbtByteArrayNode.is = is;
|
|
155
|
-
})(NbtByteArrayNode
|
|
156
|
-
var NbtIntArrayNode;
|
|
129
|
+
})(NbtByteArrayNode || (NbtByteArrayNode = {}));
|
|
130
|
+
export var NbtIntArrayNode;
|
|
157
131
|
(function (NbtIntArrayNode) {
|
|
158
132
|
/* istanbul ignore next */
|
|
159
133
|
function is(node) {
|
|
160
134
|
return node?.type === 'nbt:int_array';
|
|
161
135
|
}
|
|
162
136
|
NbtIntArrayNode.is = is;
|
|
163
|
-
})(NbtIntArrayNode
|
|
164
|
-
var NbtLongArrayNode;
|
|
137
|
+
})(NbtIntArrayNode || (NbtIntArrayNode = {}));
|
|
138
|
+
export var NbtLongArrayNode;
|
|
165
139
|
(function (NbtLongArrayNode) {
|
|
166
140
|
/* istanbul ignore next */
|
|
167
141
|
function is(node) {
|
|
168
142
|
return node?.type === 'nbt:long_array';
|
|
169
143
|
}
|
|
170
144
|
NbtLongArrayNode.is = is;
|
|
171
|
-
})(NbtLongArrayNode
|
|
172
|
-
var NbtPathNode;
|
|
145
|
+
})(NbtLongArrayNode || (NbtLongArrayNode = {}));
|
|
146
|
+
export var NbtPathNode;
|
|
173
147
|
(function (NbtPathNode) {
|
|
174
148
|
/* istanbul ignore next */
|
|
175
149
|
function is(node) {
|
|
176
150
|
return node?.type === 'nbt:path';
|
|
177
151
|
}
|
|
178
152
|
NbtPathNode.is = is;
|
|
179
|
-
})(NbtPathNode
|
|
180
|
-
var NbtPathIndexNode;
|
|
153
|
+
})(NbtPathNode || (NbtPathNode = {}));
|
|
154
|
+
export var NbtPathIndexNode;
|
|
181
155
|
(function (NbtPathIndexNode) {
|
|
182
156
|
/* istanbul ignore next */
|
|
183
157
|
function is(node) {
|
|
184
158
|
return node?.type === 'nbt:path/index';
|
|
185
159
|
}
|
|
186
160
|
NbtPathIndexNode.is = is;
|
|
187
|
-
})(NbtPathIndexNode
|
|
161
|
+
})(NbtPathIndexNode || (NbtPathIndexNode = {}));
|
|
188
162
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { NbtByteArrayNode, NbtIntArrayNode, NbtListNode, NbtLongArrayNode } from '../node';
|
|
2
|
+
import type { NbtByteArrayNode, NbtIntArrayNode, NbtListNode, NbtLongArrayNode } from '../node/index.js';
|
|
3
3
|
export declare const list: core.Parser<NbtListNode>;
|
|
4
4
|
export declare const byteArray: core.Parser<NbtByteArrayNode>;
|
|
5
5
|
export declare const intArray: core.Parser<NbtIntArrayNode>;
|
package/lib/parser/collection.js
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.longArray = exports.intArray = exports.byteArray = exports.list = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
29
|
-
const util_1 = require("../util");
|
|
30
|
-
const entry_1 = require("./entry");
|
|
31
|
-
const primitive_1 = require("./primitive");
|
|
32
|
-
const list = (src, ctx) => {
|
|
33
|
-
const parser = core.list({ start: '[', value: entry_1.entry, sep: ',', trailingSep: false, end: ']' });
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localize } from '@spyglassmc/locales';
|
|
3
|
+
import { localizeTag } from '../util.js';
|
|
4
|
+
import { entry } from './entry.js';
|
|
5
|
+
import { primitive } from './primitive.js';
|
|
6
|
+
export const list = (src, ctx) => {
|
|
7
|
+
const parser = core.list({ start: '[', value: entry, sep: ',', trailingSep: false, end: ']' });
|
|
34
8
|
const ans = parser(src, ctx);
|
|
35
9
|
ans.type = 'nbt:list';
|
|
36
10
|
ans.valueType = ans.children[0]?.value?.type;
|
|
@@ -38,50 +12,46 @@ const list = (src, ctx) => {
|
|
|
38
12
|
if (ans.valueType) {
|
|
39
13
|
for (const { value } of ans.children) {
|
|
40
14
|
if (value && value.type !== ans.valueType) {
|
|
41
|
-
ctx.err.report(
|
|
15
|
+
ctx.err.report(localize('expected-got', localizeTag(ans.valueType), localizeTag(value.type)), value);
|
|
42
16
|
}
|
|
43
17
|
}
|
|
44
18
|
}
|
|
45
19
|
return ans;
|
|
46
20
|
};
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const parser = core.list({ start: '[B;', value: primitive_1.primitive, sep: ',', trailingSep: false, end: ']' });
|
|
21
|
+
export const byteArray = (src, ctx) => {
|
|
22
|
+
const parser = core.list({ start: '[B;', value: primitive, sep: ',', trailingSep: false, end: ']' });
|
|
50
23
|
const ans = parser(src, ctx);
|
|
51
24
|
ans.type = 'nbt:byte_array';
|
|
52
25
|
// Check if every element is of the required type.
|
|
53
26
|
for (const { value } of ans.children) {
|
|
54
27
|
if (value && value.type !== 'nbt:byte') {
|
|
55
|
-
ctx.err.report(
|
|
28
|
+
ctx.err.report(localize('expected-got', localize('nbt.node.byte'), localizeTag(value.type)), value);
|
|
56
29
|
}
|
|
57
30
|
}
|
|
58
31
|
return ans;
|
|
59
32
|
};
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const parser = core.list({ start: '[I;', value: primitive_1.primitive, sep: ',', trailingSep: false, end: ']' });
|
|
33
|
+
export const intArray = (src, ctx) => {
|
|
34
|
+
const parser = core.list({ start: '[I;', value: primitive, sep: ',', trailingSep: false, end: ']' });
|
|
63
35
|
const ans = parser(src, ctx);
|
|
64
36
|
ans.type = 'nbt:int_array';
|
|
65
37
|
// Check if every element is of the required type.
|
|
66
38
|
for (const { value } of ans.children) {
|
|
67
39
|
if (value && value.type !== 'nbt:int') {
|
|
68
|
-
ctx.err.report(
|
|
40
|
+
ctx.err.report(localize('expected-got', localize('nbt.node.int'), localizeTag(value.type)), value);
|
|
69
41
|
}
|
|
70
42
|
}
|
|
71
43
|
return ans;
|
|
72
44
|
};
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const parser = core.list({ start: '[L;', value: primitive_1.primitive, sep: ',', trailingSep: false, end: ']' });
|
|
45
|
+
export const longArray = (src, ctx) => {
|
|
46
|
+
const parser = core.list({ start: '[L;', value: primitive, sep: ',', trailingSep: false, end: ']' });
|
|
76
47
|
const ans = parser(src, ctx);
|
|
77
48
|
ans.type = 'nbt:long_array';
|
|
78
49
|
// Check if every element is of the required type.
|
|
79
50
|
for (const { value } of ans.children) {
|
|
80
51
|
if (value && value.type !== 'nbt:long') {
|
|
81
|
-
ctx.err.report(
|
|
52
|
+
ctx.err.report(localize('expected-got', localize('nbt.node.long'), localizeTag(value.type)), value);
|
|
82
53
|
}
|
|
83
54
|
}
|
|
84
55
|
return ans;
|
|
85
56
|
};
|
|
86
|
-
exports.longArray = longArray;
|
|
87
57
|
//# sourceMappingURL=collection.js.map
|
package/lib/parser/compound.d.ts
CHANGED
package/lib/parser/compound.js
CHANGED
|
@@ -1,43 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.compound = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const entry_1 = require("./entry");
|
|
29
|
-
const compound = (src, ctx) => {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { entry } from './entry.js';
|
|
3
|
+
export const compound = (src, ctx) => {
|
|
30
4
|
return core.setType('nbt:compound', core.record({
|
|
31
5
|
start: '{',
|
|
32
6
|
pair: {
|
|
33
7
|
key: core.failOnEmpty(core.string({ ...core.BrigadierStringOptions, colorTokenType: 'property' })),
|
|
34
8
|
sep: ':',
|
|
35
|
-
value:
|
|
9
|
+
value: entry,
|
|
36
10
|
end: ',',
|
|
37
11
|
trailingEnd: false,
|
|
38
12
|
},
|
|
39
13
|
end: '}',
|
|
40
14
|
}))(src, ctx);
|
|
41
15
|
};
|
|
42
|
-
exports.compound = compound;
|
|
43
16
|
//# sourceMappingURL=compound.js.map
|
package/lib/parser/entry.d.ts
CHANGED
package/lib/parser/entry.js
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.entry = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const collection_1 = require("./collection");
|
|
29
|
-
const compound_1 = require("./compound");
|
|
30
|
-
const primitive_1 = require("./primitive");
|
|
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 },
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { byteArray, intArray, list, longArray } from './collection.js';
|
|
3
|
+
import { compound } from './compound.js';
|
|
4
|
+
import { primitive } from './primitive.js';
|
|
5
|
+
export const entry = (src, ctx) => core.failOnEmpty(core.select([
|
|
6
|
+
{ predicate: src => src.tryPeek('[B;'), parser: byteArray },
|
|
7
|
+
{ predicate: src => src.tryPeek('[I;'), parser: intArray },
|
|
8
|
+
{ predicate: src => src.tryPeek('[L;'), parser: longArray },
|
|
9
|
+
{ predicate: src => src.tryPeek('['), parser: list },
|
|
10
|
+
{ predicate: src => src.tryPeek('{'), parser: compound },
|
|
11
|
+
{ parser: primitive },
|
|
38
12
|
]))(src, ctx);
|
|
39
|
-
exports.entry = entry;
|
|
40
13
|
//# sourceMappingURL=entry.js.map
|
package/lib/parser/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './collection';
|
|
2
|
-
export * from './compound';
|
|
3
|
-
export * from './entry';
|
|
4
|
-
export * from './path';
|
|
5
|
-
export * from './primitive';
|
|
1
|
+
export * from './collection.js';
|
|
2
|
+
export * from './compound.js';
|
|
3
|
+
export * from './entry.js';
|
|
4
|
+
export * from './path.js';
|
|
5
|
+
export * from './primitive.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/parser/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./collection"), exports);
|
|
18
|
-
__exportStar(require("./compound"), exports);
|
|
19
|
-
__exportStar(require("./entry"), exports);
|
|
20
|
-
__exportStar(require("./path"), exports);
|
|
21
|
-
__exportStar(require("./primitive"), exports);
|
|
1
|
+
export * from './collection.js';
|
|
2
|
+
export * from './compound.js';
|
|
3
|
+
export * from './entry.js';
|
|
4
|
+
export * from './path.js';
|
|
5
|
+
export * from './primitive.js';
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/lib/parser/path.d.ts
CHANGED
package/lib/parser/path.js
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.path = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const lib_1 = require("../../../locales/lib");
|
|
29
|
-
const compound_1 = require("./compound");
|
|
30
|
-
const path = (src, ctx) => {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { arrayToMessage, localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
import { compound } from './compound.js';
|
|
4
|
+
export const path = (src, ctx) => {
|
|
31
5
|
const ans = {
|
|
32
6
|
type: 'nbt:path',
|
|
33
7
|
children: [],
|
|
@@ -38,7 +12,7 @@ const path = (src, ctx) => {
|
|
|
38
12
|
let cursor;
|
|
39
13
|
while (cursor !== src.cursor) {
|
|
40
14
|
if (!expectedParts.includes(currentPart)) {
|
|
41
|
-
ctx.err.report(
|
|
15
|
+
ctx.err.report(localize('expected-got', arrayToMessage(expectedParts.map(localizePart), false, 'or'), localizePart(currentPart)), src);
|
|
42
16
|
}
|
|
43
17
|
if (currentPart === 'end') {
|
|
44
18
|
break;
|
|
@@ -50,9 +24,8 @@ const path = (src, ctx) => {
|
|
|
50
24
|
ans.range.end = src.cursor;
|
|
51
25
|
return ans;
|
|
52
26
|
};
|
|
53
|
-
exports.path = path;
|
|
54
27
|
const filter = (children, src, ctx) => {
|
|
55
|
-
children.push(
|
|
28
|
+
children.push(compound(src, ctx));
|
|
56
29
|
return src.trySkip('.') ? ['key'] : ['end'];
|
|
57
30
|
};
|
|
58
31
|
const index = (children, src, ctx) => {
|
|
@@ -67,14 +40,14 @@ const index = (children, src, ctx) => {
|
|
|
67
40
|
src.skipSpace();
|
|
68
41
|
const c = src.peek();
|
|
69
42
|
if (c === '{') {
|
|
70
|
-
node.children = [
|
|
43
|
+
node.children = [compound(src, ctx)];
|
|
71
44
|
}
|
|
72
45
|
else if (c !== ']') {
|
|
73
46
|
node.children = [core.integer({ pattern: /^-?\d+$/ })(src, ctx)];
|
|
74
47
|
}
|
|
75
48
|
src.skipSpace();
|
|
76
49
|
if (!src.trySkip(']')) {
|
|
77
|
-
ctx.err.report(
|
|
50
|
+
ctx.err.report(localize('expected-got', localeQuote(']'), localeQuote(src.peek())), src);
|
|
78
51
|
}
|
|
79
52
|
node.range.end = src.cursor;
|
|
80
53
|
children.push(node);
|
|
@@ -111,7 +84,7 @@ function nextPart(src) {
|
|
|
111
84
|
}
|
|
112
85
|
}
|
|
113
86
|
function localizePart(part) {
|
|
114
|
-
return
|
|
87
|
+
return localize(`nbt.node.path.${part}`);
|
|
115
88
|
}
|
|
116
89
|
const PartParsers = {
|
|
117
90
|
filter,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { NbtPrimitiveNode } from '../node';
|
|
2
|
+
import type { NbtPrimitiveNode } from '../node/index.js';
|
|
3
3
|
export declare const string: core.InfallibleParser<core.StringNode>;
|
|
4
4
|
export declare const primitive: core.InfallibleParser<NbtPrimitiveNode>;
|
|
5
5
|
//# sourceMappingURL=primitive.d.ts.map
|
package/lib/parser/primitive.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.primitive = exports.string = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
29
|
-
const util_1 = require("../util");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localize } from '@spyglassmc/locales';
|
|
3
|
+
import { localizeTag } from '../util.js';
|
|
30
4
|
const FloatMaximum = (2 - (2 ** -23)) * (2 ** 127);
|
|
31
5
|
const NumeralPatterns = [
|
|
32
6
|
{ pattern: /^[-+]?(?:0|[1-9][0-9]*)b$/i, type: 'nbt:byte', hasSuffix: true, group: 2 /* Group.IntegerAlike */, min: -128, max: 127 },
|
|
@@ -39,12 +13,12 @@ const NumeralPatterns = [
|
|
|
39
13
|
{ pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Group.Boolean */ },
|
|
40
14
|
{ pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Group.Boolean */ },
|
|
41
15
|
];
|
|
42
|
-
|
|
43
|
-
const primitive = (src, ctx) => {
|
|
16
|
+
export const string = core.brigadierString;
|
|
17
|
+
export const primitive = (src, ctx) => {
|
|
44
18
|
if (core.Source.isBrigadierQuote(src.peek())) {
|
|
45
|
-
return
|
|
19
|
+
return string(src, ctx);
|
|
46
20
|
}
|
|
47
|
-
const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(
|
|
21
|
+
const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(string, src, ctx);
|
|
48
22
|
for (const e of NumeralPatterns) {
|
|
49
23
|
if (e.pattern.test(unquotedResult.value)) {
|
|
50
24
|
if (e.group === 0 /* Group.Boolean */) {
|
|
@@ -67,7 +41,7 @@ const primitive = (src, ctx) => {
|
|
|
67
41
|
: core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
|
|
68
42
|
const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
|
|
69
43
|
if (isOutOfRange) {
|
|
70
|
-
ctx.err.report(
|
|
44
|
+
ctx.err.report(localize('nbt.parser.number.out-of-range', localizeTag(e.type), localize('nbt.node.string'), e.min, e.max), unquotedResult, 2 /* core.ErrorSeverity.Warning */);
|
|
71
45
|
break;
|
|
72
46
|
}
|
|
73
47
|
updateNumeral();
|
|
@@ -84,5 +58,4 @@ const primitive = (src, ctx) => {
|
|
|
84
58
|
updateUnquoted();
|
|
85
59
|
return unquotedResult;
|
|
86
60
|
};
|
|
87
|
-
exports.primitive = primitive;
|
|
88
61
|
//# sourceMappingURL=primitive.js.map
|
package/lib/util.d.ts
CHANGED
package/lib/util.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
function localizeTag(type) {
|
|
6
|
-
return (0, locales_1.localize)(`nbt.node.${type.replace(/^nbt:/, '')}`);
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
export function localizeTag(type) {
|
|
3
|
+
return localize(`nbt.node.${type.replace(/^nbt:/, '')}`);
|
|
7
4
|
}
|
|
8
|
-
exports.localizeTag = localizeTag;
|
|
9
5
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/nbt",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "lib/index.js",
|
|
5
6
|
"types": "lib/index.d.ts",
|
|
6
7
|
"author": "SPGoding",
|
|
@@ -24,8 +25,8 @@
|
|
|
24
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@spyglassmc/core": "0.
|
|
28
|
-
"@spyglassmc/locales": "0.
|
|
29
|
-
"@spyglassmc/mcdoc": "0.
|
|
28
|
+
"@spyglassmc/core": "0.4.0",
|
|
29
|
+
"@spyglassmc/locales": "0.3.0",
|
|
30
|
+
"@spyglassmc/mcdoc": "0.3.1"
|
|
30
31
|
}
|
|
31
32
|
}
|