@spyglassmc/core 0.1.0 → 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 (196) 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.d.ts +21 -0
  5. package/lib/common/TwoWayMap.js +69 -0
  6. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  7. package/lib/common/externals/BrowserExternals.js +191 -0
  8. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  9. package/lib/common/externals/NodeJsExternals.js +151 -0
  10. package/lib/common/externals/downloader.d.ts +31 -0
  11. package/lib/common/externals/downloader.js +32 -0
  12. package/lib/common/externals/index.d.ts +96 -0
  13. package/lib/common/externals/index.js +2 -0
  14. package/lib/common/index.d.ts +2 -1
  15. package/lib/common/index.js +2 -13
  16. package/lib/common/util.d.ts +17 -34
  17. package/lib/common/util.js +32 -113
  18. package/lib/index.d.ts +7 -7
  19. package/lib/index.js +7 -19
  20. package/lib/node/AstNode.d.ts +3 -3
  21. package/lib/node/AstNode.js +10 -16
  22. package/lib/node/BooleanNode.d.ts +2 -2
  23. package/lib/node/BooleanNode.js +4 -7
  24. package/lib/node/CommentNode.d.ts +1 -1
  25. package/lib/node/CommentNode.js +2 -5
  26. package/lib/node/ErrorNode.d.ts +1 -1
  27. package/lib/node/ErrorNode.js +2 -5
  28. package/lib/node/FileNode.d.ts +3 -3
  29. package/lib/node/FileNode.js +2 -5
  30. package/lib/node/FloatNode.d.ts +2 -2
  31. package/lib/node/FloatNode.js +4 -7
  32. package/lib/node/IntegerNode.d.ts +2 -2
  33. package/lib/node/IntegerNode.js +4 -7
  34. package/lib/node/ListNode.d.ts +2 -2
  35. package/lib/node/ListNode.js +2 -5
  36. package/lib/node/LiteralNode.d.ts +4 -4
  37. package/lib/node/LiteralNode.js +5 -8
  38. package/lib/node/LongNode.d.ts +2 -2
  39. package/lib/node/LongNode.js +4 -7
  40. package/lib/node/RecordNode.d.ts +2 -2
  41. package/lib/node/RecordNode.js +2 -5
  42. package/lib/node/ResourceLocationNode.d.ts +6 -8
  43. package/lib/node/ResourceLocationNode.js +9 -12
  44. package/lib/node/Sequence.d.ts +4 -3
  45. package/lib/node/Sequence.js +4 -6
  46. package/lib/node/StringNode.d.ts +5 -5
  47. package/lib/node/StringNode.js +9 -12
  48. package/lib/node/SymbolNode.d.ts +4 -4
  49. package/lib/node/SymbolNode.js +5 -8
  50. package/lib/node/index.d.ts +15 -15
  51. package/lib/node/index.js +15 -27
  52. package/lib/nodejs.d.ts +2 -0
  53. package/lib/nodejs.js +2 -0
  54. package/lib/parser/Parser.d.ts +3 -3
  55. package/lib/parser/Parser.js +1 -4
  56. package/lib/parser/boolean.d.ts +2 -2
  57. package/lib/parser/boolean.js +3 -6
  58. package/lib/parser/comment.d.ts +2 -2
  59. package/lib/parser/comment.js +5 -9
  60. package/lib/parser/empty.d.ts +1 -1
  61. package/lib/parser/empty.js +1 -5
  62. package/lib/parser/error.d.ts +2 -2
  63. package/lib/parser/error.js +5 -9
  64. package/lib/parser/file.d.ts +3 -3
  65. package/lib/parser/file.js +9 -13
  66. package/lib/parser/float.d.ts +4 -4
  67. package/lib/parser/float.js +12 -16
  68. package/lib/parser/index.d.ts +16 -16
  69. package/lib/parser/index.js +16 -34
  70. package/lib/parser/integer.d.ts +4 -4
  71. package/lib/parser/integer.js +10 -14
  72. package/lib/parser/list.d.ts +2 -2
  73. package/lib/parser/list.js +15 -19
  74. package/lib/parser/literal.d.ts +2 -2
  75. package/lib/parser/literal.js +5 -9
  76. package/lib/parser/long.d.ts +4 -4
  77. package/lib/parser/long.js +10 -14
  78. package/lib/parser/record.d.ts +3 -3
  79. package/lib/parser/record.js +20 -24
  80. package/lib/parser/resourceLocation.d.ts +2 -2
  81. package/lib/parser/resourceLocation.js +14 -18
  82. package/lib/parser/string.d.ts +7 -7
  83. package/lib/parser/string.js +40 -44
  84. package/lib/parser/symbol.d.ts +3 -3
  85. package/lib/parser/symbol.js +3 -7
  86. package/lib/parser/util.d.ts +30 -12
  87. package/lib/parser/util.js +78 -63
  88. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  89. package/lib/processor/ColorInfoProvider.js +6 -9
  90. package/lib/processor/InlayHintProvider.d.ts +2 -2
  91. package/lib/processor/InlayHintProvider.js +1 -2
  92. package/lib/processor/SignatureHelpProvider.d.ts +2 -2
  93. package/lib/processor/SignatureHelpProvider.js +1 -2
  94. package/lib/processor/checker/Checker.d.ts +2 -2
  95. package/lib/processor/checker/Checker.js +1 -5
  96. package/lib/processor/checker/builtin.d.ts +5 -4
  97. package/lib/processor/checker/builtin.js +26 -28
  98. package/lib/processor/checker/index.d.ts +2 -2
  99. package/lib/processor/checker/index.js +2 -27
  100. package/lib/processor/colorizer/Colorizer.d.ts +4 -4
  101. package/lib/processor/colorizer/Colorizer.js +8 -11
  102. package/lib/processor/colorizer/builtin.d.ts +3 -3
  103. package/lib/processor/colorizer/builtin.js +33 -46
  104. package/lib/processor/colorizer/index.d.ts +2 -2
  105. package/lib/processor/colorizer/index.js +2 -27
  106. package/lib/processor/completer/Completer.d.ts +4 -4
  107. package/lib/processor/completer/Completer.js +14 -33
  108. package/lib/processor/completer/builtin.d.ts +7 -7
  109. package/lib/processor/completer/builtin.js +58 -74
  110. package/lib/processor/completer/index.d.ts +2 -2
  111. package/lib/processor/completer/index.js +2 -27
  112. package/lib/processor/formatter/Formatter.d.ts +2 -2
  113. package/lib/processor/formatter/Formatter.js +2 -7
  114. package/lib/processor/formatter/builtin.d.ts +3 -3
  115. package/lib/processor/formatter/builtin.js +22 -36
  116. package/lib/processor/formatter/index.d.ts +2 -2
  117. package/lib/processor/formatter/index.js +2 -27
  118. package/lib/processor/index.d.ts +9 -9
  119. package/lib/processor/index.js +9 -21
  120. package/lib/processor/linter/Linter.d.ts +2 -2
  121. package/lib/processor/linter/Linter.js +1 -2
  122. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  123. package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
  124. package/lib/processor/linter/builtin.d.ts +3 -3
  125. package/lib/processor/linter/builtin.js +19 -31
  126. package/lib/processor/linter/index.d.ts +2 -2
  127. package/lib/processor/linter/index.js +2 -27
  128. package/lib/processor/util.d.ts +2 -2
  129. package/lib/processor/util.js +4 -9
  130. package/lib/service/CacheService.d.ts +6 -6
  131. package/lib/service/CacheService.js +38 -48
  132. package/lib/service/Config.d.ts +17 -16
  133. package/lib/service/Config.js +56 -51
  134. package/lib/service/Context.d.ts +14 -14
  135. package/lib/service/Context.js +30 -32
  136. package/lib/service/Dependency.js +2 -5
  137. package/lib/service/Downloader.d.ts +10 -39
  138. package/lib/service/Downloader.js +37 -106
  139. package/lib/service/ErrorReporter.d.ts +2 -2
  140. package/lib/service/ErrorReporter.js +11 -15
  141. package/lib/service/FileService.d.ts +41 -14
  142. package/lib/service/FileService.js +107 -81
  143. package/lib/service/Hover.d.ts +2 -2
  144. package/lib/service/Hover.js +4 -7
  145. package/lib/service/Logger.js +2 -5
  146. package/lib/service/MetaRegistry.d.ts +12 -12
  147. package/lib/service/MetaRegistry.js +62 -73
  148. package/lib/service/Operations.js +3 -9
  149. package/lib/service/Profiler.d.ts +1 -1
  150. package/lib/service/Profiler.js +25 -41
  151. package/lib/service/Project.d.ts +50 -51
  152. package/lib/service/Project.js +240 -238
  153. package/lib/service/Service.d.ts +19 -29
  154. package/lib/service/Service.js +57 -53
  155. package/lib/service/SymbolLocations.d.ts +3 -3
  156. package/lib/service/SymbolLocations.js +4 -7
  157. package/lib/service/SymbolRegistrar.d.ts +1 -1
  158. package/lib/service/SymbolRegistrar.js +1 -2
  159. package/lib/service/fileUtil.d.ts +21 -41
  160. package/lib/service/fileUtil.js +59 -129
  161. package/lib/service/index.d.ts +17 -17
  162. package/lib/service/index.js +17 -31
  163. package/lib/source/IndexMap.d.ts +1 -1
  164. package/lib/source/IndexMap.js +7 -10
  165. package/lib/source/LanguageError.d.ts +2 -2
  166. package/lib/source/LanguageError.js +3 -6
  167. package/lib/source/Location.d.ts +3 -3
  168. package/lib/source/Location.js +6 -9
  169. package/lib/source/Offset.d.ts +1 -1
  170. package/lib/source/Offset.js +4 -7
  171. package/lib/source/Position.js +2 -5
  172. package/lib/source/PositionRange.d.ts +2 -2
  173. package/lib/source/PositionRange.js +14 -17
  174. package/lib/source/Range.d.ts +1 -1
  175. package/lib/source/Range.js +7 -10
  176. package/lib/source/Source.d.ts +12 -4
  177. package/lib/source/Source.js +84 -29
  178. package/lib/source/index.d.ts +8 -8
  179. package/lib/source/index.js +8 -20
  180. package/lib/symbol/Symbol.d.ts +15 -15
  181. package/lib/symbol/Symbol.js +53 -68
  182. package/lib/symbol/SymbolUtil.d.ts +23 -33
  183. package/lib/symbol/SymbolUtil.js +162 -163
  184. package/lib/symbol/UriBinder.d.ts +1 -1
  185. package/lib/symbol/UriBinder.js +1 -2
  186. package/lib/symbol/index.d.ts +3 -3
  187. package/lib/symbol/index.js +3 -15
  188. package/package.json +7 -4
  189. package/lib/common/Heap.d.ts +0 -1
  190. package/lib/common/Heap.js +0 -2
  191. package/lib/node/TableNode.d.ts +0 -17
  192. package/lib/node/TableNode.js +0 -11
  193. package/lib/parser/table.d.ts +0 -22
  194. package/lib/parser/table.js +0 -97
  195. package/lib/service/CommandExecutor.d.ts +0 -3
  196. package/lib/service/CommandExecutor.js +0 -7
