@spyglassmc/core 0.1.2 → 0.2.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.
Files changed (187) hide show
  1. package/README.md +7 -0
  2. package/lib/browser.d.ts +2 -0
  3. package/lib/browser.js +2 -0
  4. package/lib/common/TwoWayMap.js +4 -10
  5. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  6. package/lib/common/externals/BrowserExternals.js +191 -0
  7. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  8. package/lib/common/externals/NodeJsExternals.js +151 -0
  9. package/lib/common/externals/downloader.d.ts +31 -0
  10. package/lib/common/externals/downloader.js +32 -0
  11. package/lib/common/externals/index.d.ts +96 -0
  12. package/lib/common/externals/index.js +2 -0
  13. package/lib/common/index.d.ts +2 -1
  14. package/lib/common/index.js +2 -17
  15. package/lib/common/util.d.ts +15 -15
  16. package/lib/common/util.js +30 -77
  17. package/lib/index.d.ts +7 -7
  18. package/lib/index.js +7 -23
  19. package/lib/node/AstNode.d.ts +3 -3
  20. package/lib/node/AstNode.js +10 -16
  21. package/lib/node/BooleanNode.d.ts +2 -2
  22. package/lib/node/BooleanNode.js +4 -7
  23. package/lib/node/CommentNode.d.ts +1 -1
  24. package/lib/node/CommentNode.js +2 -5
  25. package/lib/node/ErrorNode.d.ts +1 -1
  26. package/lib/node/ErrorNode.js +2 -5
  27. package/lib/node/FileNode.d.ts +3 -3
  28. package/lib/node/FileNode.js +2 -5
  29. package/lib/node/FloatNode.d.ts +2 -2
  30. package/lib/node/FloatNode.js +4 -7
  31. package/lib/node/IntegerNode.d.ts +2 -2
  32. package/lib/node/IntegerNode.js +4 -7
  33. package/lib/node/ListNode.d.ts +2 -2
  34. package/lib/node/ListNode.js +2 -5
  35. package/lib/node/LiteralNode.d.ts +3 -3
  36. package/lib/node/LiteralNode.js +4 -7
  37. package/lib/node/LongNode.d.ts +2 -2
  38. package/lib/node/LongNode.js +4 -7
  39. package/lib/node/RecordNode.d.ts +2 -2
  40. package/lib/node/RecordNode.js +2 -5
  41. package/lib/node/ResourceLocationNode.d.ts +5 -5
  42. package/lib/node/ResourceLocationNode.js +9 -12
  43. package/lib/node/Sequence.d.ts +2 -2
  44. package/lib/node/Sequence.js +4 -7
  45. package/lib/node/StringNode.d.ts +4 -4
  46. package/lib/node/StringNode.js +9 -12
  47. package/lib/node/SymbolNode.d.ts +3 -3
  48. package/lib/node/SymbolNode.js +4 -7
  49. package/lib/node/index.d.ts +15 -15
  50. package/lib/node/index.js +15 -31
  51. package/lib/nodejs.d.ts +2 -0
  52. package/lib/nodejs.js +2 -0
  53. package/lib/parser/Parser.d.ts +3 -3
  54. package/lib/parser/Parser.js +1 -4
  55. package/lib/parser/boolean.d.ts +2 -2
  56. package/lib/parser/boolean.js +3 -6
  57. package/lib/parser/comment.d.ts +2 -2
  58. package/lib/parser/comment.js +5 -9
  59. package/lib/parser/empty.d.ts +1 -1
  60. package/lib/parser/empty.js +1 -5
  61. package/lib/parser/error.d.ts +2 -2
  62. package/lib/parser/error.js +5 -9
  63. package/lib/parser/file.d.ts +3 -3
  64. package/lib/parser/file.js +9 -13
  65. package/lib/parser/float.d.ts +4 -4
  66. package/lib/parser/float.js +12 -16
  67. package/lib/parser/index.d.ts +16 -16
  68. package/lib/parser/index.js +16 -38
  69. package/lib/parser/integer.d.ts +4 -4
  70. package/lib/parser/integer.js +10 -14
  71. package/lib/parser/list.d.ts +2 -2
  72. package/lib/parser/list.js +15 -19
  73. package/lib/parser/literal.d.ts +2 -2
  74. package/lib/parser/literal.js +5 -9
  75. package/lib/parser/long.d.ts +4 -4
  76. package/lib/parser/long.js +10 -14
  77. package/lib/parser/record.d.ts +3 -3
  78. package/lib/parser/record.js +20 -24
  79. package/lib/parser/resourceLocation.d.ts +2 -2
  80. package/lib/parser/resourceLocation.js +14 -18
  81. package/lib/parser/string.d.ts +5 -5
  82. package/lib/parser/string.js +36 -42
  83. package/lib/parser/symbol.d.ts +3 -3
  84. package/lib/parser/symbol.js +3 -7
  85. package/lib/parser/util.d.ts +5 -5
  86. package/lib/parser/util.js +38 -56
  87. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  88. package/lib/processor/ColorInfoProvider.js +6 -9
  89. package/lib/processor/InlayHintProvider.d.ts +2 -2
  90. package/lib/processor/InlayHintProvider.js +1 -2
  91. package/lib/processor/SignatureHelpProvider.d.ts +2 -2
  92. package/lib/processor/SignatureHelpProvider.js +1 -2
  93. package/lib/processor/checker/Checker.d.ts +2 -2
  94. package/lib/processor/checker/Checker.js +1 -5
  95. package/lib/processor/checker/builtin.d.ts +4 -4
  96. package/lib/processor/checker/builtin.js +19 -30
  97. package/lib/processor/checker/index.d.ts +2 -2
  98. package/lib/processor/checker/index.js +2 -31
  99. package/lib/processor/colorizer/Colorizer.d.ts +4 -4
  100. package/lib/processor/colorizer/Colorizer.js +8 -11
  101. package/lib/processor/colorizer/builtin.d.ts +3 -3
  102. package/lib/processor/colorizer/builtin.js +33 -46
  103. package/lib/processor/colorizer/index.d.ts +2 -2
  104. package/lib/processor/colorizer/index.js +2 -31
  105. package/lib/processor/completer/Completer.d.ts +4 -4
  106. package/lib/processor/completer/Completer.js +14 -33
  107. package/lib/processor/completer/builtin.d.ts +7 -7
  108. package/lib/processor/completer/builtin.js +46 -62
  109. package/lib/processor/completer/index.d.ts +2 -2
  110. package/lib/processor/completer/index.js +2 -31
  111. package/lib/processor/formatter/Formatter.d.ts +2 -2
  112. package/lib/processor/formatter/Formatter.js +2 -7
  113. package/lib/processor/formatter/builtin.d.ts +3 -3
  114. package/lib/processor/formatter/builtin.js +22 -36
  115. package/lib/processor/formatter/index.d.ts +2 -2
  116. package/lib/processor/formatter/index.js +2 -31
  117. package/lib/processor/index.d.ts +9 -9
  118. package/lib/processor/index.js +9 -25
  119. package/lib/processor/linter/Linter.d.ts +2 -2
  120. package/lib/processor/linter/Linter.js +1 -2
  121. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  122. package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
  123. package/lib/processor/linter/builtin.d.ts +3 -3
  124. package/lib/processor/linter/builtin.js +19 -26
  125. package/lib/processor/linter/index.d.ts +2 -2
  126. package/lib/processor/linter/index.js +2 -31
  127. package/lib/processor/util.d.ts +2 -2
  128. package/lib/processor/util.js +4 -9
  129. package/lib/service/CacheService.d.ts +6 -6
  130. package/lib/service/CacheService.js +32 -56
  131. package/lib/service/Config.d.ts +11 -12
  132. package/lib/service/Config.js +50 -45
  133. package/lib/service/Context.d.ts +13 -13
  134. package/lib/service/Context.js +29 -32
  135. package/lib/service/Dependency.js +2 -5
  136. package/lib/service/Downloader.d.ts +10 -40
  137. package/lib/service/Downloader.js +37 -110
  138. package/lib/service/ErrorReporter.d.ts +2 -2
  139. package/lib/service/ErrorReporter.js +10 -14
  140. package/lib/service/FileService.d.ts +16 -14
  141. package/lib/service/FileService.js +55 -92
  142. package/lib/service/Hover.d.ts +2 -2
  143. package/lib/service/Hover.js +4 -7
  144. package/lib/service/Logger.js +2 -5
  145. package/lib/service/MetaRegistry.d.ts +12 -12
  146. package/lib/service/MetaRegistry.js +62 -73
  147. package/lib/service/Operations.js +3 -9
  148. package/lib/service/Profiler.d.ts +1 -1
  149. package/lib/service/Profiler.js +25 -41
  150. package/lib/service/Project.d.ts +47 -51
  151. package/lib/service/Project.js +199 -239
  152. package/lib/service/Service.d.ts +17 -27
  153. package/lib/service/Service.js +37 -43
  154. package/lib/service/SymbolLocations.d.ts +3 -3
  155. package/lib/service/SymbolLocations.js +4 -7
  156. package/lib/service/SymbolRegistrar.d.ts +1 -1
  157. package/lib/service/SymbolRegistrar.js +1 -2
  158. package/lib/service/fileUtil.d.ts +15 -45
  159. package/lib/service/fileUtil.js +38 -143
  160. package/lib/service/index.d.ts +17 -17
  161. package/lib/service/index.js +17 -35
  162. package/lib/source/IndexMap.d.ts +1 -1
  163. package/lib/source/IndexMap.js +7 -10
  164. package/lib/source/LanguageError.d.ts +2 -2
  165. package/lib/source/LanguageError.js +2 -5
  166. package/lib/source/Location.d.ts +3 -3
  167. package/lib/source/Location.js +6 -9
  168. package/lib/source/Offset.d.ts +1 -1
  169. package/lib/source/Offset.js +4 -7
  170. package/lib/source/Position.js +2 -5
  171. package/lib/source/PositionRange.d.ts +2 -2
  172. package/lib/source/PositionRange.js +14 -17
  173. package/lib/source/Range.d.ts +1 -1
  174. package/lib/source/Range.js +7 -10
  175. package/lib/source/Source.d.ts +3 -3
  176. package/lib/source/Source.js +28 -29
  177. package/lib/source/index.d.ts +8 -8
  178. package/lib/source/index.js +8 -24
  179. package/lib/symbol/Symbol.d.ts +2 -2
  180. package/lib/symbol/Symbol.js +49 -65
  181. package/lib/symbol/SymbolUtil.d.ts +22 -25
  182. package/lib/symbol/SymbolUtil.js +150 -151
  183. package/lib/symbol/UriBinder.d.ts +1 -1
  184. package/lib/symbol/UriBinder.js +1 -2
  185. package/lib/symbol/index.d.ts +3 -3
  186. package/lib/symbol/index.js +3 -19
  187. package/package.json +7 -4
