@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.
@@ -2,11 +2,7 @@ import * as core from '@spyglassmc/core';
2
2
  import { arrayToMessage, localeQuote, localize } from '@spyglassmc/locales';
3
3
  import { compound } from './compound.js';
4
4
  export const path = (src, ctx) => {
5
- const ans = {
6
- type: 'nbt:path',
7
- children: [],
8
- range: core.Range.create(src),
9
- };
5
+ const ans = { type: 'nbt:path', children: [], range: core.Range.create(src) };
10
6
  let expectedParts = ['filter', 'key'];
11
7
  let currentPart = nextPart(src);
12
8
  let cursor;
@@ -25,7 +21,12 @@ export const path = (src, ctx) => {
25
21
  return ans;
26
22
  };
27
23
  const filter = (children, src, ctx) => {
28
- children.push(compound(src, ctx));
24
+ const node = compound(src, ctx);
25
+ children.push({
26
+ type: 'nbt:path/filter',
27
+ range: node.range,
28
+ children: [node],
29
+ });
29
30
  return src.trySkip('.') ? ['key'] : ['end'];
30
31
  };
31
32
  const index = (children, src, ctx) => {
@@ -54,28 +55,19 @@ const index = (children, src, ctx) => {
54
55
  return src.trySkip('.') ? ['index', 'key'] : ['end', 'index'];
55
56
  };
56
57
  const key = (children, src, ctx) => {
57
- const node = core.string({
58
+ const node = core.setType('nbt:string', core.string({
58
59
  colorTokenType: 'property',
59
60
  escapable: {},
60
61
  // Single quotes supported since 1.20 Pre-release 2 (roughly pack format 15)
61
62
  // https://bugs.mojang.com/browse/MC-175504
62
63
  quotes: ['"', "'"],
63
- unquotable: {
64
- blockList: new Set([
65
- '\n',
66
- '\r',
67
- '\t',
68
- ' ',
69
- '"',
70
- '[',
71
- ']',
72
- '.',
73
- '{',
74
- '}',
75
- ]),
76
- },
77
- })(src, ctx);
78
- children.push(node);
64
+ unquotable: { blockList: new Set(['\n', '\r', '\t', ' ', '"', '[', ']', '.', '{', '}']) },
65
+ }))(src, ctx);
66
+ children.push({
67
+ type: 'nbt:path/key',
68
+ range: node.range,
69
+ children: [node],
70
+ });
79
71
  return src.trySkip('.') ? ['index', 'key'] : ['end', 'filter', 'index'];
80
72
  };
81
73
  function nextPart(src) {
@@ -96,9 +88,5 @@ function nextPart(src) {
96
88
  function localizePart(part) {
97
89
  return localize(`nbt.node.path.${part}`);
98
90
  }
99
- const PartParsers = {
100
- filter,
101
- index,
102
- key,
103
- };
91
+ const PartParsers = { filter, index, key };
104
92
  //# sourceMappingURL=path.js.map
@@ -1,5 +1,7 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import type { NbtPrimitiveNode } from '../node/index.js';
3
- export declare const string: core.InfallibleParser<core.StringNode>;
3
+ export declare const string: core.InfallibleParser<Omit<core.StringNode, "type"> & {
4
+ type: "nbt:string";
5
+ }>;
4
6
  export declare const primitive: core.InfallibleParser<NbtPrimitiveNode>;
5
7
  //# sourceMappingURL=primitive.d.ts.map
@@ -62,13 +62,12 @@ const NumeralPatterns = [
62
62
  { pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Group.Boolean */ },
63
63
  { pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Group.Boolean */ },
64
64
  ];
65
- export const string = core.brigadierString;
65
+ export const string = core.setType('nbt:string', core.brigadierString);
66
66
  export const primitive = (src, ctx) => {
67
67
  if (core.Source.isBrigadierQuote(src.peek())) {
68
68
  return string(src, ctx);
69
69
  }
70
- const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core
71
- .attempt(string, src, ctx);
70
+ const { result: unquotedResult, updateSrcAndCtx: updateUnquoted } = core.attempt(string, src, ctx);
72
71
  for (const e of NumeralPatterns) {
73
72
  if (e.pattern.test(unquotedResult.value)) {
74
73
  if (e.group === 0 /* Group.Boolean */) {
@@ -85,17 +84,11 @@ export const primitive = (src, ctx) => {
85
84
  const numeralParser = e.group === 2 /* Group.IntegerAlike */
86
85
  // As we already checked the format of the value with `e.pattern` in the if-block, there is no need to check
87
86
  // it again here in the parser, therefore we just pass in a simple /./ regex.
88
- ? core.integer({
89
- pattern: /./,
90
- min: e.min,
91
- max: e.max,
92
- onOutOfRange,
93
- })
87
+ ? core.integer({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
94
88
  : e.group === 3 /* Group.LongAlike */
95
89
  ? core.long({ pattern: /./, min: e.min, max: e.max, onOutOfRange })
96
90
  : core.float({ pattern: /./, min: e.min, max: e.max, onOutOfRange });
97
- const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core
98
- .attempt(numeralParser, src, ctx);
91
+ const { result: numeralResult, updateSrcAndCtx: updateNumeral } = core.attempt(numeralParser, src, ctx);
99
92
  if (isOutOfRange) {
100
93
  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 */);
101
94
  break;
@@ -105,10 +98,7 @@ export const primitive = (src, ctx) => {
105
98
  src.skip();
106
99
  numeralResult.range.end++;
107
100
  }
108
- return {
109
- ...numeralResult,
110
- type: e.type,
111
- };
101
+ return { ...numeralResult, type: e.type };
112
102
  }
113
103
  }
114
104
  updateUnquoted();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/nbt",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@spyglassmc/core": "0.4.5",
29
- "@spyglassmc/locales": "0.3.5",
30
- "@spyglassmc/mcdoc": "0.3.7"
28
+ "@spyglassmc/core": "0.4.6",
29
+ "@spyglassmc/locales": "0.3.6",
30
+ "@spyglassmc/mcdoc": "0.3.9"
31
31
  }
32
32
  }