@@ -1,27 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.float = 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)('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* Error */);
5
+ ctx.err.report(localize('expected', localize('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
9
6
  };
10
- function float(options) {
7
+ export function float(options) {
11
8
  return (src, ctx) => {
12
9
  const ans = {
13
10
  type: 'float',
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
  if (src.trySkip('.')) {
24
- while (src.canRead() && source_1.Source.isDigit(src.peek())) {
21
+ while (src.canRead() && Source.isDigit(src.peek())) {
25
22
  src.skip();
26
23
  }
27
24
  }
@@ -30,7 +27,7 @@ function float(options) {
30
27
  if (src.peek() === '-' || src.peek() === '+') {
31
28
  src.skip();
32
29
  }
33
- while (src.canRead() && source_1.Source.isDigit(src.peek())) {
30
+ while (src.canRead() && Source.isDigit(src.peek())) {
34
31
  src.skip();
35
32
  }
36
33
  }
@@ -39,12 +36,12 @@ function float(options) {
39
36
  ans.value = parseFloat(raw) || 0;
40
37
  if (!raw) {
41
38
  if (options.failsOnEmpty) {
42
- return Parser_1.Failure;
39
+ return Failure;
43
40
  }
44
- ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('float')), ans);
41
+ ctx.err.report(localize('expected', localize('float')), ans);
45
42
  }
46
43
  else if (!options.pattern.test(raw)) {
47
- ctx.err.report((0, locales_1.localize)('parser.float.illegal', options.pattern), ans);
44
+ ctx.err.report(localize('parser.float.illegal', options.pattern), ans);
48
45
  }
49
46
  else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
50
47
  const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
@@ -53,5 +50,4 @@ function float(options) {
53
50
  return ans;
54
51
  };
55
52
  }
56
- exports.float = float;
57
53
  //# sourceMappingURL=float.js.map
@@ -1,17 +1,17 @@
1
- export * from './boolean';
2
- export * from './comment';
3
- export * from './empty';
4
- export * from './error';
5
- export * from './file';
6
- export { float } from './float';
7
- export { integer } from './integer';
8
- export { list } from './list';
9
- export * from './literal';
10
- export { long } from './long';
11
- export * from './Parser';
12
- export { record } from './record';
13
- export * from './resourceLocation';
14
- export * from './string';
15
- export * from './symbol';
16
- export * from './util';
1
+ export * from './boolean.js';
2
+ export * from './comment.js';
3
+ export * from './empty.js';
4
+ export * from './error.js';
5
+ export * from './file.js';
6
+ export { float } from './float.js';
7
+ export { integer } from './integer.js';
8
+ export { list } from './list.js';
9
+ export * from './literal.js';
10
+ export { long } from './long.js';
11
+ export * from './Parser.js';
12
+ export { record } from './record.js';
13
+ export * from './resourceLocation.js';
14
+ export * from './string.js';
15
+ export * from './symbol.js';
16
+ export * from './util.js';
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,36 +1,18 @@
1
- "use strict";
2
1
  /* istanbul ignore file */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.record = exports.long = exports.list = exports.integer = exports.float = void 0;
15
- __exportStar(require("./boolean"), exports);
16
- __exportStar(require("./comment"), exports);
17
- __exportStar(require("./empty"), exports);
18
- __exportStar(require("./error"), exports);
19
- __exportStar(require("./file"), exports);
20
- var float_1 = require("./float");
21
- Object.defineProperty(exports, "float", { enumerable: true, get: function () { return float_1.float; } });
22
- var integer_1 = require("./integer");
23
- Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return integer_1.integer; } });
24
- var list_1 = require("./list");
25
- Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_1.list; } });
26
- __exportStar(require("./literal"), exports);
27
- var long_1 = require("./long");
28
- Object.defineProperty(exports, "long", { enumerable: true, get: function () { return long_1.long; } });
29
- __exportStar(require("./Parser"), exports);
30
- var record_1 = require("./record");
31
- Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
32
- __exportStar(require("./resourceLocation"), exports);
33
- __exportStar(require("./string"), exports);
34
- __exportStar(require("./symbol"), exports);
35
- __exportStar(require("./util"), exports);
2
+ export * from './boolean.js';
3
+ export * from './comment.js';
4
+ export * from './empty.js';
5
+ export * from './error.js';
6
+ export * from './file.js';
7
+ export { float } from './float.js';
8
+ export { integer } from './integer.js';
9
+ export { list } from './list.js';
10
+ export * from './literal.js';
11
+ export { long } from './long.js';
12
+ export * from './Parser.js';
13
+ export { record } from './record.js';
14
+ export * from './resourceLocation.js';
15
+ export * from './string.js';
16
+ export * from './symbol.js';
17
+ export * from './util.js';
36
18
  //# sourceMappingURL=index.js.map
@@ -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 /* 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 /* 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