@spyglassmc/core 0.4.5 → 0.4.7
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.
- package/lib/common/Dev.js +2 -5
- package/lib/common/ReadonlyProxy.js +1 -3
- package/lib/common/StateProxy.js +2 -8
- package/lib/common/externals/BrowserExternals.js +7 -12
- package/lib/common/externals/NodeJsExternals.js +12 -8
- package/lib/common/externals/index.d.ts +8 -1
- package/lib/common/util.js +3 -10
- package/lib/node/AstNode.js +7 -9
- package/lib/node/BooleanNode.js +1 -4
- package/lib/node/FloatNode.js +1 -5
- package/lib/node/IntegerNode.js +1 -5
- package/lib/node/ListNode.d.ts +1 -1
- package/lib/node/LiteralNode.js +1 -6
- package/lib/node/LongNode.js +1 -5
- package/lib/node/PrefixedNode.d.ts +13 -0
- package/lib/node/PrefixedNode.js +22 -0
- package/lib/node/ResourceLocationNode.d.ts +4 -1
- package/lib/node/ResourceLocationNode.js +2 -8
- package/lib/node/StringNode.d.ts +2 -1
- package/lib/node/StringNode.js +1 -4
- package/lib/node/SymbolNode.js +1 -6
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/parser/comment.d.ts +1 -1
- package/lib/parser/comment.js +2 -6
- package/lib/parser/error.js +1 -4
- package/lib/parser/file.d.ts +2 -2
- package/lib/parser/file.js +1 -2
- package/lib/parser/float.js +2 -7
- package/lib/parser/index.d.ts +1 -0
- package/lib/parser/index.js +1 -0
- package/lib/parser/integer.js +3 -7
- package/lib/parser/list.d.ts +1 -1
- package/lib/parser/list.js +2 -6
- package/lib/parser/literal.js +2 -9
- package/lib/parser/long.js +2 -7
- package/lib/parser/prefixed.d.ts +8 -0
- package/lib/parser/prefixed.js +23 -0
- package/lib/parser/record.d.ts +1 -1
- package/lib/parser/record.js +11 -17
- package/lib/parser/resourceLocation.d.ts +1 -0
- package/lib/parser/resourceLocation.js +9 -4
- package/lib/parser/string.js +6 -9
- package/lib/parser/util.d.ts +14 -3
- package/lib/parser/util.js +48 -26
- package/lib/processor/ColorInfoProvider.js +8 -25
- package/lib/processor/binder/builtin.d.ts +1 -0
- package/lib/processor/binder/builtin.js +20 -30
- package/lib/processor/checker/builtin.d.ts +1 -0
- package/lib/processor/checker/builtin.js +13 -7
- package/lib/processor/colorizer/Colorizer.d.ts +1 -1
- package/lib/processor/colorizer/Colorizer.js +4 -7
- package/lib/processor/colorizer/builtin.js +2 -2
- package/lib/processor/completer/Completer.js +1 -3
- package/lib/processor/completer/builtin.d.ts +3 -2
- package/lib/processor/completer/builtin.js +70 -24
- package/lib/processor/formatter/Formatter.js +1 -3
- package/lib/processor/formatter/builtin.js +2 -4
- package/lib/processor/linter/builtin/undeclaredSymbol.js +27 -40
- package/lib/service/CacheService.d.ts +1 -1
- package/lib/service/CacheService.js +12 -13
- package/lib/service/Config.d.ts +36 -0
- package/lib/service/Config.js +28 -45
- package/lib/service/Context.d.ts +2 -0
- package/lib/service/Context.js +4 -12
- package/lib/service/Downloader.d.ts +3 -0
- package/lib/service/Downloader.js +9 -3
- package/lib/service/ErrorReporter.js +3 -0
- package/lib/service/FileService.js +10 -29
- package/lib/service/Hover.js +1 -4
- package/lib/service/MetaRegistry.d.ts +4 -2
- package/lib/service/MetaRegistry.js +16 -8
- package/lib/service/Project.d.ts +9 -3
- package/lib/service/Project.js +73 -49
- package/lib/service/Service.d.ts +1 -1
- package/lib/service/Service.js +11 -36
- package/lib/service/SymbolLocations.js +1 -4
- package/lib/service/fileUtil.d.ts +7 -0
- package/lib/service/fileUtil.js +29 -4
- package/lib/source/IndexMap.js +1 -4
- package/lib/source/Location.js +3 -9
- package/lib/source/Position.js +1 -2
- package/lib/source/PositionRange.js +2 -2
- package/lib/source/Range.js +9 -21
- package/lib/source/Source.d.ts +11 -1
- package/lib/source/Source.js +31 -5
- package/lib/symbol/Symbol.d.ts +14 -9
- package/lib/symbol/Symbol.js +80 -61
- package/lib/symbol/SymbolUtil.d.ts +3 -3
- package/lib/symbol/SymbolUtil.js +48 -72
- package/package.json +3 -2
package/lib/common/Dev.js
CHANGED
|
@@ -30,8 +30,7 @@ export var Dev;
|
|
|
30
30
|
switch (typeof current) {
|
|
31
31
|
case 'bigint': {
|
|
32
32
|
const bits = Math.ceil(Math.log2(Number(current)));
|
|
33
|
-
ans += (2 + Math.ceil(bits / (ByteToBits * PointerSize))) *
|
|
34
|
-
PointerSize; // https://stackoverflow.com/a/54298760
|
|
33
|
+
ans += (2 + Math.ceil(bits / (ByteToBits * PointerSize))) * PointerSize; // https://stackoverflow.com/a/54298760
|
|
35
34
|
break;
|
|
36
35
|
}
|
|
37
36
|
case 'boolean':
|
|
@@ -81,9 +80,7 @@ export var Dev;
|
|
|
81
80
|
catch (ignored) {
|
|
82
81
|
// Most likely "Maximum callstack size exceeded".
|
|
83
82
|
// Fall back to a shallow string representation.
|
|
84
|
-
return `{ ${Object.entries(value)
|
|
85
|
-
.map(([k, v]) => `'${k}': '${String(v)}'`)
|
|
86
|
-
.join(', ')} }`;
|
|
83
|
+
return `{ ${Object.entries(value).map(([k, v]) => `'${k}': '${String(v)}'`).join(', ')} }`;
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
else if (typeof value === 'symbol') {
|
|
@@ -11,9 +11,7 @@ class ReadonlyProxyHandler {
|
|
|
11
11
|
get(target, p, receiver) {
|
|
12
12
|
const value = Reflect.get(target, p, receiver);
|
|
13
13
|
if (p !== 'prototype' && isObject(value)) {
|
|
14
|
-
return emplaceMap(this.map, p, {
|
|
15
|
-
insert: () => ReadonlyProxy.create(value),
|
|
16
|
-
});
|
|
14
|
+
return emplaceMap(this.map, p, { insert: () => ReadonlyProxy.create(value) });
|
|
17
15
|
}
|
|
18
16
|
return value;
|
|
19
17
|
}
|
package/lib/common/StateProxy.js
CHANGED
|
@@ -63,18 +63,12 @@ class StateProxyHandler {
|
|
|
63
63
|
}
|
|
64
64
|
const value = Reflect.get(target, p, receiver);
|
|
65
65
|
if (p !== 'prototype' && isObject(value)) {
|
|
66
|
-
return emplaceMap(this.map, p, {
|
|
67
|
-
insert: () => _createStateProxy(value, this.rootOps),
|
|
68
|
-
});
|
|
66
|
+
return emplaceMap(this.map, p, { insert: () => _createStateProxy(value, this.rootOps) });
|
|
69
67
|
}
|
|
70
68
|
return value;
|
|
71
69
|
}
|
|
72
70
|
set(target, p, value, receiver) {
|
|
73
|
-
if (p === BranchOff ||
|
|
74
|
-
p === Is ||
|
|
75
|
-
p === Origin ||
|
|
76
|
-
p === Redo ||
|
|
77
|
-
p === Undo) {
|
|
71
|
+
if (p === BranchOff || p === Is || p === Origin || p === Redo || p === Undo) {
|
|
78
72
|
throw new TypeError(`Cannot set ${String(p)}`);
|
|
79
73
|
}
|
|
80
74
|
this.rootOps.set(target, p, StateProxy.dereference(value), receiver);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decode as arrayBufferFromBase64, encode as arrayBufferToBase64
|
|
1
|
+
import { decode as arrayBufferFromBase64, encode as arrayBufferToBase64 } from 'base64-arraybuffer';
|
|
2
2
|
import pako from 'pako';
|
|
3
3
|
import { fileUtil } from '../../service/fileUtil.js';
|
|
4
4
|
class BrowserEventEmitter {
|
|
@@ -44,10 +44,7 @@ class BrowserExternalDownloader {
|
|
|
44
44
|
headers.append(name, v);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const res = await fetch(uri, {
|
|
48
|
-
headers,
|
|
49
|
-
redirect: 'follow',
|
|
50
|
-
});
|
|
47
|
+
const res = await fetch(uri, { headers, redirect: 'follow' });
|
|
51
48
|
if (!res.ok) {
|
|
52
49
|
throw new Error(`Status code ${res.status}: ${res.ok}`);
|
|
53
50
|
}
|
|
@@ -114,10 +111,7 @@ class BrowserFileSystem {
|
|
|
114
111
|
if (!entry) {
|
|
115
112
|
throw new Error(`ENOENT: ${location}`);
|
|
116
113
|
}
|
|
117
|
-
return {
|
|
118
|
-
isDirectory: () => entry.type === 'directory',
|
|
119
|
-
isFile: () => entry.type === 'file',
|
|
120
|
-
};
|
|
114
|
+
return { isDirectory: () => entry.type === 'directory', isFile: () => entry.type === 'file' };
|
|
121
115
|
}
|
|
122
116
|
async unlink(location) {
|
|
123
117
|
location = location.toString();
|
|
@@ -164,13 +158,14 @@ export const BrowserExternals = {
|
|
|
164
158
|
},
|
|
165
159
|
downloader: new BrowserExternalDownloader(),
|
|
166
160
|
error: {
|
|
161
|
+
createKind(kind, message) {
|
|
162
|
+
return new Error(`${kind}: ${message}`);
|
|
163
|
+
},
|
|
167
164
|
isKind(e, kind) {
|
|
168
165
|
return e instanceof Error && e.message.startsWith(kind);
|
|
169
166
|
},
|
|
170
167
|
},
|
|
171
|
-
event: {
|
|
172
|
-
EventEmitter: BrowserEventEmitter,
|
|
173
|
-
},
|
|
168
|
+
event: { EventEmitter: BrowserEventEmitter },
|
|
174
169
|
fs: new BrowserFileSystem(),
|
|
175
170
|
};
|
|
176
171
|
function uint8ArrayToHex(array) {
|
|
@@ -28,6 +28,8 @@ class NodeJsExternalDownloader {
|
|
|
28
28
|
else {
|
|
29
29
|
resolve(promisifyAsyncIterable(res, (chunks) => Buffer.concat(chunks)));
|
|
30
30
|
}
|
|
31
|
+
}).on('error', (e) => {
|
|
32
|
+
reject(e);
|
|
31
33
|
});
|
|
32
34
|
});
|
|
33
35
|
}
|
|
@@ -56,22 +58,24 @@ export const NodeJsExternals = {
|
|
|
56
58
|
},
|
|
57
59
|
downloader: new NodeJsExternalDownloader(),
|
|
58
60
|
error: {
|
|
61
|
+
createKind(kind, message) {
|
|
62
|
+
const error = new Error(message);
|
|
63
|
+
error.code = kind;
|
|
64
|
+
return error;
|
|
65
|
+
},
|
|
59
66
|
isKind(e, kind) {
|
|
60
67
|
return e instanceof Error && e.code === kind;
|
|
61
68
|
},
|
|
62
69
|
},
|
|
63
|
-
event: {
|
|
64
|
-
EventEmitter,
|
|
65
|
-
},
|
|
70
|
+
event: { EventEmitter },
|
|
66
71
|
fs: {
|
|
67
72
|
chmod(location, mode) {
|
|
68
73
|
return fsp.chmod(toFsPathLike(location), mode);
|
|
69
74
|
},
|
|
70
|
-
async getAllFiles(location) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
})).map(uriFromPath);
|
|
75
|
+
async getAllFiles(location, depth) {
|
|
76
|
+
const path = toPath(location).replaceAll('\\', '/') + '**/*';
|
|
77
|
+
const files = await globby(path, { absolute: true, dot: true, deep: depth });
|
|
78
|
+
return files.map(uriFromPath);
|
|
75
79
|
},
|
|
76
80
|
async mkdir(location, options) {
|
|
77
81
|
return void (await fsp.mkdir(toFsPathLike(location), options));
|
|
@@ -17,6 +17,13 @@ export interface Externals {
|
|
|
17
17
|
};
|
|
18
18
|
downloader: ExternalDownloader;
|
|
19
19
|
error: {
|
|
20
|
+
/**
|
|
21
|
+
* @returns an error of the specified kind
|
|
22
|
+
*/
|
|
23
|
+
createKind: (kind: ExternalErrorKind, message: string) => unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether the given error is of a certain kind
|
|
26
|
+
*/
|
|
20
27
|
isKind: (e: unknown, kind: ExternalErrorKind) => boolean;
|
|
21
28
|
};
|
|
22
29
|
event: {
|
|
@@ -45,7 +52,7 @@ export interface ExternalFileSystem {
|
|
|
45
52
|
/**
|
|
46
53
|
* @returns an array of file URIs under the given `location`.
|
|
47
54
|
*/
|
|
48
|
-
getAllFiles(location: FsLocation): Promise<string[]>;
|
|
55
|
+
getAllFiles(location: FsLocation, depth?: number): Promise<string[]>;
|
|
49
56
|
/**
|
|
50
57
|
* @param options `mode` - File mode bit mask (e.g. `0o775`).
|
|
51
58
|
*/
|
package/lib/common/util.js
CHANGED
|
@@ -171,10 +171,7 @@ export var Lazy;
|
|
|
171
171
|
(function (Lazy) {
|
|
172
172
|
const LazyDiscriminator = Symbol('LazyDiscriminator');
|
|
173
173
|
function create(getter) {
|
|
174
|
-
return {
|
|
175
|
-
discriminator: LazyDiscriminator,
|
|
176
|
-
getter,
|
|
177
|
-
};
|
|
174
|
+
return { discriminator: LazyDiscriminator, getter };
|
|
178
175
|
}
|
|
179
176
|
Lazy.create = create;
|
|
180
177
|
function isComplex(lazy) {
|
|
@@ -186,9 +183,7 @@ export var Lazy;
|
|
|
186
183
|
}
|
|
187
184
|
Lazy.isUnresolved = isUnresolved;
|
|
188
185
|
function resolve(lazy) {
|
|
189
|
-
return isUnresolved(lazy)
|
|
190
|
-
? (lazy.value = lazy.getter())
|
|
191
|
-
: lazy;
|
|
186
|
+
return isUnresolved(lazy) ? (lazy.value = lazy.getter()) : lazy;
|
|
192
187
|
}
|
|
193
188
|
Lazy.resolve = resolve;
|
|
194
189
|
})(Lazy || (Lazy = {}));
|
|
@@ -201,9 +196,7 @@ export function getStates(category, ids, ctx) {
|
|
|
201
196
|
const ans = {};
|
|
202
197
|
ids = ids.map(ResourceLocation.lengthen);
|
|
203
198
|
for (const id of ids) {
|
|
204
|
-
ctx.symbols
|
|
205
|
-
.query(ctx.doc, category, id)
|
|
206
|
-
.forEachMember((state, stateQuery) => {
|
|
199
|
+
ctx.symbols.query(ctx.doc, category, id).forEachMember((state, stateQuery) => {
|
|
207
200
|
const values = Object.keys(stateQuery.visibleMembers);
|
|
208
201
|
const set = (ans[state] ??= new Set());
|
|
209
202
|
const defaultValue = stateQuery.symbol?.relations?.default;
|
package/lib/node/AstNode.js
CHANGED
|
@@ -4,10 +4,10 @@ export var AstNode;
|
|
|
4
4
|
(function (AstNode) {
|
|
5
5
|
/* istanbul ignore next */
|
|
6
6
|
function is(obj) {
|
|
7
|
-
return (!!obj
|
|
8
|
-
typeof obj === 'object'
|
|
9
|
-
typeof obj.type === 'string'
|
|
10
|
-
Range.is(obj.range));
|
|
7
|
+
return (!!obj
|
|
8
|
+
&& typeof obj === 'object'
|
|
9
|
+
&& typeof obj.type === 'string'
|
|
10
|
+
&& Range.is(obj.range));
|
|
11
11
|
}
|
|
12
12
|
AstNode.is = is;
|
|
13
13
|
function setParents(node) {
|
|
@@ -24,9 +24,7 @@ export var AstNode;
|
|
|
24
24
|
if (!node.children) {
|
|
25
25
|
return -1;
|
|
26
26
|
}
|
|
27
|
-
const comparator = typeof needle === 'number'
|
|
28
|
-
? Range.compareOffset
|
|
29
|
-
: Range.compare;
|
|
27
|
+
const comparator = typeof needle === 'number' ? Range.compareOffset : Range.compare;
|
|
30
28
|
return binarySearch(node.children, needle, (a, b) => comparator(a.range, b, endInclusive));
|
|
31
29
|
}
|
|
32
30
|
AstNode.findChildIndex = findChildIndex;
|
|
@@ -65,7 +63,7 @@ export var AstNode;
|
|
|
65
63
|
return node.children?.[findLastChildIndex(node, needle, endInclusive)];
|
|
66
64
|
}
|
|
67
65
|
AstNode.findLastChild = findLastChild;
|
|
68
|
-
function findDeepestChild({ node, needle, endInclusive = false, predicate = () => true
|
|
66
|
+
function findDeepestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
69
67
|
let last;
|
|
70
68
|
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
71
69
|
while (head && predicate(head)) {
|
|
@@ -75,7 +73,7 @@ export var AstNode;
|
|
|
75
73
|
return last;
|
|
76
74
|
}
|
|
77
75
|
AstNode.findDeepestChild = findDeepestChild;
|
|
78
|
-
function findShallowestChild({ node, needle, endInclusive = false, predicate = () => true
|
|
76
|
+
function findShallowestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
79
77
|
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
80
78
|
while (head && !predicate(head)) {
|
|
81
79
|
head = findChild(head, needle, endInclusive);
|
package/lib/node/BooleanNode.js
CHANGED
|
@@ -7,10 +7,7 @@ export var BooleanNode;
|
|
|
7
7
|
}
|
|
8
8
|
BooleanNode.is = is;
|
|
9
9
|
function mock(range) {
|
|
10
|
-
return {
|
|
11
|
-
type: 'boolean',
|
|
12
|
-
range: Range.get(range),
|
|
13
|
-
};
|
|
10
|
+
return { type: 'boolean', range: Range.get(range) };
|
|
14
11
|
}
|
|
15
12
|
BooleanNode.mock = mock;
|
|
16
13
|
})(BooleanNode || (BooleanNode = {}));
|
package/lib/node/FloatNode.js
CHANGED
|
@@ -7,11 +7,7 @@ export var FloatNode;
|
|
|
7
7
|
}
|
|
8
8
|
FloatNode.is = is;
|
|
9
9
|
function mock(range) {
|
|
10
|
-
return {
|
|
11
|
-
type: 'float',
|
|
12
|
-
range: Range.get(range),
|
|
13
|
-
value: 0,
|
|
14
|
-
};
|
|
10
|
+
return { type: 'float', range: Range.get(range), value: 0 };
|
|
15
11
|
}
|
|
16
12
|
FloatNode.mock = mock;
|
|
17
13
|
})(FloatNode || (FloatNode = {}));
|
package/lib/node/IntegerNode.js
CHANGED
|
@@ -6,11 +6,7 @@ export var IntegerNode;
|
|
|
6
6
|
}
|
|
7
7
|
IntegerNode.is = is;
|
|
8
8
|
function mock(range) {
|
|
9
|
-
return {
|
|
10
|
-
type: 'integer',
|
|
11
|
-
range: Range.get(range),
|
|
12
|
-
value: 0,
|
|
13
|
-
};
|
|
9
|
+
return { type: 'integer', range: Range.get(range), value: 0 };
|
|
14
10
|
}
|
|
15
11
|
IntegerNode.mock = mock;
|
|
16
12
|
})(IntegerNode || (IntegerNode = {}));
|
package/lib/node/ListNode.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export interface ItemNode<V extends AstNode> extends AstNode {
|
|
|
10
10
|
readonly sep?: Range;
|
|
11
11
|
}
|
|
12
12
|
export declare namespace ItemNode {
|
|
13
|
-
function is<V extends AstNode>(node:
|
|
13
|
+
function is<V extends AstNode>(node: object | undefined): node is ItemNode<V>;
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=ListNode.d.ts.map
|
package/lib/node/LiteralNode.js
CHANGED
|
@@ -7,12 +7,7 @@ export var LiteralNode;
|
|
|
7
7
|
}
|
|
8
8
|
LiteralNode.is = is;
|
|
9
9
|
function mock(range, options) {
|
|
10
|
-
return {
|
|
11
|
-
type: 'literal',
|
|
12
|
-
range: Range.get(range),
|
|
13
|
-
options,
|
|
14
|
-
value: '',
|
|
15
|
-
};
|
|
10
|
+
return { type: 'literal', range: Range.get(range), options, value: '' };
|
|
16
11
|
}
|
|
17
12
|
LiteralNode.mock = mock;
|
|
18
13
|
})(LiteralNode || (LiteralNode = {}));
|
package/lib/node/LongNode.js
CHANGED
|
@@ -6,11 +6,7 @@ export var LongNode;
|
|
|
6
6
|
}
|
|
7
7
|
LongNode.is = is;
|
|
8
8
|
function mock(range) {
|
|
9
|
-
return {
|
|
10
|
-
type: 'long',
|
|
11
|
-
range: Range.get(range),
|
|
12
|
-
value: 0n,
|
|
13
|
-
};
|
|
9
|
+
return { type: 'long', range: Range.get(range), value: 0n };
|
|
14
10
|
}
|
|
15
11
|
LongNode.mock = mock;
|
|
16
12
|
})(LongNode || (LongNode = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
|
+
import { LiteralNode } from './LiteralNode.js';
|
|
4
|
+
export interface PrefixedNode<C extends AstNode = AstNode> extends AstNode {
|
|
5
|
+
readonly type: 'prefixed';
|
|
6
|
+
readonly children: (LiteralNode | C)[];
|
|
7
|
+
readonly prefix: string;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace PrefixedNode {
|
|
10
|
+
function is<C extends AstNode>(obj: object): obj is PrefixedNode<C>;
|
|
11
|
+
function mock<C extends AstNode>(range: RangeLike, prefix: string, child: C): PrefixedNode<C>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=PrefixedNode.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
import { LiteralNode } from './LiteralNode.js';
|
|
3
|
+
export var PrefixedNode;
|
|
4
|
+
(function (PrefixedNode) {
|
|
5
|
+
function is(obj) {
|
|
6
|
+
return obj.type === 'prefixed';
|
|
7
|
+
}
|
|
8
|
+
PrefixedNode.is = is;
|
|
9
|
+
function mock(range, prefix, child) {
|
|
10
|
+
return {
|
|
11
|
+
type: 'prefixed',
|
|
12
|
+
range: Range.get(range),
|
|
13
|
+
prefix,
|
|
14
|
+
children: [
|
|
15
|
+
LiteralNode.mock(range, { pool: [prefix] }),
|
|
16
|
+
child,
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
PrefixedNode.mock = mock;
|
|
21
|
+
})(PrefixedNode || (PrefixedNode = {}));
|
|
22
|
+
//# sourceMappingURL=PrefixedNode.js.map
|
|
@@ -5,23 +5,26 @@ import type { ResourceLocationCategory, SymbolAccessType, SymbolUsageType, Tagga
|
|
|
5
5
|
import type { AstNode } from './AstNode.js';
|
|
6
6
|
export type ResourceLocationOptions = {
|
|
7
7
|
accessType?: SymbolAccessType;
|
|
8
|
-
|
|
8
|
+
requireCanonical?: boolean;
|
|
9
9
|
usageType?: SymbolUsageType;
|
|
10
10
|
namespacePathSep?: ':' | '.';
|
|
11
11
|
} & ({
|
|
12
12
|
category: ResourceLocationCategory;
|
|
13
13
|
pool?: undefined;
|
|
14
14
|
allowTag?: false;
|
|
15
|
+
requireTag?: false;
|
|
15
16
|
allowUnknown?: false;
|
|
16
17
|
} | {
|
|
17
18
|
category: TaggableResourceLocationCategory;
|
|
18
19
|
pool?: undefined;
|
|
19
20
|
allowTag?: boolean;
|
|
21
|
+
requireTag?: boolean;
|
|
20
22
|
allowUnknown?: false;
|
|
21
23
|
} | {
|
|
22
24
|
category?: undefined;
|
|
23
25
|
pool: string[];
|
|
24
26
|
allowTag?: false;
|
|
27
|
+
requireTag?: false;
|
|
25
28
|
allowUnknown?: boolean;
|
|
26
29
|
});
|
|
27
30
|
export interface ResourceLocationBaseNode extends AstNode, Partial<ResourceLocation> {
|
|
@@ -21,11 +21,7 @@ export var ResourceLocationNode;
|
|
|
21
21
|
}
|
|
22
22
|
ResourceLocationNode.is = is;
|
|
23
23
|
function mock(range, options) {
|
|
24
|
-
return {
|
|
25
|
-
type: 'resource_location',
|
|
26
|
-
range: Range.get(range),
|
|
27
|
-
options,
|
|
28
|
-
};
|
|
24
|
+
return { type: 'resource_location', range: Range.get(range), options };
|
|
29
25
|
}
|
|
30
26
|
ResourceLocationNode.mock = mock;
|
|
31
27
|
function toString(node, type = 'origin', includesTagPrefix = false) {
|
|
@@ -43,9 +39,7 @@ export var ResourceLocationNode;
|
|
|
43
39
|
switch (type) {
|
|
44
40
|
case 'origin':
|
|
45
41
|
// Use `node.namespace !== undefined`, so that empty namespaces can be correctly restored to string.
|
|
46
|
-
id = node.namespace !== undefined
|
|
47
|
-
? `${node.namespace}${NamespacePathSep}${path}`
|
|
48
|
-
: path;
|
|
42
|
+
id = node.namespace !== undefined ? `${node.namespace}${NamespacePathSep}${path}` : path;
|
|
49
43
|
break;
|
|
50
44
|
case 'full':
|
|
51
45
|
// Use `node.namespace` before `||`, so that both undefined and empty value can result in the default namespace.
|
package/lib/node/StringNode.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type EscapeChar = (typeof EscapeChars)[number];
|
|
|
7
7
|
export declare namespace EscapeChar {
|
|
8
8
|
function is(expected: EscapeChar[] | undefined, c: string): c is EscapeChar;
|
|
9
9
|
}
|
|
10
|
-
export declare const EscapeTable: Map<"\"" | "'" | "b" | "f" | "n" | "r" | "t"
|
|
10
|
+
export declare const EscapeTable: Map<"\"" | "'" | "\\" | "b" | "f" | "n" | "r" | "t", string>;
|
|
11
11
|
export type Quote = "'" | '"';
|
|
12
12
|
export interface StringOptions {
|
|
13
13
|
colorTokenType?: ColorTokenType;
|
|
@@ -50,6 +50,7 @@ export interface StringOptions {
|
|
|
50
50
|
export type QuoteTypeConfig = 'always double' | 'always single' | 'prefer double' | 'prefer single';
|
|
51
51
|
export interface StringBaseNode extends AstNode {
|
|
52
52
|
readonly options: StringOptions;
|
|
53
|
+
quote?: Quote;
|
|
53
54
|
value: string;
|
|
54
55
|
readonly valueMap: IndexMap;
|
|
55
56
|
}
|
package/lib/node/StringNode.js
CHANGED
|
@@ -32,10 +32,7 @@ export var StringNode;
|
|
|
32
32
|
range,
|
|
33
33
|
options,
|
|
34
34
|
value: '',
|
|
35
|
-
valueMap: [{
|
|
36
|
-
inner: Range.create(0),
|
|
37
|
-
outer: Range.create(range.start),
|
|
38
|
-
}],
|
|
35
|
+
valueMap: [{ inner: Range.create(0), outer: Range.create(range.start) }],
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
38
|
StringNode.mock = mock;
|
package/lib/node/SymbolNode.js
CHANGED
|
@@ -7,12 +7,7 @@ export var SymbolNode;
|
|
|
7
7
|
}
|
|
8
8
|
SymbolNode.is = is;
|
|
9
9
|
function mock(range, options) {
|
|
10
|
-
return {
|
|
11
|
-
type: 'symbol',
|
|
12
|
-
range: Range.get(range),
|
|
13
|
-
options,
|
|
14
|
-
value: '',
|
|
15
|
-
};
|
|
10
|
+
return { type: 'symbol', range: Range.get(range), options, value: '' };
|
|
16
11
|
}
|
|
17
12
|
SymbolNode.mock = mock;
|
|
18
13
|
})(SymbolNode || (SymbolNode = {}));
|
package/lib/node/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './IntegerNode.js';
|
|
|
8
8
|
export * from './ListNode.js';
|
|
9
9
|
export * from './LiteralNode.js';
|
|
10
10
|
export * from './LongNode.js';
|
|
11
|
+
export * from './PrefixedNode.js';
|
|
11
12
|
export * from './RecordNode.js';
|
|
12
13
|
export * from './ResourceLocationNode.js';
|
|
13
14
|
export * from './Sequence.js';
|
package/lib/node/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './IntegerNode.js';
|
|
|
8
8
|
export * from './ListNode.js';
|
|
9
9
|
export * from './LiteralNode.js';
|
|
10
10
|
export * from './LongNode.js';
|
|
11
|
+
export * from './PrefixedNode.js';
|
|
11
12
|
export * from './RecordNode.js';
|
|
12
13
|
export * from './ResourceLocationNode.js';
|
|
13
14
|
export * from './Sequence.js';
|
package/lib/parser/comment.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ interface Options {
|
|
|
7
7
|
/**
|
|
8
8
|
* `Failure` when three isn't a comment.
|
|
9
9
|
*/
|
|
10
|
-
export declare function comment({ singleLinePrefixes, includesEol
|
|
10
|
+
export declare function comment({ singleLinePrefixes, includesEol }: Options): Parser<CommentNode>;
|
|
11
11
|
export {};
|
|
12
12
|
//# sourceMappingURL=comment.d.ts.map
|
package/lib/parser/comment.js
CHANGED
|
@@ -3,14 +3,10 @@ import { Failure } from './Parser.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* `Failure` when three isn't a comment.
|
|
5
5
|
*/
|
|
6
|
-
export function comment({ singleLinePrefixes, includesEol
|
|
6
|
+
export function comment({ singleLinePrefixes, includesEol }) {
|
|
7
7
|
return (src, _ctx) => {
|
|
8
8
|
const start = src.cursor;
|
|
9
|
-
const ans = {
|
|
10
|
-
type: 'comment',
|
|
11
|
-
range: Range.create(start),
|
|
12
|
-
comment: '',
|
|
13
|
-
};
|
|
9
|
+
const ans = { type: 'comment', range: Range.create(start), comment: '' };
|
|
14
10
|
for (const prefix of singleLinePrefixes) {
|
|
15
11
|
if (src.peek(prefix.length) === prefix) {
|
|
16
12
|
if (includesEol) {
|
package/lib/parser/error.js
CHANGED
|
@@ -8,10 +8,7 @@ export const error = (src, ctx) => {
|
|
|
8
8
|
if (!src.canRead()) {
|
|
9
9
|
return undefined;
|
|
10
10
|
}
|
|
11
|
-
const ans = {
|
|
12
|
-
type: 'error',
|
|
13
|
-
range: Range.create(src, () => src.skipRemaining()),
|
|
14
|
-
};
|
|
11
|
+
const ans = { type: 'error', range: Range.create(src, () => src.skipRemaining()) };
|
|
15
12
|
ctx.err.report(localize('error.unparseable-content'), ans);
|
|
16
13
|
return ans;
|
|
17
14
|
};
|
package/lib/parser/file.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { FileNode } from '../node/index.js';
|
|
2
2
|
import { AstNode } from '../node/index.js';
|
|
3
|
-
import type { InfallibleParser } from './Parser.js';
|
|
3
|
+
import type { InfallibleParser, Parser } from './Parser.js';
|
|
4
4
|
/**
|
|
5
5
|
* Dispatches to the corresponding parser for the language.
|
|
6
6
|
* @throws If there's no parser registered for this language ID.
|
|
7
7
|
*/
|
|
8
|
-
export declare function file(): InfallibleParser<FileNode<AstNode>>;
|
|
8
|
+
export declare function file(parser: Parser<AstNode>): InfallibleParser<FileNode<AstNode>>;
|
|
9
9
|
//# sourceMappingURL=file.d.ts.map
|
package/lib/parser/file.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Failure } from './Parser.js';
|
|
|
6
6
|
* Dispatches to the corresponding parser for the language.
|
|
7
7
|
* @throws If there's no parser registered for this language ID.
|
|
8
8
|
*/
|
|
9
|
-
export function file() {
|
|
9
|
+
export function file(parser) {
|
|
10
10
|
return (src, ctx) => {
|
|
11
11
|
const fullRange = Range.create(src, src.string.length);
|
|
12
12
|
const ans = {
|
|
@@ -17,7 +17,6 @@ export function file() {
|
|
|
17
17
|
parserErrors: [],
|
|
18
18
|
};
|
|
19
19
|
src.skipWhitespace();
|
|
20
|
-
const parser = ctx.meta.getParserForLanguageId(ctx.doc.languageId);
|
|
21
20
|
const result = parser(src, ctx);
|
|
22
21
|
if (result && result !== Failure) {
|
|
23
22
|
ans.children.push(result);
|
package/lib/parser/float.js
CHANGED
|
@@ -6,11 +6,7 @@ const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
|
6
6
|
};
|
|
7
7
|
export function float(options) {
|
|
8
8
|
return (src, ctx) => {
|
|
9
|
-
const ans = {
|
|
10
|
-
type: 'float',
|
|
11
|
-
range: Range.create(src),
|
|
12
|
-
value: 0,
|
|
13
|
-
};
|
|
9
|
+
const ans = { type: 'float', range: Range.create(src), value: 0 };
|
|
14
10
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
15
11
|
src.skip();
|
|
16
12
|
}
|
|
@@ -43,8 +39,7 @@ export function float(options) {
|
|
|
43
39
|
else if (!options.pattern.test(raw)) {
|
|
44
40
|
ctx.err.report(localize('parser.float.illegal', options.pattern), ans);
|
|
45
41
|
}
|
|
46
|
-
else if ((options.min && ans.value < options.min) ||
|
|
47
|
-
(options.max && ans.value > options.max)) {
|
|
42
|
+
else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
|
|
48
43
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
49
44
|
onOutOfRange(ans, src, ctx, options);
|
|
50
45
|
}
|
package/lib/parser/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { list } from './list.js';
|
|
|
9
9
|
export * from './literal.js';
|
|
10
10
|
export { long } from './long.js';
|
|
11
11
|
export * from './Parser.js';
|
|
12
|
+
export * from './prefixed.js';
|
|
12
13
|
export { record } from './record.js';
|
|
13
14
|
export * from './resourceLocation.js';
|
|
14
15
|
export * from './string.js';
|
package/lib/parser/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { list } from './list.js';
|
|
|
10
10
|
export * from './literal.js';
|
|
11
11
|
export { long } from './long.js';
|
|
12
12
|
export * from './Parser.js';
|
|
13
|
+
export * from './prefixed.js';
|
|
13
14
|
export { record } from './record.js';
|
|
14
15
|
export * from './resourceLocation.js';
|
|
15
16
|
export * from './string.js';
|
package/lib/parser/integer.js
CHANGED
|
@@ -6,11 +6,7 @@ const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
|
6
6
|
};
|
|
7
7
|
export function integer(options) {
|
|
8
8
|
return (src, ctx) => {
|
|
9
|
-
const ans = {
|
|
10
|
-
type: 'integer',
|
|
11
|
-
range: Range.create(src),
|
|
12
|
-
value: 0,
|
|
13
|
-
};
|
|
9
|
+
const ans = { type: 'integer', range: Range.create(src), value: 0 };
|
|
14
10
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
15
11
|
src.skip();
|
|
16
12
|
}
|
|
@@ -32,8 +28,8 @@ export function integer(options) {
|
|
|
32
28
|
else if (!options.pattern.test(raw) || isOnlySign) {
|
|
33
29
|
ctx.err.report(localize('parser.integer.illegal', options.pattern), ans);
|
|
34
30
|
}
|
|
35
|
-
else if ((options.min !== undefined && ans.value < options.min)
|
|
36
|
-
(options.max !== undefined && ans.value > options.max)) {
|
|
31
|
+
else if ((options.min !== undefined && ans.value < options.min)
|
|
32
|
+
|| (options.max !== undefined && ans.value > options.max)) {
|
|
37
33
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
38
34
|
onOutOfRange(ans, src, ctx, options);
|
|
39
35
|
}
|
package/lib/parser/list.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export interface Options<V extends AstNode> {
|
|
|
8
8
|
trailingSep: boolean;
|
|
9
9
|
end: string;
|
|
10
10
|
}
|
|
11
|
-
export declare function list<V extends AstNode>({ start, value, sep, trailingSep, end
|
|
11
|
+
export declare function list<V extends AstNode>({ start, value, sep, trailingSep, end }: Options<V>): InfallibleParser<ListNode<V>>;
|
|
12
12
|
//# sourceMappingURL=list.d.ts.map
|
package/lib/parser/list.js
CHANGED
|
@@ -2,13 +2,9 @@ import { localeQuote, localize } from '@spyglassmc/locales';
|
|
|
2
2
|
import { Range } from '../source/index.js';
|
|
3
3
|
import { Failure } from './Parser.js';
|
|
4
4
|
import { attempt } from './util.js';
|
|
5
|
-
export function list({ start, value, sep, trailingSep, end
|
|
5
|
+
export function list({ start, value, sep, trailingSep, end }) {
|
|
6
6
|
return (src, ctx) => {
|
|
7
|
-
const ans = {
|
|
8
|
-
type: 'list',
|
|
9
|
-
range: Range.create(src),
|
|
10
|
-
children: [],
|
|
11
|
-
};
|
|
7
|
+
const ans = { type: 'list', range: Range.create(src), children: [] };
|
|
12
8
|
if (src.trySkip(start)) {
|
|
13
9
|
src.skipWhitespace();
|
|
14
10
|
let requiresValueSep = false;
|