@@ -1,7 +1,7 @@
1
- import type { IntegerNode } from '../node';
2
- import type { ParserContext } from '../service';
3
- import { Source } from '../source';
4
- import type { InfallibleParser, Parser } from './Parser';
1
+ import type { IntegerNode } from '../node/index.js';
2
+ import type { ParserContext } from '../service/index.js';
3
+ import { Source } from '../source/index.js';
4
+ import type { InfallibleParser, Parser } from './Parser.js';
5
5
  interface OptionsBase {
6
6
  pattern: RegExp;
7
7
  /**
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.integer = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- const Parser_1 = require("./Parser");
1
+ import { localize } from '@spyglassmc/locales';
2
+ import { Range, Source } from '../source/index.js';
3
+ import { Failure } from './Parser.js';
7
4
  const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
8
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
5
+ ctx.err.report(localize('expected', localize('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
9
6
  };
10
- function integer(options) {
7
+ export function integer(options) {
11
8
  return (src, ctx) => {
12
9
  const ans = {
13
10
  type: 'integer',
14
- range: source_1.Range.create(src),
11
+ range: Range.create(src),
15
12
  value: 0,
16
13
  };
17
14
  if (src.peek() === '-' || src.peek() === '+') {
18
15
  src.skip();
19
16
  }
20
- while (src.canRead() && source_1.Source.isDigit(src.peek())) {
17
+ while (src.canRead() && Source.isDigit(src.peek())) {
21
18
  src.skip();
22
19
  }
23
20
  ans.range.end = src.cursor;
@@ -28,12 +25,12 @@ function integer(options) {
28
25
  }
29
26
  if (!raw) {
30
27
  if (options.failsOnEmpty) {
31
- return Parser_1.Failure;
28
+ return Failure;
32
29
  }
33
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('integer')), ans);
30
+ ctx.err.report(localize('expected', localize('integer')), ans);
34
31
  }
35
32
  else if (!options.pattern.test(raw) || isOnlySign) {
36
- ctx.err.report((0, locales_1.localize)('parser.integer.illegal', options.pattern), ans);
33
+ ctx.err.report(localize('parser.integer.illegal', options.pattern), ans);
37
34
  }
38
35
  else if ((options.min !== undefined && ans.value < options.min) || (options.max !== undefined && ans.value > options.max)) {
39
36
  const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
@@ -42,5 +39,4 @@ function integer(options) {
42
39
  return ans;
43
40
  };
44
41
  }
45
- exports.integer = integer;
46
42
  //# sourceMappingURL=integer.js.map
@@ -1,5 +1,5 @@
1
- import type { AstNode, ListNode } from '../node';
2
- import type { InfallibleParser, Parser } from './Parser';
1
+ import type { AstNode, ListNode } from '../node/index.js';
2
+ import type { InfallibleParser, Parser } from './Parser.js';
3
3
  /** @internal For test only */
4
4
  export interface Options<V extends AstNode> {
5
5
  start: string;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.list = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- const Parser_1 = require("./Parser");
7
- const util_1 = require("./util");
8
- function list({ start, value, sep, trailingSep, end }) {
1
+ import { localeQuote, localize } from '@spyglassmc/locales';
2
+ import { Range } from '../source/index.js';
3
+ import { Failure } from './Parser.js';
4
+ import { attempt } from './util.js';
5
+ export function list({ start, value, sep, trailingSep, end }) {
9
6
  return (src, ctx) => {
10
7
  const ans = {
11
8
  type: 'list',
12
- range: source_1.Range.create(src),
9
+ range: Range.create(src),
13
10
  children: [],
14
11
  };
15
12
  if (src.trySkip(start)) {
@@ -21,13 +18,13 @@ function list({ start, value, sep, trailingSep, end }) {
21
18
  let valueNode;
22
19
  // Item sep of the last item.
23
20
  if (requiresValueSep && !hasValueSep) {
24
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(sep)), src);
21
+ ctx.err.report(localize('expected', localeQuote(sep)), src);
25
22
  }
26
23
  // Value.
27
24
  src.skipWhitespace();
28
- const { result, endCursor, updateSrcAndCtx } = (0, util_1.attempt)(value, src, ctx);
29
- if (result === Parser_1.Failure || endCursor === src.cursor) {
30
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('parser.list.value')), source_1.Range.create(src, () => src.skipUntilOrEnd(sep, end, '\r', '\n')));
25
+ const { result, endCursor, updateSrcAndCtx } = attempt(value, src, ctx);
26
+ if (result === Failure || endCursor === src.cursor) {
27
+ ctx.err.report(localize('expected', localize('parser.list.value')), Range.create(src, () => src.skipUntilOrEnd(sep, end, '\r', '\n')));
31
28
  }
32
29
  else {
33
30
  updateSrcAndCtx();
@@ -38,12 +35,12 @@ function list({ start, value, sep, trailingSep, end }) {
38
35
  src.skipWhitespace();
39
36
  requiresValueSep = true;
40
37
  if (hasValueSep = src.peek(sep.length) === sep) {
41
- sepRange = source_1.Range.create(src, () => src.skip(sep.length));
38
+ sepRange = Range.create(src, () => src.skip(sep.length));
42
39
  }
43
40
  // Create item.
44
41
  ans.children.push({
45
42
  type: 'item',
46
- range: source_1.Range.create(itemStart, src),
43
+ range: Range.create(itemStart, src),
47
44
  ...valueNode ? { children: [valueNode] } : {},
48
45
  value: valueNode,
49
46
  sep: sepRange,
@@ -52,19 +49,18 @@ function list({ start, value, sep, trailingSep, end }) {
52
49
  }
53
50
  // Trailing item sep.
54
51
  if (hasValueSep && !trailingSep) {
55
- ctx.err.report((0, locales_1.localize)('parser.list.trailing-sep'), ans.children[ans.children.length - 1].sep);
52
+ ctx.err.report(localize('parser.list.trailing-sep'), ans.children[ans.children.length - 1].sep);
56
53
  }
57
54
  // End.
58
55
  if (!src.trySkip(end)) {
59
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(end)), src);
56
+ ctx.err.report(localize('expected', localeQuote(end)), src);
60
57
  }
61
58
  }
62
59
  else {
63
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(start)), src);
60
+ ctx.err.report(localize('expected', localeQuote(start)), src);
64
61
  }
65
62
  ans.range.end = src.cursor;
66
63
  return ans;
67
64
  };
68
65
  }
69
- exports.list = list;
70
66
  //# sourceMappingURL=list.js.map
@@ -1,5 +1,5 @@
1
- import type { LiteralNode, LiteralOptions } from '../node/LiteralNode';
2
- import type { InfallibleParser } from './Parser';
1
+ import type { LiteralNode, LiteralOptions } from '../node/LiteralNode.js';
2
+ import type { InfallibleParser } from './Parser.js';
3
3
  export declare function literal(...pool: string[]): InfallibleParser<LiteralNode>;
4
4
  export declare function literal(options: LiteralOptions): InfallibleParser<LiteralNode>;
5
5
  //# sourceMappingURL=literal.d.ts.map
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.literal = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- function literal(...param) {
1
+ import { localize } from '@spyglassmc/locales';
2
+ import { Range } from '../source/index.js';
3
+ export function literal(...param) {
7
4
  const options = getOptions(param);
8
5
  return (src, ctx) => {
9
6
  const ans = {
10
7
  type: 'literal',
11
- range: source_1.Range.create(src),
8
+ range: Range.create(src),
12
9
  options,
13
10
  value: '',
14
11
  };
@@ -19,11 +16,10 @@ function literal(...param) {
19
16
  return ans;
20
17
  }
21
18
  }
22
- ctx.err.report((0, locales_1.localize)('expected', options.pool), ans);
19
+ ctx.err.report(localize('expected', options.pool), ans);
23
20
  return ans;
24
21
  };
25
22
  }
26
- exports.literal = literal;
27
23
  function getOptions(param) {
28
24
  let ans;
29
25
  if (typeof param[0] === 'object') {
@@ -1,7 +1,7 @@
1
- import type { LongNode } from '../node';
2
- import type { ParserContext } from '../service';
3
- import { Source } from '../source';
4
- import type { InfallibleParser, Parser } from './Parser';
1
+ import type { LongNode } from '../node/index.js';
2
+ import type { ParserContext } from '../service/index.js';
3
+ import { Source } from '../source/index.js';
4
+ import type { InfallibleParser, Parser } from './Parser.js';
5
5
  interface OptionsBase {
6
6
  pattern: RegExp;
7
7
  /**
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.long = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- const Parser_1 = require("./Parser");
1
+ import { localize } from '@spyglassmc/locales';
2
+ import { Range, Source } from '../source/index.js';
3
+ import { Failure } from './Parser.js';
7
4
  const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
8
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
5
+ ctx.err.report(localize('expected', localize('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
9
6
  };
10
- function long(options) {
7
+ export function long(options) {
11
8
  return (src, ctx) => {
12
9
  const ans = {
13
10
  type: 'long',
14
- range: source_1.Range.create(src),
11
+ range: Range.create(src),
15
12
  value: 0n,
16
13
  };
17
14
  if (src.peek() === '-' || src.peek() === '+') {
18
15
  src.skip();
19
16
  }
20
- while (src.canRead() && source_1.Source.isDigit(src.peek())) {
17
+ while (src.canRead() && Source.isDigit(src.peek())) {
21
18
  src.skip();
22
19
  }
23
20
  ans.range.end = src.cursor;
@@ -32,12 +29,12 @@ function long(options) {
32
29
  }
33
30
  if (!raw) {
34
31
  if (options.failsOnEmpty) {
35
- return Parser_1.Failure;
32
+ return Failure;
36
33
  }
37
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('long')), ans);
34
+ ctx.err.report(localize('expected', localize('long')), ans);
38
35
  }
39
36
  else if (!options.pattern.test(raw) || isOnlySign) {
40
- ctx.err.report((0, locales_1.localize)('parser.long.illegal', options.pattern), ans);
37
+ ctx.err.report(localize('parser.long.illegal', options.pattern), ans);
41
38
  }
42
39
  else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
43
40
  const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
@@ -46,5 +43,4 @@ function long(options) {
46
43
  return ans;
47
44
  };
48
45
  }
49
- exports.long = long;
50
46
  //# sourceMappingURL=long.js.map
@@ -1,6 +1,6 @@
1
- import type { AstNode } from '../node';
2
- import type { RecordNode } from '../node/RecordNode';
3
- import type { InfallibleParser, Parser } from './Parser';
1
+ import type { AstNode } from '../node/index.js';
2
+ import type { RecordNode } from '../node/RecordNode.js';
3
+ import type { InfallibleParser, Parser } from './Parser.js';
4
4
  /** @internal For test only */
5
5
  export interface Options<K extends AstNode, V extends AstNode> {
6
6
  start: string;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.record = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- const Parser_1 = require("./Parser");
7
- const util_1 = require("./util");
1
+ import { localeQuote, localize } from '@spyglassmc/locales';
2
+ import { Range } from '../source/index.js';
3
+ import { Failure } from './Parser.js';
4
+ import { attempt } from './util.js';
8
5
  /**
9
6
  * @returns A parser that parses something coming in a key-value pair form. e.g. SNBT objects, entity selector arguments.
10
7
  */
11
- function record({ start, pair, end }) {
8
+ export function record({ start, pair, end }) {
12
9
  return (src, ctx) => {
13
10
  const ans = {
14
11
  type: 'record',
15
- range: source_1.Range.create(src),
12
+ range: Range.create(src),
16
13
  children: [],
17
14
  };
18
15
  if (src.trySkip(start)) {
@@ -25,13 +22,13 @@ function record({ start, pair, end }) {
25
22
  let value;
26
23
  // Pair end of the last pair.
27
24
  if (requiresPairEnd && !hasPairEnd) {
28
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(pair.end)), src);
25
+ ctx.err.report(localize('expected', localeQuote(pair.end)), src);
29
26
  }
30
27
  // Key.
31
28
  const keyStart = src.cursor;
32
- const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd } = (0, util_1.attempt)(pair.key, src, ctx);
33
- if (keyResult === Parser_1.Failure || (keyEnd - keyStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
34
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('parser.record.key')), source_1.Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
29
+ const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd } = attempt(pair.key, src, ctx);
30
+ if (keyResult === Failure || (keyEnd - keyStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
31
+ ctx.err.report(localize('expected', localize('parser.record.key')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
35
32
  }
36
33
  else {
37
34
  updateForKey();
@@ -41,18 +38,18 @@ function record({ start, pair, end }) {
41
38
  let sepCharRange = undefined;
42
39
  src.skipWhitespace();
43
40
  if (src.peek(pair.sep.length) === pair.sep) {
44
- sepCharRange = source_1.Range.create(src, () => src.skip(pair.sep.length));
41
+ sepCharRange = Range.create(src, () => src.skip(pair.sep.length));
45
42
  }
46
43
  else {
47
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(pair.sep)), src);
44
+ ctx.err.report(localize('expected', localeQuote(pair.sep)), src);
48
45
  }
49
46
  // Value.
50
47
  src.skipWhitespace();
51
48
  const valueParser = typeof pair.value === 'function' ? pair.value : pair.value.get(ans, key);
52
49
  const valueStart = src.cursor;
53
- const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd } = (0, util_1.attempt)(valueParser, src, ctx);
54
- if (valueResult === Parser_1.Failure || (valueEnd - valueStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
55
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('parser.record.value')), source_1.Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
50
+ const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd } = attempt(valueParser, src, ctx);
51
+ if (valueResult === Failure || (valueEnd - valueStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
52
+ ctx.err.report(localize('expected', localize('parser.record.value')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
56
53
  }
57
54
  else {
58
55
  updateForValue();
@@ -63,12 +60,12 @@ function record({ start, pair, end }) {
63
60
  src.skipWhitespace();
64
61
  requiresPairEnd = true;
65
62
  if (hasPairEnd = src.peek(pair.end.length) === pair.end) {
66
- endCharRange = source_1.Range.create(src, () => src.skip(pair.end.length));
63
+ endCharRange = Range.create(src, () => src.skip(pair.end.length));
67
64
  }
68
65
  // Create pair.
69
66
  ans.children.push({
70
67
  type: 'pair',
71
- range: source_1.Range.create(pairStart, src),
68
+ range: Range.create(pairStart, src),
72
69
  ...(key || value) ? { children: [key, value].filter(v => !!v) } : {},
73
70
  key,
74
71
  sep: sepCharRange,
@@ -79,19 +76,18 @@ function record({ start, pair, end }) {
79
76
  }
80
77
  // Trailing pair end.
81
78
  if (hasPairEnd && !pair.trailingEnd) {
82
- ctx.err.report((0, locales_1.localize)('parser.record.trailing-end'), ans.children[ans.children.length - 1].end);
79
+ ctx.err.report(localize('parser.record.trailing-end'), ans.children[ans.children.length - 1].end);
83
80
  }
84
81
  // End.
85
82
  if (!src.trySkip(end)) {
86
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(end)), src);
83
+ ctx.err.report(localize('expected', localeQuote(end)), src);
87
84
  }
88
85
  }
89
86
  else {
90
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(start)), src);
87
+ ctx.err.report(localize('expected', localeQuote(start)), src);
91
88
  }
92
89
  ans.range.end = src.cursor;
93
90
  return ans;
94
91
  };
95
92
  }
96
- exports.record = record;
97
93
  //# sourceMappingURL=record.js.map
@@ -1,4 +1,4 @@
1
- import type { ResourceLocationNode, ResourceLocationOptions } from '../node';
2
- import type { InfallibleParser } from './Parser';
1
+ import type { ResourceLocationNode, ResourceLocationOptions } from '../node/index.js';
2
+ import type { InfallibleParser } from './Parser.js';
3
3
  export declare function resourceLocation(options: ResourceLocationOptions): InfallibleParser<ResourceLocationNode>;
4
4
  //# sourceMappingURL=resourceLocation.d.ts.map
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resourceLocation = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const common_1 = require("../common");
6
- const source_1 = require("../source");
1
+ import { arrayToMessage, localize } from '@spyglassmc/locales';
2
+ import { ResourceLocation } from '../common/index.js';
3
+ import { Range } from '../source/index.js';
7
4
  const Terminators = new Set([' ', '\r', '\n', '=', ',', '"', "'", '{', '}', '[', ']', '(', ')', ';']);
8
5
  const LegalCharacters = new Set([
9
6
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
10
7
  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
11
8
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '.',
12
9
  ]);
13
- function resourceLocation(options) {
10
+ export function resourceLocation(options) {
14
11
  return (src, ctx) => {
15
12
  const ans = {
16
13
  type: 'resource_location',
17
- range: source_1.Range.create(src),
14
+ range: Range.create(src),
18
15
  options,
19
16
  };
20
- if (src.trySkip(common_1.ResourceLocation.TagPrefix)) {
17
+ if (src.trySkip(ResourceLocation.TagPrefix)) {
21
18
  ans.isTag = true;
22
19
  }
23
20
  const start = src.cursor;
@@ -27,15 +24,15 @@ function resourceLocation(options) {
27
24
  const raw = src.sliceToCursor(start);
28
25
  ans.range.end = src.cursor;
29
26
  if (raw.length === 0) {
30
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('resource-location')), ans);
27
+ ctx.err.report(localize('expected', localize('resource-location')), ans);
31
28
  }
32
29
  else {
33
- const sepIndex = raw.indexOf(options.namespacePathSep ?? common_1.ResourceLocation.NamespacePathSep);
30
+ const sepIndex = raw.indexOf(options.namespacePathSep ?? ResourceLocation.NamespacePathSep);
34
31
  if (sepIndex >= 0) {
35
32
  ans.namespace = raw.slice(0, sepIndex);
36
33
  }
37
34
  const rawPath = raw.slice(sepIndex + 1);
38
- ans.path = rawPath.split(common_1.ResourceLocation.PathSep);
35
+ ans.path = rawPath.split(ResourceLocation.PathSep);
39
36
  // Check characters.
40
37
  /* istanbul ignore next */
41
38
  const illegalChars = [...new Set([
@@ -43,17 +40,17 @@ function resourceLocation(options) {
43
40
  ...[...rawPath].filter(c => c !== '/' && !LegalCharacters.has(c)),
44
41
  ])];
45
42
  if (illegalChars.length) {
46
- ctx.err.report((0, locales_1.localize)('parser.resource-location.illegal', (0, locales_1.arrayToMessage)(illegalChars, true, 'and')), ans);
43
+ ctx.err.report(localize('parser.resource-location.illegal', arrayToMessage(illegalChars, true, 'and')), ans);
47
44
  }
48
45
  if (ans.isTag && !options.allowTag) {
49
- ctx.err.report((0, locales_1.localize)('parser.resource-location.tag-diallowed'), ans);
46
+ ctx.err.report(localize('parser.resource-location.tag-diallowed'), ans);
50
47
  }
51
48
  if (!ans.namespace && options.isPredicate) {
52
- ctx.err.report((0, locales_1.localize)('parser.resource-location.namespace-expected'), ans);
49
+ ctx.err.report(localize('parser.resource-location.namespace-expected'), ans);
53
50
  }
54
51
  if (options.category) {
55
- const fullRaw = common_1.ResourceLocation.lengthen(options.namespacePathSep === '.'
56
- ? raw.replace('.', common_1.ResourceLocation.NamespacePathSep)
52
+ const fullRaw = ResourceLocation.lengthen(options.namespacePathSep === '.'
53
+ ? raw.replace('.', ResourceLocation.NamespacePathSep)
57
54
  : raw);
58
55
  ctx.symbols
59
56
  .query(ctx.doc, ans.isTag ? `tag/${options.category}` : options.category, fullRaw)
@@ -63,5 +60,4 @@ function resourceLocation(options) {
63
60
  return ans;
64
61
  };
65
62
  }
66
- exports.resourceLocation = resourceLocation;
67
63
  //# sourceMappingURL=resourceLocation.js.map
@@ -1,8 +1,8 @@
1
- import type { StringNode, StringOptions } from '../node';
2
- import type { InfallibleParser } from '../parser';
3
- import type { ParserContext } from '../service';
4
- import type { IndexMap } from '../source';
5
- import type { Parser, Result, Returnable } from './Parser';
1
+ import type { StringNode, StringOptions } from '../node/index.js';
2
+ import type { InfallibleParser } from '../parser/index.js';
3
+ import type { ParserContext } from '../service/index.js';
4
+ import type { IndexMap } from '../source/index.js';
5
+ import type { Parser, Result, Returnable } from './Parser.js';
6
6
  export declare function string(options: StringOptions): InfallibleParser<StringNode>;
7
7
  export declare function parseStringValue<T extends Returnable>(parser: Parser<T>, value: string, map: IndexMap, ctx: ParserContext): Result<T>;
8
8
  export declare const BrigadierUnquotableCharacters: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "_", ".", "+", "-"];