@spyglassmc/nbt 0.3.7 → 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.
@@ -1,42 +1,15 @@
1
1
  const BlockItems = {
2
2
  // Coral fans.
3
- 'minecraft:brain_coral_fan': [
4
- 'minecraft:brain_coral_fan',
5
- 'minecraft:brain_coral_wall_fan',
6
- ],
7
- 'minecraft:bubble_coral_fan': [
8
- 'minecraft:bubble_coral_fan',
9
- 'minecraft:bubble_coral_wall_fan',
10
- ],
11
- 'minecraft:fire_coral_fan': [
12
- 'minecraft:fire_coral_fan',
13
- 'minecraft:fire_coral_wall_fan',
14
- ],
15
- 'minecraft:horn_coral_fan': [
16
- 'minecraft:horn_coral_fan',
17
- 'minecraft:horn_coral_wall_fan',
18
- ],
19
- 'minecraft:tube_coral_fan': [
20
- 'minecraft:tube_coral_fan',
21
- 'minecraft:tube_coral_wall_fan',
22
- ],
3
+ 'minecraft:brain_coral_fan': ['minecraft:brain_coral_fan', 'minecraft:brain_coral_wall_fan'],
4
+ 'minecraft:bubble_coral_fan': ['minecraft:bubble_coral_fan', 'minecraft:bubble_coral_wall_fan'],
5
+ 'minecraft:fire_coral_fan': ['minecraft:fire_coral_fan', 'minecraft:fire_coral_wall_fan'],
6
+ 'minecraft:horn_coral_fan': ['minecraft:horn_coral_fan', 'minecraft:horn_coral_wall_fan'],
7
+ 'minecraft:tube_coral_fan': ['minecraft:tube_coral_fan', 'minecraft:tube_coral_wall_fan'],
23
8
  // Heads and skulls.
24
- 'minecraft:creeper_head': [
25
- 'minecraft:creeper_head',
26
- 'minecraft:creeper_wall_head',
27
- ],
28
- 'minecraft:dragon_head': [
29
- 'minecraft:dragon_head',
30
- 'minecraft:dragon_wall_head',
31
- ],
32
- 'minecraft:player_head': [
33
- 'minecraft:player_head',
34
- 'minecraft:player_wall_head',
35
- ],
36
- 'minecraft:skeleton_skull': [
37
- 'minecraft:skeleton_skull',
38
- 'minecraft:skeleton_wall_skull',
39
- ],
9
+ 'minecraft:creeper_head': ['minecraft:creeper_head', 'minecraft:creeper_wall_head'],
10
+ 'minecraft:dragon_head': ['minecraft:dragon_head', 'minecraft:dragon_wall_head'],
11
+ 'minecraft:player_head': ['minecraft:player_head', 'minecraft:player_wall_head'],
12
+ 'minecraft:skeleton_skull': ['minecraft:skeleton_skull', 'minecraft:skeleton_wall_skull'],
40
13
  'minecraft:wither_skeleton_skull': [
41
14
  'minecraft:wither_skeleton_skull',
42
15
  'minecraft:wither_skeleton_wall_skull',
@@ -64,14 +37,8 @@ const BlockItems = {
64
37
  ],
65
38
  // Torches.
66
39
  'minecraft:torch': ['minecraft:torch', 'minecraft:wall_torch'],
67
- 'minecraft:soul_torch': [
68
- 'minecraft:soul_torch',
69
- 'minecraft:soul_wall_torch',
70
- ],
71
- 'minecraft:redstone_torch': [
72
- 'minecraft:redstone_torch',
73
- 'minecraft:redstone_wall_torch',
74
- ],
40
+ 'minecraft:soul_torch': ['minecraft:soul_torch', 'minecraft:soul_wall_torch'],
41
+ 'minecraft:redstone_torch': ['minecraft:redstone_torch', 'minecraft:redstone_wall_torch'],
75
42
  'minecraft:beetroot_seeds': ['minecraft:beetroots'],
76
43
  'minecraft:carrot': ['minecraft:carrots'],
77
44
  'minecraft:cocoa_beans': ['minecraft:cocoa'],
@@ -97,40 +64,4 @@ export function getEntityFromItem(item) {
97
64
  }
98
65
  return undefined;
99
66
  }
100
- const SpecialStrings = {
101
- '::minecraft::block::banner::Banner.CustomName': 'mcfunction:component',
102
- '::minecraft::block::brewingstand::BrewingStand.CustomName': 'mcfunction:component',
103
- '::minecraft::block::commandblock::CommandBlock.Command': 'mcfunction:command',
104
- '::minecraft::block::commandblock::CommandBlock.CustomName': 'mcfunction:component',
105
- '::minecraft::block::container::ContainerBase.CustomName': 'mcfunction:component',
106
- '::minecraft::block::enchantingtable::EnchantingTable.CustomName': 'mcfunction:component',
107
- '::minecraft::block::furnace::Furnace.CustomName': 'mcfunction:component',
108
- '::minecraft::block::hopper::Hopper.CustomName': 'mcfunction:component',
109
- '::minecraft::block::sign::Sign.Text1': 'mcfunction:component',
110
- '::minecraft::block::sign::Sign.Text2': 'mcfunction:component',
111
- '::minecraft::block::sign::Sign.Text3': 'mcfunction:component',
112
- '::minecraft::block::sign::Sign.Text4': 'mcfunction:component',
113
- '::minecraft::entity::effectcloud::EffectCloud.Particle': 'mcfunction:particle',
114
- '::minecraft::entity::minecart::CommandMinecart.Command': 'mcfunction:command',
115
- '::minecraft::entity::mob::LivingEntity.Team': 'mcfunction:team',
116
- '::minecraft::entity::EntityBase.Tags[]': 'mcfunction:tag',
117
- '::minecraft::item::blockitem::BlockItem.CanPlaceOn[]': 'mcfunction:block_predicate',
118
- '::minecraft::item::book::WrittenBook.pages[]': 'mcfunction:component',
119
- '::minecraft::item::ItemBase.CanDestroy[]': 'mcfunction:block_predicate',
120
- };
121
- export function getSpecialStringParser(mcdocPath) {
122
- return SpecialStrings[mcdocPath];
123
- }
124
- const ExpandableCompounds = [
125
- '::minecraft::item::ItemBase',
126
- '::minecraft::entity::marker::Any',
127
- '::minecraft::util::any::Any',
128
- '::minecraft::util::Any',
129
- ];
130
- /**
131
- * @param mcdocPath Path of the mcdoc compound definition.
132
- */
133
- export function isExpandableCompound(mcdocPath) {
134
- return ExpandableCompounds.includes(mcdocPath);
135
- }
136
67
  //# sourceMappingURL=mcdocUtil.js.map
@@ -1,5 +1,6 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  export function register(meta) {
3
+ meta.registerColorizer('nbt:string', core.colorizer.string);
3
4
  meta.registerColorizer('nbt:byte', core.colorizer.number);
4
5
  meta.registerColorizer('nbt:short', core.colorizer.number);
5
6
  meta.registerColorizer('nbt:int', core.colorizer.number);
@@ -0,0 +1,3 @@
1
+ import * as core from '@spyglassmc/core';
2
+ export declare function register(meta: core.MetaRegistry): void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,160 @@
1
+ import * as core from '@spyglassmc/core';
2
+ import * as mcdoc from '@spyglassmc/mcdoc';
3
+ const collection = (node, ctx) => {
4
+ const index = core.binarySearch(node.children, ctx.offset, (n, o) => {
5
+ return core.Range.compareOffset(n.range, o, true);
6
+ });
7
+ const item = index >= 0 ? node.children[index] : undefined;
8
+ if (item?.value) {
9
+ return ctx.meta.getCompleter(item.value.type)(item.value, ctx);
10
+ }
11
+ if (node.typeDef?.kind === 'list') {
12
+ const completions = getValues(node.typeDef.item, ctx.offset, {
13
+ ...ctx,
14
+ requireCanonical: node.requireCanonical,
15
+ });
16
+ if (ctx.offset < node.children[node.children.length - 1]?.range.start ?? 0) {
17
+ return completions.map(c => ({ ...c, insertText: c.insertText + ',' }));
18
+ }
19
+ return completions;
20
+ }
21
+ return [];
22
+ };
23
+ const compound = core.completer.record({
24
+ key: (record, pair, ctx, range, iv, ipe, exitingKeys) => {
25
+ if (!record.typeDef) {
26
+ return [];
27
+ }
28
+ const keySet = new Set(exitingKeys.map(n => n.value));
29
+ return mcdoc.runtime.completer
30
+ .getFields(record.typeDef, { ...ctx, requireCanonical: record.requireCanonical })
31
+ .filter(({ key }) => !keySet.has(key))
32
+ .map(({ key, field }) => core.CompletionItem.create(key, pair?.key ?? range, {
33
+ kind: 5 /* core.CompletionKind.Field */,
34
+ detail: mcdoc.McdocType.toString(field.type),
35
+ deprecated: field.deprecated,
36
+ sortText: field.optional ? '$b' : '$a', // sort above hardcoded $schema
37
+ filterText: formatKey(key, pair?.key?.quote),
38
+ insertText: `${formatKey(key, pair?.key?.quote)}${iv ? ':' : ''}${ipe ? '$1,' : ''}`,
39
+ }));
40
+ },
41
+ value: (record, pair, ctx, range) => {
42
+ if (pair.value) {
43
+ return ctx.meta.getCompleter(pair.value.type)(pair.value, ctx);
44
+ }
45
+ if (pair.key && record.typeDef) {
46
+ const pairKey = pair.key.value;
47
+ const field = mcdoc.runtime.completer
48
+ .getFields(record.typeDef, ctx)
49
+ .find(({ key }) => key === pairKey)
50
+ ?.field.type;
51
+ if (field) {
52
+ return getValues(field, range, {
53
+ ...ctx,
54
+ requireCanonical: record.requireCanonical,
55
+ });
56
+ }
57
+ }
58
+ return [];
59
+ },
60
+ });
61
+ const primitive = (node, ctx) => {
62
+ const insideRange = core.Range.contains(node, ctx.offset, true);
63
+ if (node.type === 'nbt:string' && node.children?.length && insideRange) {
64
+ const childItems = core.completer.string(node, ctx);
65
+ if (childItems.length > 0) {
66
+ return childItems;
67
+ }
68
+ }
69
+ if (!node.typeDef) {
70
+ return [];
71
+ }
72
+ return getValues(node.typeDef, insideRange ? node : ctx.offset, {
73
+ ...ctx,
74
+ requireCanonical: node.requireCanonical,
75
+ });
76
+ };
77
+ const path = (node, ctx) => {
78
+ const index = core.binarySearch(node.children, ctx.offset, (n, o) => {
79
+ return core.Range.compareOffset(n.range, o, true);
80
+ });
81
+ const item = index >= 0 ? node.children[index] : undefined;
82
+ if (item) {
83
+ return ctx.meta.getCompleter(item.type)(item, ctx);
84
+ }
85
+ if (!node.endTypeDef) {
86
+ return [];
87
+ }
88
+ return getPathKeys(node.endTypeDef, ctx.offset, undefined, ctx);
89
+ };
90
+ const pathKey = (node, ctx) => {
91
+ if (!node.typeDef) {
92
+ return [];
93
+ }
94
+ const child = node.children[0];
95
+ if (child.children?.length) {
96
+ return core.completer.dispatch(child.children[0], ctx);
97
+ }
98
+ return getPathKeys(node.typeDef, node, child.quote, ctx);
99
+ };
100
+ function getPathKeys(typeDef, range, quote, ctx) {
101
+ return mcdoc.runtime.completer
102
+ .getFields(typeDef, { ...ctx, requireCanonical: true })
103
+ .map(({ key, field }) => core.CompletionItem.create(key, range, {
104
+ kind: 5 /* core.CompletionKind.Field */,
105
+ detail: mcdoc.McdocType.toString(field.type),
106
+ deprecated: field.deprecated,
107
+ sortText: field.optional ? '$b' : '$a', // sort above hardcoded $schema
108
+ filterText: formatKey(key, quote),
109
+ insertText: formatKey(key, quote),
110
+ }));
111
+ }
112
+ function getValues(typeDef, range, ctx) {
113
+ return mcdoc.runtime.completer.getValues(typeDef, ctx)
114
+ .map(({ value, detail, kind, completionKind, insertText }) => core.CompletionItem.create(value, range, {
115
+ kind: completionKind ?? 12 /* core.CompletionKind.Value */,
116
+ detail,
117
+ filterText: formatValue(value, kind),
118
+ insertText: formatValue(insertText ?? value, kind),
119
+ }));
120
+ }
121
+ function formatKey(key, quote) {
122
+ if (!quote && core.BrigadierUnquotablePattern.test(key)) {
123
+ return key;
124
+ }
125
+ const q = quote ?? '"';
126
+ return q + core.completer.escapeString(key, q) + q;
127
+ }
128
+ function formatValue(value, kind) {
129
+ switch (kind) {
130
+ case 'string':
131
+ return `"${core.completer.escapeString(value, '"')}"`;
132
+ case 'byte':
133
+ return `${value}b`;
134
+ case 'short':
135
+ return `${value}s`;
136
+ case 'long':
137
+ return `${value}L`;
138
+ case 'float':
139
+ return `${value}f`;
140
+ default:
141
+ return value;
142
+ }
143
+ }
144
+ export function register(meta) {
145
+ meta.registerCompleter('nbt:byte', primitive);
146
+ meta.registerCompleter('nbt:byte_array', collection);
147
+ meta.registerCompleter('nbt:compound', compound);
148
+ meta.registerCompleter('nbt:double', primitive);
149
+ meta.registerCompleter('nbt:int', primitive);
150
+ meta.registerCompleter('nbt:int_array', collection);
151
+ meta.registerCompleter('nbt:list', collection);
152
+ meta.registerCompleter('nbt:long', primitive);
153
+ meta.registerCompleter('nbt:long_array', collection);
154
+ meta.registerCompleter('nbt:string', primitive);
155
+ meta.registerCompleter('nbt:short', primitive);
156
+ meta.registerCompleter('nbt:float', primitive);
157
+ meta.registerCompleter('nbt:path', path);
158
+ meta.registerCompleter('nbt:path/key', pathKey);
159
+ }
160
+ //# sourceMappingURL=index.js.map
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type * as core from '@spyglassmc/core';
2
2
  export * as checker from './checker/index.js';
3
3
  export * as colorizer from './colorizer/index.js';
4
+ export * as completer from './completer/index.js';
4
5
  export * from './node/index.js';
5
6
  export * as parser from './parser/index.js';
6
7
  export declare const initialize: core.SyncProjectInitializer;
package/lib/index.js CHANGED
@@ -1,18 +1,28 @@
1
+ import { registerMcdocAttributes } from './attributes.js';
2
+ import * as checker from './checker/index.js';
1
3
  import * as colorizer from './colorizer/index.js';
4
+ import * as completer from './completer/index.js';
2
5
  import * as parser from './parser/index.js';
3
6
  export * as checker from './checker/index.js';
4
7
  export * as colorizer from './colorizer/index.js';
8
+ export * as completer from './completer/index.js';
5
9
  export * from './node/index.js';
6
10
  export * as parser from './parser/index.js';
7
11
  /* istanbul ignore next */
8
12
  export const initialize = ({ meta }) => {
9
- meta.registerLanguage('nbt', {
13
+ meta.registerLanguage('snbt', {
10
14
  extensions: ['.snbt'],
11
15
  parser: parser.entry,
12
16
  });
17
+ meta.registerLanguage('nbt', {
18
+ extensions: ['.nbt'],
19
+ });
13
20
  meta.registerParser('nbt:entry', parser.entry);
14
21
  meta.registerParser('nbt:compound', parser.compound);
15
22
  meta.registerParser('nbt:path', parser.path);
23
+ checker.register(meta);
16
24
  colorizer.register(meta);
25
+ completer.register(meta);
26
+ registerMcdocAttributes(meta);
17
27
  };
18
28
  //# sourceMappingURL=index.js.map
@@ -1,13 +1,23 @@
1
- import * as core from '@spyglassmc/core';
1
+ import type * as core from '@spyglassmc/core';
2
2
  import type * as mcdoc from '@spyglassmc/mcdoc';
3
+ interface NbtBaseNode {
4
+ typeDef?: mcdoc.runtime.checker.SimplifiedMcdocType;
5
+ requireCanonical?: boolean;
6
+ }
3
7
  export type NbtNode = NbtPrimitiveNode | NbtCompoundNode | NbtCollectionNode;
4
8
  export declare namespace NbtNode {
5
9
  function is(node: core.AstNode | undefined): node is NbtNode;
6
10
  }
7
- export type NbtPrimitiveNode = NbtNumberNode | core.StringNode;
11
+ export type NbtPrimitiveNode = NbtNumberNode | NbtStringNode;
8
12
  export declare namespace NbtPrimitiveNode {
9
13
  function is(node: core.AstNode | undefined): node is NbtPrimitiveNode;
10
14
  }
15
+ export interface NbtStringNode extends core.StringBaseNode, NbtBaseNode {
16
+ readonly type: 'nbt:string';
17
+ }
18
+ export declare namespace NbtStringNode {
19
+ function is(obj: object | undefined): obj is NbtStringNode;
20
+ }
11
21
  export type NbtNumberNode = NbtIntegerAlikeNode | NbtFloatAlikeNode;
12
22
  export declare namespace NbtNumberNode {
13
23
  function is(node: core.AstNode | undefined): node is NbtNumberNode;
@@ -16,25 +26,25 @@ export type NbtIntegerAlikeNode = NbtByteNode | NbtShortNode | NbtIntNode | NbtL
16
26
  export declare namespace NbtIntegerAlikeNode {
17
27
  function is(node: core.AstNode | undefined): node is NbtIntegerAlikeNode;
18
28
  }
19
- export interface NbtByteNode extends core.IntegerBaseNode {
29
+ export interface NbtByteNode extends core.IntegerBaseNode, NbtBaseNode {
20
30
  readonly type: 'nbt:byte';
21
31
  }
22
32
  export declare namespace NbtByteNode {
23
33
  function is(node: core.AstNode | undefined): node is NbtByteNode;
24
34
  }
25
- export interface NbtShortNode extends core.IntegerBaseNode {
35
+ export interface NbtShortNode extends core.IntegerBaseNode, NbtBaseNode {
26
36
  readonly type: 'nbt:short';
27
37
  }
28
38
  export declare namespace NbtShortNode {
29
39
  function is(node: core.AstNode | undefined): node is NbtShortNode;
30
40
  }
31
- export interface NbtIntNode extends core.IntegerBaseNode {
41
+ export interface NbtIntNode extends core.IntegerBaseNode, NbtBaseNode {
32
42
  readonly type: 'nbt:int';
33
43
  }
34
44
  export declare namespace NbtIntNode {
35
45
  function is(node: core.AstNode | undefined): node is NbtIntNode;
36
46
  }
37
- export interface NbtLongNode extends core.LongBaseNode {
47
+ export interface NbtLongNode extends core.LongBaseNode, NbtBaseNode {
38
48
  readonly type: 'nbt:long';
39
49
  }
40
50
  export declare namespace NbtLongNode {
@@ -44,19 +54,19 @@ export type NbtFloatAlikeNode = NbtFloatNode | NbtDoubleNode;
44
54
  export declare namespace NbtFloatAlikeNode {
45
55
  function is(node: core.AstNode | undefined): node is NbtFloatAlikeNode;
46
56
  }
47
- export interface NbtFloatNode extends core.FloatBaseNode {
57
+ export interface NbtFloatNode extends core.FloatBaseNode, NbtBaseNode {
48
58
  readonly type: 'nbt:float';
49
59
  }
50
60
  export declare namespace NbtFloatNode {
51
61
  function is(node: core.AstNode | undefined): node is NbtFloatNode;
52
62
  }
53
- export interface NbtDoubleNode extends core.FloatBaseNode {
63
+ export interface NbtDoubleNode extends core.FloatBaseNode, NbtBaseNode {
54
64
  readonly type: 'nbt:double';
55
65
  }
56
66
  export declare namespace NbtDoubleNode {
57
67
  function is(node: core.AstNode | undefined): node is NbtDoubleNode;
58
68
  }
59
- export interface NbtCompoundNode extends core.RecordBaseNode<core.StringNode, NbtNode> {
69
+ export interface NbtCompoundNode extends core.RecordBaseNode<NbtStringNode, NbtNode>, NbtBaseNode {
60
70
  readonly type: 'nbt:compound';
61
71
  }
62
72
  export declare namespace NbtCompoundNode {
@@ -66,7 +76,7 @@ export type NbtCollectionNode = NbtListNode | NbtPrimitiveArrayNode;
66
76
  export declare namespace NbtCollectionNode {
67
77
  function is(node: core.AstNode | undefined): node is NbtCollectionNode;
68
78
  }
69
- export interface NbtListNode extends core.ListNode<NbtNode> {
79
+ export interface NbtListNode extends core.ListNode<NbtNode>, NbtBaseNode {
70
80
  type: 'nbt:list';
71
81
  valueType?: NbtNode['type'];
72
82
  }
@@ -77,37 +87,64 @@ export type NbtPrimitiveArrayNode = NbtByteArrayNode | NbtIntArrayNode | NbtLong
77
87
  export declare namespace NbtPrimitiveArrayNode {
78
88
  function is(node: core.AstNode | undefined): node is NbtPrimitiveArrayNode;
79
89
  }
80
- export interface NbtByteArrayNode extends core.ListNode<NbtByteNode> {
90
+ export interface NbtByteArrayNode extends core.ListNode<NbtByteNode>, NbtBaseNode {
81
91
  type: 'nbt:byte_array';
82
92
  }
83
93
  export declare namespace NbtByteArrayNode {
84
94
  function is(node: core.AstNode | undefined): node is NbtByteArrayNode;
85
95
  }
86
- export interface NbtIntArrayNode extends core.ListNode<NbtIntNode> {
96
+ export interface NbtIntArrayNode extends core.ListNode<NbtIntNode>, NbtBaseNode {
87
97
  type: 'nbt:int_array';
88
98
  }
89
99
  export declare namespace NbtIntArrayNode {
90
100
  function is(node: core.AstNode | undefined): node is NbtIntArrayNode;
91
101
  }
92
- export interface NbtLongArrayNode extends core.ListNode<NbtLongNode> {
102
+ export interface NbtLongArrayNode extends core.ListNode<NbtLongNode>, NbtBaseNode {
93
103
  type: 'nbt:long_array';
94
104
  }
95
105
  export declare namespace NbtLongArrayNode {
96
106
  function is(node: core.AstNode | undefined): node is NbtLongArrayNode;
97
107
  }
108
+ export type NbtPathChild = NbtPathKeyNode | NbtPathFilterNode | NbtPathIndexNode;
98
109
  export interface NbtPathNode extends core.AstNode {
99
110
  type: 'nbt:path';
100
- children: (core.StringNode | NbtCompoundNode | NbtPathIndexNode)[];
101
- targetType?: mcdoc.McdocType | undefined;
111
+ children: NbtPathChild[];
112
+ /**
113
+ * The type definition at the end of the path
114
+ */
115
+ endTypeDef?: mcdoc.runtime.checker.SimplifiedMcdocType;
102
116
  }
103
117
  export declare namespace NbtPathNode {
104
118
  function is(node: core.AstNode | undefined): node is NbtPathNode;
105
119
  }
106
- export interface NbtPathIndexNode extends core.AstNode {
120
+ export interface NbtPathKeyNode extends core.AstNode, NbtBaseNode {
121
+ type: 'nbt:path/key';
122
+ children: [NbtStringNode];
123
+ }
124
+ export declare namespace NbtPathKeyNode {
125
+ function is(node: core.AstNode | undefined): node is NbtPathKeyNode;
126
+ }
127
+ export interface NbtPathFilterNode extends core.AstNode, NbtBaseNode {
128
+ type: 'nbt:path/filter';
129
+ children: [NbtCompoundNode];
130
+ }
131
+ export declare namespace NbtPathFilterNode {
132
+ function is(node: core.AstNode | undefined): node is NbtPathFilterNode;
133
+ }
134
+ export interface NbtPathIndexNode extends core.AstNode, NbtBaseNode {
107
135
  type: 'nbt:path/index';
108
136
  children: [core.IntegerNode] | [NbtCompoundNode] | undefined;
109
137
  }
110
138
  export declare namespace NbtPathIndexNode {
111
139
  function is(node: core.AstNode | undefined): node is NbtPathIndexNode;
112
140
  }
141
+ export interface TypedNbtNode extends core.AstNode {
142
+ type: 'nbt:typed';
143
+ children: [NbtNode];
144
+ targetType: mcdoc.McdocType;
145
+ }
146
+ export declare namespace TypedNbtNode {
147
+ function is(node: core.AstNode | undefined): node is TypedNbtNode;
148
+ }
149
+ export {};
113
150
  //# sourceMappingURL=index.d.ts.map
package/lib/node/index.js CHANGED
@@ -1,11 +1,8 @@
1
- import * as core from '@spyglassmc/core';
2
1
  export var NbtNode;
3
2
  (function (NbtNode) {
4
3
  /* istanbul ignore next */
5
4
  function is(node) {
6
- return (NbtPrimitiveNode.is(node) ||
7
- NbtCompoundNode.is(node) ||
8
- NbtCollectionNode.is(node));
5
+ return (NbtPrimitiveNode.is(node) || NbtCompoundNode.is(node) || NbtCollectionNode.is(node));
9
6
  }
10
7
  NbtNode.is = is;
11
8
  })(NbtNode || (NbtNode = {}));
@@ -13,10 +10,18 @@ export var NbtPrimitiveNode;
13
10
  (function (NbtPrimitiveNode) {
14
11
  /* istanbul ignore next */
15
12
  function is(node) {
16
- return NbtNumberNode.is(node) || core.StringNode.is(node);
13
+ return NbtNumberNode.is(node) || NbtStringNode.is(node);
17
14
  }
18
15
  NbtPrimitiveNode.is = is;
19
16
  })(NbtPrimitiveNode || (NbtPrimitiveNode = {}));
17
+ export var NbtStringNode;
18
+ (function (NbtStringNode) {
19
+ /* istanbul ignore next */
20
+ function is(obj) {
21
+ return obj?.type === 'nbt:string';
22
+ }
23
+ NbtStringNode.is = is;
24
+ })(NbtStringNode || (NbtStringNode = {}));
20
25
  export var NbtNumberNode;
21
26
  (function (NbtNumberNode) {
22
27
  /* istanbul ignore next */
@@ -29,10 +34,10 @@ export var NbtIntegerAlikeNode;
29
34
  (function (NbtIntegerAlikeNode) {
30
35
  /* istanbul ignore next */
31
36
  function is(node) {
32
- return (NbtByteNode.is(node) ||
33
- NbtShortNode.is(node) ||
34
- NbtIntNode.is(node) ||
35
- NbtLongNode.is(node));
37
+ return (NbtByteNode.is(node)
38
+ || NbtShortNode.is(node)
39
+ || NbtIntNode.is(node)
40
+ || NbtLongNode.is(node));
36
41
  }
37
42
  NbtIntegerAlikeNode.is = is;
38
43
  })(NbtIntegerAlikeNode || (NbtIntegerAlikeNode = {}));
@@ -120,9 +125,7 @@ export var NbtPrimitiveArrayNode;
120
125
  (function (NbtPrimitiveArrayNode) {
121
126
  /* istanbul ignore next */
122
127
  function is(node) {
123
- return (NbtByteArrayNode.is(node) ||
124
- NbtIntArrayNode.is(node) ||
125
- NbtLongArrayNode.is(node));
128
+ return (NbtByteArrayNode.is(node) || NbtIntArrayNode.is(node) || NbtLongArrayNode.is(node));
126
129
  }
127
130
  NbtPrimitiveArrayNode.is = is;
128
131
  })(NbtPrimitiveArrayNode || (NbtPrimitiveArrayNode = {}));
@@ -158,6 +161,22 @@ export var NbtPathNode;
158
161
  }
159
162
  NbtPathNode.is = is;
160
163
  })(NbtPathNode || (NbtPathNode = {}));
164
+ export var NbtPathKeyNode;
165
+ (function (NbtPathKeyNode) {
166
+ /* istanbul ignore next */
167
+ function is(node) {
168
+ return node?.type === 'nbt:path/key';
169
+ }
170
+ NbtPathKeyNode.is = is;
171
+ })(NbtPathKeyNode || (NbtPathKeyNode = {}));
172
+ export var NbtPathFilterNode;
173
+ (function (NbtPathFilterNode) {
174
+ /* istanbul ignore next */
175
+ function is(node) {
176
+ return node?.type === 'nbt:path/filter';
177
+ }
178
+ NbtPathFilterNode.is = is;
179
+ })(NbtPathFilterNode || (NbtPathFilterNode = {}));
161
180
  export var NbtPathIndexNode;
162
181
  (function (NbtPathIndexNode) {
163
182
  /* istanbul ignore next */
@@ -166,4 +185,12 @@ export var NbtPathIndexNode;
166
185
  }
167
186
  NbtPathIndexNode.is = is;
168
187
  })(NbtPathIndexNode || (NbtPathIndexNode = {}));
188
+ export var TypedNbtNode;
189
+ (function (TypedNbtNode) {
190
+ /* istanbul ignore next */
191
+ function is(node) {
192
+ return node?.type === 'nbt:typed';
193
+ }
194
+ TypedNbtNode.is = is;
195
+ })(TypedNbtNode || (TypedNbtNode = {}));
169
196
  //# sourceMappingURL=index.js.map
@@ -8,7 +8,7 @@ export const list = (src, ctx) => {
8
8
  start: '[',
9
9
  value: entry,
10
10
  sep: ',',
11
- trailingSep: false,
11
+ trailingSep: true,
12
12
  end: ']',
13
13
  });
14
14
  const ans = parser(src, ctx);
@@ -29,7 +29,7 @@ export const byteArray = (src, ctx) => {
29
29
  start: '[B;',
30
30
  value: primitive,
31
31
  sep: ',',
32
- trailingSep: false,
32
+ trailingSep: true,
33
33
  end: ']',
34
34
  });
35
35
  const ans = parser(src, ctx);
@@ -47,7 +47,7 @@ export const intArray = (src, ctx) => {
47
47
  start: '[I;',
48
48
  value: primitive,
49
49
  sep: ',',
50
- trailingSep: false,
50
+ trailingSep: true,
51
51
  end: ']',
52
52
  });
53
53
  const ans = parser(src, ctx);
@@ -65,7 +65,7 @@ export const longArray = (src, ctx) => {
65
65
  start: '[L;',
66
66
  value: primitive,
67
67
  sep: ',',
68
- trailingSep: false,
68
+ trailingSep: true,
69
69
  end: ']',
70
70
  });
71
71
  const ans = parser(src, ctx);
@@ -4,14 +4,11 @@ export const compound = (src, ctx) => {
4
4
  return core.setType('nbt:compound', core.record({
5
5
  start: '{',
6
6
  pair: {
7
- key: core.failOnEmpty(core.string({
8
- ...core.BrigadierStringOptions,
9
- colorTokenType: 'property',
10
- })),
7
+ key: core.failOnEmpty(core.setType('nbt:string', core.string({ ...core.BrigadierStringOptions, colorTokenType: 'property' }))),
11
8
  sep: ':',
12
9
  value: entry,
13
10
  end: ',',
14
- trailingEnd: false,
11
+ trailingEnd: true,
15
12
  },
16
13
  end: '}',
17
14
  }))(src, ctx);
@@ -4,7 +4,10 @@ import { compound } from './compound.js';
4
4
  import { primitive } from './primitive.js';
5
5
  export const entry = (src, ctx) => core.failOnEmpty(core.select([
6
6
  { predicate: (src) => src.tryPeek('[B;'), parser: byteArray },
7
- { predicate: (src) => src.tryPeek('[I;'), parser: intArray },
7
+ {
8
+ predicate: (src) => src.tryPeek('[I;'),
9
+ parser: intArray,
10
+ },
8
11
  { predicate: (src) => src.tryPeek('[L;'), parser: longArray },
9
12
  { predicate: (src) => src.tryPeek('['), parser: list },
10
13
  { predicate: (src) => src.tryPeek('{'), parser: compound },