@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,6 +1,6 @@
1
- import { IndexMap } from '.';
2
- import type { RangeContainer } from './Range';
3
- import { Range } from './Range';
1
+ import { IndexMap } from './IndexMap.js';
2
+ import type { RangeContainer } from './Range.js';
3
+ import { Range } from './Range.js';
4
4
  declare type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
5
5
  declare type Space = ' ' | '\t';
6
6
  declare type Newline = '\r\n' | '\r' | '\n';
@@ -35,9 +35,15 @@ export declare class ReadonlySource {
35
35
  /**
36
36
  * If the `expectedValue` is right after the cursor, returns `true`. Otherwise returns `false`.
37
37
  *
38
+ * @param offset Defaults to 0.
39
+ *
38
40
  * @see {@link Source.trySkip}
39
41
  */
40
- tryPeek(expectedValue: string): boolean;
42
+ tryPeek(expectedValue: string, offset?: number): boolean;
43
+ tryPeekAfterWhitespace(expectedValue: string): boolean;
44
+ peekUntil(...terminators: string[]): string;
45
+ peekLine(): string;
46
+ hasNonSpaceAheadInLine(): boolean;
41
47
  slice(start: number, end?: number): string;
42
48
  slice(rangeLike: Range | RangeContainer): string;
43
49
  sliceToCursor(start: number): string;
@@ -88,6 +94,8 @@ export declare class Source extends ReadonlySource {
88
94
  skipSpace(): this;
89
95
  readWhitespace(): string;
90
96
  skipWhitespace(): this;
97
+ readIf(predicate: (this: void, char: string) => boolean): string;
98
+ skipIf(predicate: (this: void, char: string) => boolean): this;
91
99
  /**
92
100
  * @param terminators Ending character. Will not be skipped or included in the result.
93
101
  */
@@ -1,20 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Source = exports.ReadonlySource = exports.Whitespaces = exports.LF = exports.CR = exports.CRLF = void 0;
4
- const _1 = require(".");
5
- const Range_1 = require("./Range");
6
- exports.CRLF = '\r\n';
7
- exports.CR = '\r';
8
- exports.LF = '\n';
9
- exports.Whitespaces = Object.freeze([' ', '\n', '\r', '\t']);
10
- class ReadonlySource {
1
+ import { IndexMap } from './IndexMap.js';
2
+ import { Range } from './Range.js';
3
+ export const CRLF = '\r\n';
4
+ export const CR = '\r';
5
+ export const LF = '\n';
6
+ export const Whitespaces = Object.freeze([' ', '\n', '\r', '\t']);
7
+ export class ReadonlySource {
8
+ string;
9
+ indexMap;
10
+ innerCursor = 0;
11
11
  constructor(string, indexMap = []) {
12
12
  this.string = string;
13
13
  this.indexMap = indexMap;
14
- this.innerCursor = 0;
15
14
  }
16
15
  get cursor() {
17
- return _1.IndexMap.toOuterOffset(this.indexMap, this.innerCursor);
16
+ return IndexMap.toOuterOffset(this.indexMap, this.innerCursor);
18
17
  }
19
18
  /**
20
19
  * @param offset The index to offset from cursor. Defaults to 0.
@@ -27,7 +26,7 @@ class ReadonlySource {
27
26
  * getCharRange(1) // Returns the range of the character after cursor.
28
27
  */
29
28
  getCharRange(offset = 0) {
30
- return _1.IndexMap.toOuterRange(this.indexMap, Range_1.Range.create(this.innerCursor + offset, this.innerCursor + offset + 1));
29
+ return IndexMap.toOuterRange(this.indexMap, Range.create(this.innerCursor + offset, this.innerCursor + offset + 1));
31
30
  }
32
31
  /**
33
32
  * Peeks a substring from the current cursor.
@@ -40,27 +39,66 @@ class ReadonlySource {
40
39
  /**
41
40
  * If the `expectedValue` is right after the cursor, returns `true`. Otherwise returns `false`.
42
41
  *
42
+ * @param offset Defaults to 0.
43
+ *
43
44
  * @see {@link Source.trySkip}
44
45
  */
45
- tryPeek(expectedValue) {
46
- return this.peek(expectedValue.length) === expectedValue;
46
+ tryPeek(expectedValue, offset = 0) {
47
+ return this.peek(expectedValue.length, offset) === expectedValue;
48
+ }
49
+ tryPeekAfterWhitespace(expectedValue) {
50
+ const maxOffset = this.string.length - this.innerCursor;
51
+ let offset = 0;
52
+ while (offset < maxOffset && Source.isWhitespace(this.peek(1, offset))) {
53
+ offset++;
54
+ }
55
+ return this.tryPeek(expectedValue, offset);
56
+ }
57
+ peekUntil(...terminators) {
58
+ let ans = '';
59
+ for (let cursor = this.innerCursor; cursor < this.string.length; cursor++) {
60
+ const c = this.string.charAt(cursor);
61
+ if (terminators.includes(c)) {
62
+ return ans;
63
+ }
64
+ else {
65
+ ans += c;
66
+ }
67
+ }
68
+ return ans;
69
+ }
70
+ peekLine() {
71
+ return this.peekUntil(CR, LF);
72
+ }
73
+ hasNonSpaceAheadInLine() {
74
+ for (let cursor = this.innerCursor; cursor < this.string.length; cursor++) {
75
+ const c = this.string.charAt(cursor);
76
+ if (c === CR || c === LF) {
77
+ break;
78
+ }
79
+ if (!(c === ' ' || c === '\t')) {
80
+ return true;
81
+ }
82
+ }
83
+ return false;
47
84
  }
48
85
  slice(param0, end) {
49
86
  if (typeof param0 === 'number') {
50
- const innerStart = _1.IndexMap.toInnerOffset(this.indexMap, param0);
51
- const innerEnd = end !== undefined ? _1.IndexMap.toInnerOffset(this.indexMap, end) : undefined;
87
+ const innerStart = IndexMap.toInnerOffset(this.indexMap, param0);
88
+ const innerEnd = end !== undefined ? IndexMap.toInnerOffset(this.indexMap, end) : undefined;
52
89
  return this.string.slice(innerStart, innerEnd);
53
90
  }
54
- const range = _1.IndexMap.toInnerRange(this.indexMap, Range_1.Range.get(param0));
91
+ const range = IndexMap.toInnerRange(this.indexMap, Range.get(param0));
55
92
  return this.string.slice(range.start, range.end);
56
93
  }
57
94
  sliceToCursor(start) {
58
- const innerStart = _1.IndexMap.toInnerOffset(this.indexMap, start);
95
+ const innerStart = IndexMap.toInnerOffset(this.indexMap, start);
59
96
  return this.string.slice(innerStart, this.innerCursor);
60
97
  }
61
98
  }
62
- exports.ReadonlySource = ReadonlySource;
63
- class Source extends ReadonlySource {
99
+ export class Source extends ReadonlySource {
100
+ string;
101
+ indexMap;
64
102
  constructor(string, indexMap = []) {
65
103
  super(string, indexMap);
66
104
  this.string = string;
@@ -70,7 +108,7 @@ class Source extends ReadonlySource {
70
108
  return super.cursor;
71
109
  }
72
110
  set cursor(cursor) {
73
- this.innerCursor = _1.IndexMap.toInnerOffset(this.indexMap, cursor);
111
+ this.innerCursor = IndexMap.toInnerOffset(this.indexMap, cursor);
74
112
  }
75
113
  clone() {
76
114
  const ans = new Source(this.string, this.indexMap);
@@ -81,7 +119,7 @@ class Source extends ReadonlySource {
81
119
  return this.innerCursor + length <= this.string.length;
82
120
  }
83
121
  canReadInLine() {
84
- return this.canRead() && this.peek() !== exports.CR && this.peek() !== exports.LF;
122
+ return this.canRead() && this.peek() !== CR && this.peek() !== LF;
85
123
  }
86
124
  read() {
87
125
  return this.string.charAt(this.innerCursor++);
@@ -119,7 +157,7 @@ class Source extends ReadonlySource {
119
157
  * Reads until the end of this line.
120
158
  */
121
159
  readLine() {
122
- return this.readUntil(exports.CR, exports.LF);
160
+ return this.readUntil(CR, LF);
123
161
  }
124
162
  /**
125
163
  * Skips until the end of this line.
@@ -133,10 +171,10 @@ class Source extends ReadonlySource {
133
171
  */
134
172
  nextLine() {
135
173
  this.skipLine();
136
- if (this.peek(2) === exports.CRLF) {
174
+ if (this.peek(2) === CRLF) {
137
175
  this.skip(2);
138
176
  }
139
- else if (this.peek() === exports.CR || this.peek() === exports.LF) {
177
+ else if (this.peek() === CR || this.peek() === LF) {
140
178
  this.skip();
141
179
  }
142
180
  return this;
@@ -163,6 +201,24 @@ class Source extends ReadonlySource {
163
201
  }
164
202
  return this;
165
203
  }
204
+ readIf(predicate) {
205
+ let ans = '';
206
+ while (this.canRead()) {
207
+ const c = this.peek();
208
+ if (predicate(c)) {
209
+ this.skip();
210
+ ans += c;
211
+ }
212
+ else {
213
+ break;
214
+ }
215
+ }
216
+ return ans;
217
+ }
218
+ skipIf(predicate) {
219
+ this.readIf(predicate);
220
+ return this;
221
+ }
166
222
  /**
167
223
  * @param terminators Ending character. Will not be skipped or included in the result.
168
224
  */
@@ -188,10 +244,10 @@ class Source extends ReadonlySource {
188
244
  return this;
189
245
  }
190
246
  readUntilLineEnd() {
191
- return this.readUntil(exports.CR, exports.LF);
247
+ return this.readUntil(CR, LF);
192
248
  }
193
249
  skipUntilLineEnd() {
194
- return this.skipUntilOrEnd(exports.CR, exports.LF);
250
+ return this.skipUntilOrEnd(CR, LF);
195
251
  }
196
252
  readRemaining() {
197
253
  const start = this.innerCursor;
@@ -218,5 +274,4 @@ class Source extends ReadonlySource {
218
274
  return Source.isSpace(c) || Source.isNewline(c);
219
275
  }
220
276
  }
221
- exports.Source = Source;
222
277
  //# sourceMappingURL=Source.js.map
@@ -1,9 +1,9 @@
1
- export * from './IndexMap';
2
- export * from './LanguageError';
3
- export * from './Location';
4
- export * from './Offset';
5
- export * from './Position';
6
- export * from './PositionRange';
7
- export * from './Range';
8
- export * from './Source';
1
+ export * from './IndexMap.js';
2
+ export * from './LanguageError.js';
3
+ export * from './Location.js';
4
+ export * from './Offset.js';
5
+ export * from './Position.js';
6
+ export * from './PositionRange.js';
7
+ export * from './Range.js';
8
+ export * from './Source.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,21 +1,9 @@
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("./IndexMap"), exports);
14
- __exportStar(require("./LanguageError"), exports);
15
- __exportStar(require("./Location"), exports);
16
- __exportStar(require("./Offset"), exports);
17
- __exportStar(require("./Position"), exports);
18
- __exportStar(require("./PositionRange"), exports);
19
- __exportStar(require("./Range"), exports);
20
- __exportStar(require("./Source"), exports);
1
+ export * from './IndexMap.js';
2
+ export * from './LanguageError.js';
3
+ export * from './Location.js';
4
+ export * from './Offset.js';
5
+ export * from './Position.js';
6
+ export * from './PositionRange.js';
7
+ export * from './Range.js';
8
+ export * from './Source.js';
21
9
  //# sourceMappingURL=index.js.map