@spyglassmc/core 0.1.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 (186) hide show
  1. package/README.md +10 -0
  2. package/lib/common/Heap.d.ts +1 -0
  3. package/lib/common/Heap.js +2 -0
  4. package/lib/common/index.d.ts +2 -0
  5. package/lib/common/index.js +14 -0
  6. package/lib/common/util.d.ts +120 -0
  7. package/lib/common/util.js +292 -0
  8. package/lib/index.d.ts +8 -0
  9. package/lib/index.js +20 -0
  10. package/lib/node/AstNode.d.ts +64 -0
  11. package/lib/node/AstNode.js +108 -0
  12. package/lib/node/BooleanNode.d.ts +13 -0
  13. package/lib/node/BooleanNode.js +20 -0
  14. package/lib/node/CommentNode.d.ts +12 -0
  15. package/lib/node/CommentNode.js +11 -0
  16. package/lib/node/ErrorNode.d.ts +8 -0
  17. package/lib/node/ErrorNode.js +12 -0
  18. package/lib/node/FileNode.d.ts +21 -0
  19. package/lib/node/FileNode.js +11 -0
  20. package/lib/node/FloatNode.d.ts +13 -0
  21. package/lib/node/FloatNode.js +21 -0
  22. package/lib/node/IntegerNode.d.ts +13 -0
  23. package/lib/node/IntegerNode.js +20 -0
  24. package/lib/node/ListNode.d.ts +15 -0
  25. package/lib/node/ListNode.js +11 -0
  26. package/lib/node/LiteralNode.d.ts +19 -0
  27. package/lib/node/LiteralNode.js +22 -0
  28. package/lib/node/LongNode.d.ts +13 -0
  29. package/lib/node/LongNode.js +20 -0
  30. package/lib/node/RecordNode.d.ts +20 -0
  31. package/lib/node/RecordNode.js +11 -0
  32. package/lib/node/ResourceLocationNode.d.ts +41 -0
  33. package/lib/node/ResourceLocationNode.js +65 -0
  34. package/lib/node/Sequence.d.ts +22 -0
  35. package/lib/node/Sequence.js +11 -0
  36. package/lib/node/StringNode.d.ts +63 -0
  37. package/lib/node/StringNode.js +43 -0
  38. package/lib/node/SymbolNode.d.ts +21 -0
  39. package/lib/node/SymbolNode.js +22 -0
  40. package/lib/node/TableNode.d.ts +17 -0
  41. package/lib/node/TableNode.js +11 -0
  42. package/lib/node/index.d.ts +16 -0
  43. package/lib/node/index.js +28 -0
  44. package/lib/parser/Parser.d.ts +16 -0
  45. package/lib/parser/Parser.js +5 -0
  46. package/lib/parser/boolean.d.ts +4 -0
  47. package/lib/parser/boolean.js +11 -0
  48. package/lib/parser/comment.d.ts +12 -0
  49. package/lib/parser/comment.js +34 -0
  50. package/lib/parser/empty.d.ts +3 -0
  51. package/lib/parser/empty.js +7 -0
  52. package/lib/parser/error.d.ts +8 -0
  53. package/lib/parser/error.js +22 -0
  54. package/lib/parser/file.d.ts +9 -0
  55. package/lib/parser/file.js +37 -0
  56. package/lib/parser/float.d.ts +33 -0
  57. package/lib/parser/float.js +57 -0
  58. package/lib/parser/index.d.ts +17 -0
  59. package/lib/parser/index.js +36 -0
  60. package/lib/parser/integer.d.ts +33 -0
  61. package/lib/parser/integer.js +46 -0
  62. package/lib/parser/list.d.ts +12 -0
  63. package/lib/parser/list.js +70 -0
  64. package/lib/parser/literal.d.ts +5 -0
  65. package/lib/parser/literal.js +41 -0
  66. package/lib/parser/long.d.ts +33 -0
  67. package/lib/parser/long.js +50 -0
  68. package/lib/parser/record.d.ts +22 -0
  69. package/lib/parser/record.js +97 -0
  70. package/lib/parser/resourceLocation.d.ts +4 -0
  71. package/lib/parser/resourceLocation.js +67 -0
  72. package/lib/parser/string.d.ts +18 -0
  73. package/lib/parser/string.js +129 -0
  74. package/lib/parser/symbol.d.ts +12 -0
  75. package/lib/parser/symbol.js +33 -0
  76. package/lib/parser/table.d.ts +22 -0
  77. package/lib/parser/table.js +97 -0
  78. package/lib/parser/util.d.ts +134 -0
  79. package/lib/parser/util.js +224 -0
  80. package/lib/processor/ColorInfoProvider.d.ts +87 -0
  81. package/lib/processor/ColorInfoProvider.js +141 -0
  82. package/lib/processor/InlayHintProvider.d.ts +8 -0
  83. package/lib/processor/InlayHintProvider.js +3 -0
  84. package/lib/processor/SignatureHelpProvider.d.ts +18 -0
  85. package/lib/processor/SignatureHelpProvider.js +3 -0
  86. package/lib/processor/checker/Checker.d.ts +7 -0
  87. package/lib/processor/checker/Checker.js +7 -0
  88. package/lib/processor/checker/builtin.d.ts +23 -0
  89. package/lib/processor/checker/builtin.js +83 -0
  90. package/lib/processor/checker/index.d.ts +3 -0
  91. package/lib/processor/checker/index.js +28 -0
  92. package/lib/processor/colorizer/Colorizer.d.ts +23 -0
  93. package/lib/processor/colorizer/Colorizer.js +70 -0
  94. package/lib/processor/colorizer/builtin.d.ts +17 -0
  95. package/lib/processor/colorizer/builtin.js +84 -0
  96. package/lib/processor/colorizer/index.d.ts +3 -0
  97. package/lib/processor/colorizer/index.js +28 -0
  98. package/lib/processor/completer/Completer.d.ts +75 -0
  99. package/lib/processor/completer/Completer.js +92 -0
  100. package/lib/processor/completer/builtin.d.ts +30 -0
  101. package/lib/processor/completer/builtin.js +172 -0
  102. package/lib/processor/completer/index.d.ts +3 -0
  103. package/lib/processor/completer/index.js +28 -0
  104. package/lib/processor/formatter/Formatter.d.ts +6 -0
  105. package/lib/processor/formatter/Formatter.js +19 -0
  106. package/lib/processor/formatter/builtin.d.ts +15 -0
  107. package/lib/processor/formatter/builtin.js +60 -0
  108. package/lib/processor/formatter/index.d.ts +3 -0
  109. package/lib/processor/formatter/index.js +28 -0
  110. package/lib/processor/index.d.ts +10 -0
  111. package/lib/processor/index.js +22 -0
  112. package/lib/processor/linter/Linter.d.ts +4 -0
  113. package/lib/processor/linter/Linter.js +3 -0
  114. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +4 -0
  115. package/lib/processor/linter/builtin/undeclaredSymbol.js +73 -0
  116. package/lib/processor/linter/builtin.d.ts +15 -0
  117. package/lib/processor/linter/builtin.js +120 -0
  118. package/lib/processor/linter/index.d.ts +3 -0
  119. package/lib/processor/linter/index.js +28 -0
  120. package/lib/processor/util.d.ts +17 -0
  121. package/lib/processor/util.js +32 -0
  122. package/lib/service/CacheService.d.ts +54 -0
  123. package/lib/service/CacheService.js +195 -0
  124. package/lib/service/CommandExecutor.d.ts +3 -0
  125. package/lib/service/CommandExecutor.js +7 -0
  126. package/lib/service/Config.d.ts +218 -0
  127. package/lib/service/Config.js +264 -0
  128. package/lib/service/Context.d.ts +143 -0
  129. package/lib/service/Context.js +143 -0
  130. package/lib/service/Dependency.d.ts +10 -0
  131. package/lib/service/Dependency.js +11 -0
  132. package/lib/service/Downloader.d.ts +67 -0
  133. package/lib/service/Downloader.js +185 -0
  134. package/lib/service/ErrorReporter.d.ts +27 -0
  135. package/lib/service/ErrorReporter.js +49 -0
  136. package/lib/service/FileService.d.ts +96 -0
  137. package/lib/service/FileService.js +224 -0
  138. package/lib/service/Hover.d.ts +10 -0
  139. package/lib/service/Hover.js +16 -0
  140. package/lib/service/Logger.d.ts +31 -0
  141. package/lib/service/Logger.js +30 -0
  142. package/lib/service/MetaRegistry.d.ts +106 -0
  143. package/lib/service/MetaRegistry.js +192 -0
  144. package/lib/service/Operations.d.ts +8 -0
  145. package/lib/service/Operations.js +26 -0
  146. package/lib/service/Profiler.d.ts +33 -0
  147. package/lib/service/Profiler.js +76 -0
  148. package/lib/service/Project.d.ts +173 -0
  149. package/lib/service/Project.js +593 -0
  150. package/lib/service/Service.d.ts +55 -0
  151. package/lib/service/Service.js +207 -0
  152. package/lib/service/SymbolLocations.d.ts +17 -0
  153. package/lib/service/SymbolLocations.js +16 -0
  154. package/lib/service/SymbolRegistrar.d.ts +5 -0
  155. package/lib/service/SymbolRegistrar.js +3 -0
  156. package/lib/service/fileUtil.d.ts +121 -0
  157. package/lib/service/fileUtil.js +268 -0
  158. package/lib/service/index.d.ts +18 -0
  159. package/lib/service/index.js +33 -0
  160. package/lib/source/IndexMap.d.ts +16 -0
  161. package/lib/source/IndexMap.js +46 -0
  162. package/lib/source/LanguageError.d.ts +27 -0
  163. package/lib/source/LanguageError.js +15 -0
  164. package/lib/source/Location.d.ts +19 -0
  165. package/lib/source/Location.js +25 -0
  166. package/lib/source/Offset.d.ts +13 -0
  167. package/lib/source/Offset.js +25 -0
  168. package/lib/source/Position.d.ts +23 -0
  169. package/lib/source/Position.js +43 -0
  170. package/lib/source/PositionRange.d.ts +38 -0
  171. package/lib/source/PositionRange.js +83 -0
  172. package/lib/source/Range.d.ts +68 -0
  173. package/lib/source/Range.js +155 -0
  174. package/lib/source/Source.d.ts +110 -0
  175. package/lib/source/Source.js +222 -0
  176. package/lib/source/index.d.ts +9 -0
  177. package/lib/source/index.js +21 -0
  178. package/lib/symbol/Symbol.d.ts +219 -0
  179. package/lib/symbol/Symbol.js +324 -0
  180. package/lib/symbol/SymbolUtil.d.ts +407 -0
  181. package/lib/symbol/SymbolUtil.js +880 -0
  182. package/lib/symbol/UriBinder.d.ts +3 -0
  183. package/lib/symbol/UriBinder.js +3 -0
  184. package/lib/symbol/index.d.ts +4 -0
  185. package/lib/symbol/index.js +16 -0
  186. package/package.json +41 -0
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./AstNode"), exports);
14
+ __exportStar(require("./BooleanNode"), exports);
15
+ __exportStar(require("./CommentNode"), exports);
16
+ __exportStar(require("./ErrorNode"), exports);
17
+ __exportStar(require("./FileNode"), exports);
18
+ __exportStar(require("./FloatNode"), exports);
19
+ __exportStar(require("./IntegerNode"), exports);
20
+ __exportStar(require("./ListNode"), exports);
21
+ __exportStar(require("./LiteralNode"), exports);
22
+ __exportStar(require("./LongNode"), exports);
23
+ __exportStar(require("./RecordNode"), exports);
24
+ __exportStar(require("./ResourceLocationNode"), exports);
25
+ __exportStar(require("./Sequence"), exports);
26
+ __exportStar(require("./StringNode"), exports);
27
+ __exportStar(require("./SymbolNode"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import type { AstNode } from '../node';
2
+ import type { ParserContext } from '../service';
3
+ import type { Source } from '../source';
4
+ /**
5
+ * A parser.
6
+ */
7
+ export declare type Parser<N extends Returnable = AstNode> = (this: void, src: Source, ctx: ParserContext) => Result<N>;
8
+ /**
9
+ * A parser that always succeeds.
10
+ */
11
+ export declare type InfallibleParser<N extends Returnable = AstNode> = (this: void, src: Source, ctx: ParserContext) => Success<N>;
12
+ export declare type Result<T extends Returnable> = Success<T> | typeof Failure;
13
+ export declare type Success<T extends Returnable> = T;
14
+ export declare const Failure: unique symbol;
15
+ export declare type Returnable = object | string | number | bigint | boolean | undefined;
16
+ //# sourceMappingURL=Parser.d.ts.map
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Failure = void 0;
4
+ exports.Failure = Symbol('Failure');
5
+ //# sourceMappingURL=Parser.js.map
@@ -0,0 +1,4 @@
1
+ import type { BooleanNode } from '../node/BooleanNode';
2
+ import type { InfallibleParser } from './Parser';
3
+ export declare const boolean: InfallibleParser<BooleanNode>;
4
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.boolean = void 0;
4
+ const literal_1 = require("./literal");
5
+ const util_1 = require("./util");
6
+ exports.boolean = (0, util_1.map)((0, literal_1.literal)('false', 'true'), res => ({
7
+ type: 'boolean',
8
+ range: res.range,
9
+ value: res.value === '' ? undefined : res.value === 'true',
10
+ }));
11
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1,12 @@
1
+ import type { CommentNode } from '../node';
2
+ import type { Parser } from './Parser';
3
+ interface Options {
4
+ singleLinePrefixes: Set<string>;
5
+ includesEol?: boolean;
6
+ }
7
+ /**
8
+ * `Failure` when three isn't a comment.
9
+ */
10
+ export declare function comment({ singleLinePrefixes, includesEol }: Options): Parser<CommentNode>;
11
+ export {};
12
+ //# sourceMappingURL=comment.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.comment = void 0;
4
+ const source_1 = require("../source");
5
+ const Parser_1 = require("./Parser");
6
+ /**
7
+ * `Failure` when three isn't a comment.
8
+ */
9
+ function comment({ singleLinePrefixes, includesEol }) {
10
+ return (src, _ctx) => {
11
+ const start = src.cursor;
12
+ const ans = {
13
+ type: 'comment',
14
+ range: source_1.Range.create(start),
15
+ comment: '',
16
+ };
17
+ for (const prefix of singleLinePrefixes) {
18
+ if (src.peek(prefix.length) === prefix) {
19
+ if (includesEol) {
20
+ src.nextLine();
21
+ }
22
+ else {
23
+ src.skipLine();
24
+ }
25
+ ans.range.end = src.cursor;
26
+ ans.comment = src.sliceToCursor(start + prefix.length);
27
+ return ans;
28
+ }
29
+ }
30
+ return Parser_1.Failure;
31
+ };
32
+ }
33
+ exports.comment = comment;
34
+ //# sourceMappingURL=comment.js.map
@@ -0,0 +1,3 @@
1
+ import type { InfallibleParser } from './Parser';
2
+ export declare const empty: InfallibleParser<undefined>;
3
+ //# sourceMappingURL=empty.d.ts.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.empty = void 0;
4
+ /* istanbul ignore next */
5
+ const empty = () => undefined;
6
+ exports.empty = empty;
7
+ //# sourceMappingURL=empty.js.map
@@ -0,0 +1,8 @@
1
+ import type { ErrorNode } from '../node';
2
+ import type { InfallibleParser } from './Parser';
3
+ /**
4
+ * Returns an error node containing all the remaining text (including whitespace),
5
+ * or returns `undefined` if the `Source` has already reached its end.
6
+ */
7
+ export declare const error: InfallibleParser<ErrorNode | undefined>;
8
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.error = void 0;
4
+ const locales_1 = require("@spyglassmc/locales");
5
+ const source_1 = require("../source");
6
+ /**
7
+ * Returns an error node containing all the remaining text (including whitespace),
8
+ * or returns `undefined` if the `Source` has already reached its end.
9
+ */
10
+ const error = (src, ctx) => {
11
+ if (!src.canRead()) {
12
+ return undefined;
13
+ }
14
+ const ans = {
15
+ type: 'error',
16
+ range: source_1.Range.create(src, () => src.skipRemaining()),
17
+ };
18
+ ctx.err.report((0, locales_1.localize)('error.unparseable-content'), ans);
19
+ return ans;
20
+ };
21
+ exports.error = error;
22
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1,9 @@
1
+ import type { FileNode } from '../node';
2
+ import { AstNode } from '../node';
3
+ import type { InfallibleParser } from './Parser';
4
+ /**
5
+ * Dispatches to the corresponding parser for the language.
6
+ * @throws If there's no parser registered for this language ID.
7
+ */
8
+ export declare function file(): InfallibleParser<FileNode<AstNode>>;
9
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.file = void 0;
4
+ const node_1 = require("../node");
5
+ const source_1 = require("../source");
6
+ const error_1 = require("./error");
7
+ const Parser_1 = require("./Parser");
8
+ /**
9
+ * Dispatches to the corresponding parser for the language.
10
+ * @throws If there's no parser registered for this language ID.
11
+ */
12
+ function file() {
13
+ return (src, ctx) => {
14
+ const fullRange = source_1.Range.create(src, src.string.length);
15
+ const ans = {
16
+ type: 'file',
17
+ range: fullRange,
18
+ children: [],
19
+ locals: Object.create(null),
20
+ parserErrors: [],
21
+ };
22
+ src.skipWhitespace();
23
+ const parser = ctx.meta.getParserForLanguageId(ctx.doc.languageId);
24
+ const result = parser(src, ctx);
25
+ if (result && result !== Parser_1.Failure) {
26
+ ans.children.push(result);
27
+ }
28
+ if (src.skipWhitespace().canRead()) {
29
+ ans.children.push((0, error_1.error)(src, ctx));
30
+ }
31
+ node_1.AstNode.setParents(ans);
32
+ ans.parserErrors = ctx.err.dump();
33
+ return ans;
34
+ };
35
+ }
36
+ exports.file = file;
37
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1,33 @@
1
+ import type { FloatNode } from '../node';
2
+ import type { ParserContext } from '../service';
3
+ import { Source } from '../source';
4
+ import type { InfallibleParser, Parser } from './Parser';
5
+ interface OptionsBase {
6
+ pattern: RegExp;
7
+ /**
8
+ * Inclusive.
9
+ */
10
+ min?: number;
11
+ /**
12
+ * Inclusive.
13
+ */
14
+ max?: number;
15
+ /**
16
+ * A callback function that will be called when the numeral value is out of range.
17
+ *
18
+ * Defaults to a function that marks an `Error` at the range of the node.
19
+ */
20
+ onOutOfRange?: (ans: FloatNode, src: Source, ctx: ParserContext, options: Options) => void;
21
+ }
22
+ interface FallibleOptions extends OptionsBase {
23
+ failsOnEmpty: true;
24
+ }
25
+ interface InfallibleOptions extends OptionsBase {
26
+ failsOnEmpty?: false;
27
+ }
28
+ /** @internal For test only */
29
+ export declare type Options = FallibleOptions | InfallibleOptions;
30
+ export declare function float(options: InfallibleOptions): InfallibleParser<FloatNode>;
31
+ export declare function float(options: FallibleOptions): Parser<FloatNode>;
32
+ export {};
33
+ //# sourceMappingURL=float.d.ts.map
@@ -0,0 +1,57 @@
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");
7
+ 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 */);
9
+ };
10
+ function float(options) {
11
+ return (src, ctx) => {
12
+ const ans = {
13
+ type: 'float',
14
+ range: source_1.Range.create(src),
15
+ value: 0,
16
+ };
17
+ if (src.peek() === '-' || src.peek() === '+') {
18
+ src.skip();
19
+ }
20
+ while (src.canRead() && source_1.Source.isDigit(src.peek())) {
21
+ src.skip();
22
+ }
23
+ if (src.trySkip('.')) {
24
+ while (src.canRead() && source_1.Source.isDigit(src.peek())) {
25
+ src.skip();
26
+ }
27
+ }
28
+ if (src.peek().toLowerCase() === 'e') {
29
+ src.skip();
30
+ if (src.peek() === '-' || src.peek() === '+') {
31
+ src.skip();
32
+ }
33
+ while (src.canRead() && source_1.Source.isDigit(src.peek())) {
34
+ src.skip();
35
+ }
36
+ }
37
+ ans.range.end = src.cursor;
38
+ const raw = src.sliceToCursor(ans.range.start);
39
+ ans.value = parseFloat(raw) || 0;
40
+ if (!raw) {
41
+ if (options.failsOnEmpty) {
42
+ return Parser_1.Failure;
43
+ }
44
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('float')), ans);
45
+ }
46
+ else if (!options.pattern.test(raw)) {
47
+ ctx.err.report((0, locales_1.localize)('parser.float.illegal', options.pattern), ans);
48
+ }
49
+ else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
50
+ const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
51
+ onOutOfRange(ans, src, ctx, options);
52
+ }
53
+ return ans;
54
+ };
55
+ }
56
+ exports.float = float;
57
+ //# sourceMappingURL=float.js.map
@@ -0,0 +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';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /* 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);
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,33 @@
1
+ import type { IntegerNode } from '../node';
2
+ import type { ParserContext } from '../service';
3
+ import { Source } from '../source';
4
+ import type { InfallibleParser, Parser } from './Parser';
5
+ interface OptionsBase {
6
+ pattern: RegExp;
7
+ /**
8
+ * Inclusive.
9
+ */
10
+ min?: number;
11
+ /**
12
+ * Inclusive.
13
+ */
14
+ max?: number;
15
+ /**
16
+ * A callback function that will be called when the numeral value is out of range.
17
+ *
18
+ * Defaults to a function that marks an `Error` at the range of the node.
19
+ */
20
+ onOutOfRange?: (ans: IntegerNode, src: Source, ctx: ParserContext, options: Options) => void;
21
+ }
22
+ interface FallibleOptions extends OptionsBase {
23
+ failsOnEmpty: true;
24
+ }
25
+ interface InfallibleOptions extends OptionsBase {
26
+ failsOnEmpty?: false;
27
+ }
28
+ /** @internal For test only */
29
+ export declare type Options = FallibleOptions | InfallibleOptions;
30
+ export declare function integer(options: InfallibleOptions): InfallibleParser<IntegerNode>;
31
+ export declare function integer(options: FallibleOptions): Parser<IntegerNode>;
32
+ export {};
33
+ //# sourceMappingURL=integer.d.ts.map
@@ -0,0 +1,46 @@
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");
7
+ 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 */);
9
+ };
10
+ function integer(options) {
11
+ return (src, ctx) => {
12
+ const ans = {
13
+ type: 'integer',
14
+ range: source_1.Range.create(src),
15
+ value: 0,
16
+ };
17
+ if (src.peek() === '-' || src.peek() === '+') {
18
+ src.skip();
19
+ }
20
+ while (src.canRead() && source_1.Source.isDigit(src.peek())) {
21
+ src.skip();
22
+ }
23
+ ans.range.end = src.cursor;
24
+ const raw = src.sliceToCursor(ans.range.start);
25
+ const isOnlySign = raw === '-' || raw === '+';
26
+ if (!isOnlySign) {
27
+ ans.value = Number(raw);
28
+ }
29
+ if (!raw) {
30
+ if (options.failsOnEmpty) {
31
+ return Parser_1.Failure;
32
+ }
33
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('integer')), ans);
34
+ }
35
+ else if (!options.pattern.test(raw) || isOnlySign) {
36
+ ctx.err.report((0, locales_1.localize)('parser.integer.illegal', options.pattern), ans);
37
+ }
38
+ else if ((options.min !== undefined && ans.value < options.min) || (options.max !== undefined && ans.value > options.max)) {
39
+ const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
40
+ onOutOfRange(ans, src, ctx, options);
41
+ }
42
+ return ans;
43
+ };
44
+ }
45
+ exports.integer = integer;
46
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1,12 @@
1
+ import type { AstNode, ListNode } from '../node';
2
+ import type { InfallibleParser, Parser } from './Parser';
3
+ /** @internal For test only */
4
+ export interface Options<V extends AstNode> {
5
+ start: string;
6
+ value: Parser<V>;
7
+ sep: string;
8
+ trailingSep: boolean;
9
+ end: string;
10
+ }
11
+ export declare function list<V extends AstNode>({ start, value, sep, trailingSep, end }: Options<V>): InfallibleParser<ListNode<V>>;
12
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1,70 @@
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 }) {
9
+ return (src, ctx) => {
10
+ const ans = {
11
+ type: 'list',
12
+ range: source_1.Range.create(src),
13
+ children: [],
14
+ };
15
+ if (src.trySkip(start)) {
16
+ src.skipWhitespace();
17
+ let requiresValueSep = false;
18
+ let hasValueSep = false;
19
+ while (src.canRead() && src.peek(end.length) !== end) {
20
+ const itemStart = src.cursor;
21
+ let valueNode;
22
+ // Item sep of the last item.
23
+ if (requiresValueSep && !hasValueSep) {
24
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(sep)), src);
25
+ }
26
+ // Value.
27
+ 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')));
31
+ }
32
+ else {
33
+ updateSrcAndCtx();
34
+ valueNode = result;
35
+ }
36
+ // Item sep.
37
+ let sepRange = undefined;
38
+ src.skipWhitespace();
39
+ requiresValueSep = true;
40
+ if (hasValueSep = src.peek(sep.length) === sep) {
41
+ sepRange = source_1.Range.create(src, () => src.skip(sep.length));
42
+ }
43
+ // Create item.
44
+ ans.children.push({
45
+ type: 'item',
46
+ range: source_1.Range.create(itemStart, src),
47
+ ...valueNode ? { children: [valueNode] } : {},
48
+ value: valueNode,
49
+ sep: sepRange,
50
+ });
51
+ src.skipWhitespace();
52
+ }
53
+ // Trailing item sep.
54
+ if (hasValueSep && !trailingSep) {
55
+ ctx.err.report((0, locales_1.localize)('parser.list.trailing-sep'), ans.children[ans.children.length - 1].sep);
56
+ }
57
+ // End.
58
+ if (!src.trySkip(end)) {
59
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(end)), src);
60
+ }
61
+ }
62
+ else {
63
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localeQuote)(start)), src);
64
+ }
65
+ ans.range.end = src.cursor;
66
+ return ans;
67
+ };
68
+ }
69
+ exports.list = list;
70
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1,5 @@
1
+ import type { LiteralNode, LiteralOptions } from '../node/LiteralNode';
2
+ import type { InfallibleParser } from './Parser';
3
+ export declare function literal(...pool: string[]): InfallibleParser<LiteralNode>;
4
+ export declare function literal(options: LiteralOptions): InfallibleParser<LiteralNode>;
5
+ //# sourceMappingURL=literal.d.ts.map
@@ -0,0 +1,41 @@
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) {
7
+ const options = getOptions(param);
8
+ return (src, ctx) => {
9
+ const ans = {
10
+ type: 'literal',
11
+ range: source_1.Range.create(src),
12
+ options,
13
+ value: '',
14
+ };
15
+ for (const expected of options.pool) {
16
+ if (src.trySkip(expected)) {
17
+ ans.value = expected;
18
+ ans.range.end = src.cursor;
19
+ return ans;
20
+ }
21
+ }
22
+ ctx.err.report((0, locales_1.localize)('expected', options.pool), ans);
23
+ return ans;
24
+ };
25
+ }
26
+ exports.literal = literal;
27
+ function getOptions(param) {
28
+ let ans;
29
+ if (typeof param[0] === 'object') {
30
+ ans = param[0];
31
+ }
32
+ else {
33
+ ans = {
34
+ pool: param,
35
+ };
36
+ }
37
+ // Sort the pool from longest to shortest.
38
+ ans.pool = ans.pool.sort((a, b) => b.length - a.length);
39
+ return ans;
40
+ }
41
+ //# sourceMappingURL=literal.js.map
@@ -0,0 +1,33 @@
1
+ import type { LongNode } from '../node';
2
+ import type { ParserContext } from '../service';
3
+ import { Source } from '../source';
4
+ import type { InfallibleParser, Parser } from './Parser';
5
+ interface OptionsBase {
6
+ pattern: RegExp;
7
+ /**
8
+ * Inclusive.
9
+ */
10
+ min?: bigint;
11
+ /**
12
+ * Inclusive.
13
+ */
14
+ max?: bigint;
15
+ /**
16
+ * A callback function that will be called when the numeral value is out of range.
17
+ *
18
+ * Defaults to a function that marks an `Error` at the range of the node.
19
+ */
20
+ onOutOfRange?: (ans: LongNode, src: Source, ctx: ParserContext, options: Options) => void;
21
+ }
22
+ interface FallibleOptions extends OptionsBase {
23
+ failsOnEmpty: true;
24
+ }
25
+ interface InfallibleOptions extends OptionsBase {
26
+ failsOnEmpty?: false;
27
+ }
28
+ /** @internal For test only */
29
+ export declare type Options = FallibleOptions | InfallibleOptions;
30
+ export declare function long(options: InfallibleOptions): InfallibleParser<LongNode>;
31
+ export declare function long(options: FallibleOptions): Parser<LongNode>;
32
+ export {};
33
+ //# sourceMappingURL=long.d.ts.map
@@ -0,0 +1,50 @@
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");
7
+ 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 */);
9
+ };
10
+ function long(options) {
11
+ return (src, ctx) => {
12
+ const ans = {
13
+ type: 'long',
14
+ range: source_1.Range.create(src),
15
+ value: 0n,
16
+ };
17
+ if (src.peek() === '-' || src.peek() === '+') {
18
+ src.skip();
19
+ }
20
+ while (src.canRead() && source_1.Source.isDigit(src.peek())) {
21
+ src.skip();
22
+ }
23
+ ans.range.end = src.cursor;
24
+ const raw = src.sliceToCursor(ans.range.start);
25
+ let isOnlySign = false;
26
+ try {
27
+ ans.value = BigInt(raw);
28
+ }
29
+ catch (_) {
30
+ // `raw` might be "+" or "-" here.
31
+ isOnlySign = true;
32
+ }
33
+ if (!raw) {
34
+ if (options.failsOnEmpty) {
35
+ return Parser_1.Failure;
36
+ }
37
+ ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('long')), ans);
38
+ }
39
+ else if (!options.pattern.test(raw) || isOnlySign) {
40
+ ctx.err.report((0, locales_1.localize)('parser.long.illegal', options.pattern), ans);
41
+ }
42
+ else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
43
+ const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
44
+ onOutOfRange(ans, src, ctx, options);
45
+ }
46
+ return ans;
47
+ };
48
+ }
49
+ exports.long = long;
50
+ //# sourceMappingURL=long.js.map