@spyglassmc/nbt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/lib/checker/index.d.ts +40 -0
- package/lib/checker/index.js +593 -0
- package/lib/checker/nbtdocUtil.d.ts +9 -0
- package/lib/checker/nbtdocUtil.js +167 -0
- package/lib/colorizer/index.d.ts +3 -0
- package/lib/colorizer/index.js +33 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +44 -0
- package/lib/node/index.d.ts +113 -0
- package/lib/node/index.js +184 -0
- package/lib/parser/collection.d.ts +7 -0
- package/lib/parser/collection.js +83 -0
- package/lib/parser/compound.d.ts +4 -0
- package/lib/parser/compound.js +39 -0
- package/lib/parser/entry.d.ts +4 -0
- package/lib/parser/entry.js +36 -0
- package/lib/parser/index.d.ts +6 -0
- package/lib/parser/index.js +18 -0
- package/lib/parser/path.d.ts +4 -0
- package/lib/parser/path.js +117 -0
- package/lib/parser/primitive.d.ts +5 -0
- package/lib/parser/primitive.js +84 -0
- package/lib/util.d.ts +3 -0
- package/lib/util.js +9 -0
- package/package.json +31 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.compound = void 0;
|
|
23
|
+
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
+
const entry_1 = require("./entry");
|
|
25
|
+
const compound = (src, ctx) => {
|
|
26
|
+
return core.setType('nbt:compound', core.record({
|
|
27
|
+
start: '{',
|
|
28
|
+
pair: {
|
|
29
|
+
key: core.failOnEmpty(core.string({ ...core.BrigadierStringOptions, colorTokenType: 'property' })),
|
|
30
|
+
sep: ':',
|
|
31
|
+
value: entry_1.entry,
|
|
32
|
+
end: ',',
|
|
33
|
+
trailingEnd: false,
|
|
34
|
+
},
|
|
35
|
+
end: '}',
|
|
36
|
+
}))(src, ctx);
|
|
37
|
+
};
|
|
38
|
+
exports.compound = compound;
|
|
39
|
+
//# sourceMappingURL=compound.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.entry = void 0;
|
|
23
|
+
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
+
const collection_1 = require("./collection");
|
|
25
|
+
const compound_1 = require("./compound");
|
|
26
|
+
const primitive_1 = require("./primitive");
|
|
27
|
+
const entry = (src, ctx) => core.failOnEmpty(core.any([
|
|
28
|
+
primitive_1.primitive,
|
|
29
|
+
compound_1.compound,
|
|
30
|
+
collection_1.list,
|
|
31
|
+
collection_1.byteArray,
|
|
32
|
+
collection_1.intArray,
|
|
33
|
+
collection_1.longArray,
|
|
34
|
+
]))(src, ctx);
|
|
35
|
+
exports.entry = entry;
|
|
36
|
+
//# sourceMappingURL=entry.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./collection"), exports);
|
|
14
|
+
__exportStar(require("./compound"), exports);
|
|
15
|
+
__exportStar(require("./entry"), exports);
|
|
16
|
+
__exportStar(require("./path"), exports);
|
|
17
|
+
__exportStar(require("./primitive"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.path = void 0;
|
|
23
|
+
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
+
const lib_1 = require("../../../locales/lib");
|
|
25
|
+
const compound_1 = require("./compound");
|
|
26
|
+
const path = (src, ctx) => {
|
|
27
|
+
const ans = {
|
|
28
|
+
type: 'nbt:path',
|
|
29
|
+
children: [],
|
|
30
|
+
range: core.Range.create(src),
|
|
31
|
+
};
|
|
32
|
+
let expectedParts = ['filter', 'key'];
|
|
33
|
+
let currentPart = nextPart(src);
|
|
34
|
+
let cursor;
|
|
35
|
+
while (cursor !== src.cursor) {
|
|
36
|
+
if (!expectedParts.includes(currentPart)) {
|
|
37
|
+
ctx.err.report((0, lib_1.localize)('expected-got', (0, lib_1.arrayToMessage)(expectedParts.map(localizePart), false, 'or'), localizePart(currentPart)), src);
|
|
38
|
+
}
|
|
39
|
+
if (currentPart === 'end') {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
cursor = src.cursor;
|
|
43
|
+
expectedParts = PartParsers[currentPart](ans.children, src, ctx);
|
|
44
|
+
currentPart = nextPart(src);
|
|
45
|
+
}
|
|
46
|
+
ans.range.end = src.cursor;
|
|
47
|
+
return ans;
|
|
48
|
+
};
|
|
49
|
+
exports.path = path;
|
|
50
|
+
const filter = (children, src, ctx) => {
|
|
51
|
+
children.push((0, compound_1.compound)(src, ctx));
|
|
52
|
+
return src.trySkip('.') ? ['key'] : ['end'];
|
|
53
|
+
};
|
|
54
|
+
const index = (children, src, ctx) => {
|
|
55
|
+
const node = {
|
|
56
|
+
type: 'nbt:path/index',
|
|
57
|
+
children: undefined,
|
|
58
|
+
range: core.Range.create(src),
|
|
59
|
+
};
|
|
60
|
+
if (!src.trySkip('[')) {
|
|
61
|
+
throw new Error(`NBT path index parser called at illegal position: “${src.peek()}” at ${src.cursor}`);
|
|
62
|
+
}
|
|
63
|
+
src.skipSpace();
|
|
64
|
+
const c = src.peek();
|
|
65
|
+
if (c === '{') {
|
|
66
|
+
node.children = [(0, compound_1.compound)(src, ctx)];
|
|
67
|
+
}
|
|
68
|
+
else if (c !== ']') {
|
|
69
|
+
node.children = [core.integer({ pattern: /^-?\d+$/ })(src, ctx)];
|
|
70
|
+
}
|
|
71
|
+
src.skipSpace();
|
|
72
|
+
if (!src.trySkip(']')) {
|
|
73
|
+
ctx.err.report((0, lib_1.localize)('expected-got', (0, lib_1.localeQuote)(']'), (0, lib_1.localeQuote)(src.peek())), src);
|
|
74
|
+
}
|
|
75
|
+
node.range.end = src.cursor;
|
|
76
|
+
children.push(node);
|
|
77
|
+
return src.trySkip('.')
|
|
78
|
+
? ['index', 'key']
|
|
79
|
+
: ['end', 'index'];
|
|
80
|
+
};
|
|
81
|
+
const key = (children, src, ctx) => {
|
|
82
|
+
const node = core.string({
|
|
83
|
+
colorTokenType: 'property',
|
|
84
|
+
escapable: {},
|
|
85
|
+
// No single quotes: https://bugs.mojang.com/browse/MC-175504
|
|
86
|
+
quotes: ['"'],
|
|
87
|
+
unquotable: { blockList: new Set(['\n', '\r', '\t', ' ', '"', '[', ']', '.', '{', '}']) },
|
|
88
|
+
})(src, ctx);
|
|
89
|
+
children.push(node);
|
|
90
|
+
return src.trySkip('.')
|
|
91
|
+
? ['index', 'key']
|
|
92
|
+
: ['end', 'filter', 'index'];
|
|
93
|
+
};
|
|
94
|
+
function nextPart(src) {
|
|
95
|
+
switch (src.peek()) {
|
|
96
|
+
case '':
|
|
97
|
+
case ' ':
|
|
98
|
+
case '\n':
|
|
99
|
+
case '\r':
|
|
100
|
+
return 'end';
|
|
101
|
+
case '{':
|
|
102
|
+
return 'filter';
|
|
103
|
+
case '[':
|
|
104
|
+
return 'index';
|
|
105
|
+
default:
|
|
106
|
+
return 'key';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function localizePart(part) {
|
|
110
|
+
return (0, lib_1.localize)(`nbt.node.path.${part}`);
|
|
111
|
+
}
|
|
112
|
+
const PartParsers = {
|
|
113
|
+
filter,
|
|
114
|
+
index,
|
|
115
|
+
key,
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import type { NbtPrimitiveNode } from '../node';
|
|
3
|
+
export declare const string: core.InfallibleParser<core.StringNode>;
|
|
4
|
+
export declare const primitive: core.InfallibleParser<NbtPrimitiveNode>;
|
|
5
|
+
//# sourceMappingURL=primitive.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.primitive = exports.string = void 0;
|
|
23
|
+
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
+
const locales_1 = require("@spyglassmc/locales");
|
|
25
|
+
const util_1 = require("../util");
|
|
26
|
+
const FloatMaximum = (2 - (2 ** -23)) * (2 ** 127);
|
|
27
|
+
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 */ },
|
|
37
|
+
];
|
|
38
|
+
exports.string = core.brigadierString;
|
|
39
|
+
const primitive = (src, ctx) => {
|
|
40
|
+
if (core.Source.isBrigadierQuote(src.peek())) {
|
|
41
|
+
return (0, exports.string)(src, ctx);
|
|
42
|
+
}
|
|
43
|
+
const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(exports.string, src, ctx);
|
|
44
|
+
for (const e of NumeralPatterns) {
|
|
45
|
+
if (e.pattern.test(unquotedResult.value)) {
|
|
46
|
+
if (e.group === 0 /* Boolean */) {
|
|
47
|
+
const ans = {
|
|
48
|
+
type: 'nbt:byte',
|
|
49
|
+
range: unquotedResult.range,
|
|
50
|
+
value: e.value,
|
|
51
|
+
};
|
|
52
|
+
updateUnquoted();
|
|
53
|
+
return ans;
|
|
54
|
+
}
|
|
55
|
+
let isOutOfRange = false;
|
|
56
|
+
const onOutOfRange = () => isOutOfRange = true;
|
|
57
|
+
const numeralParser = e.group === 2 /* IntegerAlike */
|
|
58
|
+
// As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
|
|
59
|
+
// it again here in the parser, therefore we just pass in a simple /./ regex.
|
|
60
|
+
? core.integer({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
|
|
61
|
+
: e.group === 3 /* LongAlike */
|
|
62
|
+
? core.long({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
|
|
63
|
+
: core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
|
|
64
|
+
const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
|
|
65
|
+
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 */);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
updateNumeral();
|
|
70
|
+
if (e.hasSuffix) {
|
|
71
|
+
src.skip();
|
|
72
|
+
numeralResult.range.end++;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
...numeralResult,
|
|
76
|
+
type: e.type,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
updateUnquoted();
|
|
81
|
+
return unquotedResult;
|
|
82
|
+
};
|
|
83
|
+
exports.primitive = primitive;
|
|
84
|
+
//# sourceMappingURL=primitive.js.map
|
package/lib/util.d.ts
ADDED
package/lib/util.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.localizeTag = void 0;
|
|
4
|
+
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
+
function localizeTag(type) {
|
|
6
|
+
return (0, locales_1.localize)(`nbt.node.${type.replace(/^nbt:/, '')}`);
|
|
7
|
+
}
|
|
8
|
+
exports.localizeTag = localizeTag;
|
|
9
|
+
//# sourceMappingURL=util.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spyglassmc/nbt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"types": "lib/index.d.ts",
|
|
6
|
+
"author": "SPGoding",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"directories": {
|
|
9
|
+
"test": "test/"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"release": "npm publish",
|
|
13
|
+
"release:dry": "npm publish --dry-run"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/SpyglassMC/Spyglass.git"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://spyglassmc.com",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@spyglassmc/core": "0.1.0",
|
|
28
|
+
"@spyglassmc/locales": "0.1.0",
|
|
29
|
+
"@spyglassmc/nbtdoc": "0.1.0"
|
|
30
|
+
}
|
|
31
|
+
}
|