@spyglassmc/nbt 0.3.8 → 0.3.9
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/attributes.d.ts +3 -0
- package/lib/attributes.js +36 -0
- package/lib/checker/index.d.ts +8 -18
- package/lib/checker/index.js +244 -349
- package/lib/checker/mcdocUtil.d.ts +0 -5
- package/lib/checker/mcdocUtil.js +11 -80
- package/lib/colorizer/index.js +1 -0
- package/lib/completer/index.d.ts +3 -0
- package/lib/completer/index.js +160 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -1
- package/lib/node/index.d.ts +53 -16
- package/lib/node/index.js +39 -12
- package/lib/parser/collection.js +4 -4
- package/lib/parser/compound.js +2 -5
- package/lib/parser/entry.js +4 -1
- package/lib/parser/path.js +16 -28
- package/lib/parser/primitive.d.ts +3 -1
- package/lib/parser/primitive.js +5 -15
- package/package.json +4 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localize } from '@spyglassmc/locales';
|
|
3
|
+
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
4
|
+
import { entry } from './parser/entry.js';
|
|
5
|
+
import { path } from './parser/path.js';
|
|
6
|
+
const nbtValidator = (value) => {
|
|
7
|
+
if (!value || value?.kind === 'tree') {
|
|
8
|
+
return core.Failure;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
export function registerMcdocAttributes(meta) {
|
|
13
|
+
mcdoc.runtime.registerAttribute(meta, 'nbt', nbtValidator, {
|
|
14
|
+
stringParser: (config) => makeInfallible(core.map(entry, res => ({
|
|
15
|
+
type: 'nbt:typed',
|
|
16
|
+
range: res.range,
|
|
17
|
+
children: [res],
|
|
18
|
+
targetType: config,
|
|
19
|
+
})), localize('nbt.node')),
|
|
20
|
+
});
|
|
21
|
+
mcdoc.runtime.registerAttribute(meta, 'nbt_path', nbtValidator, {
|
|
22
|
+
stringParser: () => makeInfallible(path, localize('nbt.path')),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function makeInfallible(parser, message) {
|
|
26
|
+
return (src, ctx) => {
|
|
27
|
+
const start = src.cursor;
|
|
28
|
+
const res = parser(src, ctx);
|
|
29
|
+
if (res === core.Failure) {
|
|
30
|
+
ctx.err.report(localize('expected', message), core.Range.create(start, src.skipRemaining()));
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=attributes.js.map
|
package/lib/checker/index.d.ts
CHANGED
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import * as mcdoc from '@spyglassmc/mcdoc';
|
|
3
|
-
import type {
|
|
3
|
+
import type { NbtPathNode } from '../node/index.js';
|
|
4
|
+
import { NbtNode } from '../node/index.js';
|
|
5
|
+
export declare function register(meta: core.MetaRegistry): void;
|
|
4
6
|
interface Options {
|
|
5
|
-
allowUnknownKey?: boolean;
|
|
6
7
|
isPredicate?: boolean;
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
interface ArrayConstructor {
|
|
10
|
-
isArray(arg: unknown): arg is unknown[] | readonly unknown[];
|
|
11
|
-
}
|
|
8
|
+
isMerge?: boolean;
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
11
|
* @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`.
|
|
15
12
|
* 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.
|
|
16
13
|
*/
|
|
17
|
-
export declare function index(registry:
|
|
18
|
-
export declare function index(registry: string, id: core.FullResourceLocation, options?: Options): core.SyncChecker<NbtCompoundNode>;
|
|
14
|
+
export declare function index(registry: core.FullResourceLocation, id?: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined, options?: Options): core.SyncChecker<NbtNode>;
|
|
19
15
|
/**
|
|
20
16
|
* @param identifier An identifier of mcdoc compound definition. e.g. `::minecraft::util::invitem::InventoryItem`
|
|
21
17
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function blockStates(blocks: string[], _options?: Options): core.SyncChecker<
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function enum_(path: core.SymbolPath | undefined, _options?: Options): core.SyncChecker<NbtPrimitiveNode>;
|
|
26
|
-
/**
|
|
27
|
-
* @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.
|
|
28
|
-
*/
|
|
29
|
-
export declare function path(registry: string, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined): core.SyncChecker<NbtPathNode>;
|
|
30
|
-
export declare function fieldValue(type: mcdoc.McdocType, options: Options): core.SyncChecker<NbtNode>;
|
|
18
|
+
export declare function typeDefinition(typeDef: mcdoc.McdocType, options?: Options): core.SyncChecker<NbtNode>;
|
|
19
|
+
export declare function blockStates(blocks: string[], _options?: Options): core.SyncChecker<NbtNode>;
|
|
20
|
+
export declare function path(registry: core.FullResourceLocation, id: core.FullResourceLocation | readonly core.FullResourceLocation[] | undefined): core.SyncChecker<NbtPathNode>;
|
|
31
21
|
export {};
|
|
32
22
|
//# sourceMappingURL=index.d.ts.map
|