@spyglassmc/core 0.4.0 → 0.4.2
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 +5 -2
- package/lib/common/Operations.js +7 -3
- package/lib/common/ReadonlyProxy.d.ts +2 -2
- package/lib/common/ReadonlyProxy.js +3 -1
- package/lib/common/StateProxy.d.ts +2 -2
- package/lib/common/StateProxy.js +18 -7
- package/lib/common/externals/BrowserExternals.js +2 -9
- package/lib/common/externals/NodeJsExternals.js +11 -18
- package/lib/common/externals/downloader.d.ts +2 -2
- package/lib/common/externals/index.d.ts +2 -5
- package/lib/common/util.d.ts +8 -7
- package/lib/common/util.js +16 -12
- package/lib/node/AstNode.d.ts +1 -1
- package/lib/node/AstNode.js +9 -5
- package/lib/node/CommentNode.d.ts +2 -2
- package/lib/node/FileNode.js +6 -1
- package/lib/node/ResourceLocationNode.d.ts +3 -3
- package/lib/node/ResourceLocationNode.js +9 -5
- package/lib/node/StringNode.d.ts +3 -3
- package/lib/node/StringNode.js +4 -1
- package/lib/parser/Parser.d.ts +5 -5
- package/lib/parser/boolean.js +1 -1
- package/lib/parser/comment.d.ts +1 -1
- package/lib/parser/comment.js +1 -1
- package/lib/parser/float.d.ts +1 -1
- package/lib/parser/float.js +2 -1
- package/lib/parser/integer.d.ts +1 -1
- package/lib/parser/integer.js +2 -1
- package/lib/parser/list.d.ts +1 -1
- package/lib/parser/list.js +3 -3
- package/lib/parser/long.d.ts +1 -1
- package/lib/parser/long.js +2 -1
- package/lib/parser/record.d.ts +1 -1
- package/lib/parser/record.js +18 -8
- package/lib/parser/resourceLocation.js +61 -8
- package/lib/parser/string.js +79 -8
- package/lib/parser/util.d.ts +7 -7
- package/lib/parser/util.js +14 -5
- package/lib/processor/ColorInfoProvider.d.ts +3 -3
- package/lib/processor/ColorInfoProvider.js +22 -7
- package/lib/processor/InlayHintProvider.d.ts +1 -1
- package/lib/processor/SignatureHelpProvider.d.ts +1 -1
- package/lib/processor/binder/Binder.d.ts +1 -1
- package/lib/processor/binder/builtin.d.ts +2 -2
- package/lib/processor/binder/builtin.js +30 -18
- package/lib/processor/binder/index.d.ts +1 -1
- package/lib/processor/binder/index.js +1 -1
- package/lib/processor/checker/Checker.d.ts +3 -3
- package/lib/processor/checker/builtin.d.ts +2 -3
- package/lib/processor/checker/builtin.js +12 -13
- package/lib/processor/colorizer/Colorizer.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +8 -7
- package/lib/processor/completer/Completer.d.ts +1 -1
- package/lib/processor/completer/Completer.js +4 -2
- package/lib/processor/completer/builtin.js +33 -26
- package/lib/processor/formatter/Formatter.d.ts +1 -1
- package/lib/processor/formatter/Formatter.js +3 -1
- package/lib/processor/formatter/builtin.js +14 -12
- package/lib/processor/linter/Linter.d.ts +1 -1
- package/lib/processor/linter/builtin/undeclaredSymbol.js +47 -24
- package/lib/processor/linter/builtin.js +7 -8
- package/lib/processor/util.d.ts +1 -1
- package/lib/service/CacheService.d.ts +1 -1
- package/lib/service/CacheService.js +9 -6
- package/lib/service/Config.d.ts +11 -11
- package/lib/service/Config.js +28 -21
- package/lib/service/Dependency.d.ts +3 -3
- package/lib/service/Downloader.js +12 -7
- package/lib/service/FileService.d.ts +1 -1
- package/lib/service/FileService.js +28 -10
- package/lib/service/MetaRegistry.js +7 -6
- package/lib/service/Profiler.js +10 -5
- package/lib/service/Project.d.ts +5 -5
- package/lib/service/Project.js +45 -34
- package/lib/service/Service.js +31 -12
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/UriProcessor.d.ts +3 -3
- package/lib/service/fileUtil.d.ts +2 -2
- package/lib/service/fileUtil.js +2 -1
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +1 -1
- package/lib/source/LanguageError.js +1 -1
- package/lib/source/Location.d.ts +1 -1
- package/lib/source/Location.js +4 -1
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +6 -3
- package/lib/source/Source.d.ts +4 -4
- package/lib/source/Source.js +3 -1
- package/lib/symbol/Symbol.d.ts +19 -19
- package/lib/symbol/Symbol.js +27 -12
- package/lib/symbol/SymbolUtil.d.ts +6 -6
- package/lib/symbol/SymbolUtil.js +76 -44
- package/package.json +2 -2
package/lib/parser/float.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface InfallibleOptions extends OptionsBase {
|
|
|
26
26
|
failsOnEmpty?: false;
|
|
27
27
|
}
|
|
28
28
|
/** @internal For test only */
|
|
29
|
-
export
|
|
29
|
+
export type Options = FallibleOptions | InfallibleOptions;
|
|
30
30
|
export declare function float(options: InfallibleOptions): InfallibleParser<FloatNode>;
|
|
31
31
|
export declare function float(options: FallibleOptions): Parser<FloatNode>;
|
|
32
32
|
export {};
|
package/lib/parser/float.js
CHANGED
|
@@ -43,7 +43,8 @@ export function float(options) {
|
|
|
43
43
|
else if (!options.pattern.test(raw)) {
|
|
44
44
|
ctx.err.report(localize('parser.float.illegal', options.pattern), ans);
|
|
45
45
|
}
|
|
46
|
-
else if ((options.min && ans.value < options.min) ||
|
|
46
|
+
else if ((options.min && ans.value < options.min) ||
|
|
47
|
+
(options.max && ans.value > options.max)) {
|
|
47
48
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
48
49
|
onOutOfRange(ans, src, ctx, options);
|
|
49
50
|
}
|
package/lib/parser/integer.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface InfallibleOptions extends OptionsBase {
|
|
|
26
26
|
failsOnEmpty?: false;
|
|
27
27
|
}
|
|
28
28
|
/** @internal For test only */
|
|
29
|
-
export
|
|
29
|
+
export type Options = FallibleOptions | InfallibleOptions;
|
|
30
30
|
export declare function integer(options: InfallibleOptions): InfallibleParser<IntegerNode>;
|
|
31
31
|
export declare function integer(options: FallibleOptions): Parser<IntegerNode>;
|
|
32
32
|
export {};
|
package/lib/parser/integer.js
CHANGED
|
@@ -32,7 +32,8 @@ export function integer(options) {
|
|
|
32
32
|
else if (!options.pattern.test(raw) || isOnlySign) {
|
|
33
33
|
ctx.err.report(localize('parser.integer.illegal', options.pattern), ans);
|
|
34
34
|
}
|
|
35
|
-
else if ((options.min !== undefined && ans.value < options.min) ||
|
|
35
|
+
else if ((options.min !== undefined && ans.value < options.min) ||
|
|
36
|
+
(options.max !== undefined && ans.value > options.max)) {
|
|
36
37
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
37
38
|
onOutOfRange(ans, src, ctx, options);
|
|
38
39
|
}
|
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 }: Options<V>): InfallibleParser<ListNode<V>>;
|
|
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,7 +2,7 @@ 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
7
|
const ans = {
|
|
8
8
|
type: 'list',
|
|
@@ -34,14 +34,14 @@ export function list({ start, value, sep, trailingSep, end }) {
|
|
|
34
34
|
let sepRange = undefined;
|
|
35
35
|
src.skipWhitespace();
|
|
36
36
|
requiresValueSep = true;
|
|
37
|
-
if (hasValueSep = src.peek(sep.length) === sep) {
|
|
37
|
+
if ((hasValueSep = src.peek(sep.length) === sep)) {
|
|
38
38
|
sepRange = Range.create(src, () => src.skip(sep.length));
|
|
39
39
|
}
|
|
40
40
|
// Create item.
|
|
41
41
|
ans.children.push({
|
|
42
42
|
type: 'item',
|
|
43
43
|
range: Range.create(itemStart, src),
|
|
44
|
-
...valueNode ? { children: [valueNode] } : {},
|
|
44
|
+
...(valueNode ? { children: [valueNode] } : {}),
|
|
45
45
|
value: valueNode,
|
|
46
46
|
sep: sepRange,
|
|
47
47
|
});
|
package/lib/parser/long.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface InfallibleOptions extends OptionsBase {
|
|
|
26
26
|
failsOnEmpty?: false;
|
|
27
27
|
}
|
|
28
28
|
/** @internal For test only */
|
|
29
|
-
export
|
|
29
|
+
export type Options = FallibleOptions | InfallibleOptions;
|
|
30
30
|
export declare function long(options: InfallibleOptions): InfallibleParser<LongNode>;
|
|
31
31
|
export declare function long(options: FallibleOptions): Parser<LongNode>;
|
|
32
32
|
export {};
|
package/lib/parser/long.js
CHANGED
|
@@ -36,7 +36,8 @@ export function long(options) {
|
|
|
36
36
|
else if (!options.pattern.test(raw) || isOnlySign) {
|
|
37
37
|
ctx.err.report(localize('parser.long.illegal', options.pattern), ans);
|
|
38
38
|
}
|
|
39
|
-
else if ((options.min && ans.value < options.min) ||
|
|
39
|
+
else if ((options.min && ans.value < options.min) ||
|
|
40
|
+
(options.max && ans.value > options.max)) {
|
|
40
41
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
41
42
|
onOutOfRange(ans, src, ctx, options);
|
|
42
43
|
}
|
package/lib/parser/record.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export interface Options<K extends AstNode, V extends AstNode> {
|
|
|
18
18
|
/**
|
|
19
19
|
* @returns A parser that parses something coming in a key-value pair form. e.g. SNBT objects, entity selector arguments.
|
|
20
20
|
*/
|
|
21
|
-
export declare function record<K extends AstNode, V extends AstNode>({ start, pair, end }: Options<K, V>): InfallibleParser<RecordNode<K, V>>;
|
|
21
|
+
export declare function record<K extends AstNode, V extends AstNode>({ start, pair, end, }: Options<K, V>): InfallibleParser<RecordNode<K, V>>;
|
|
22
22
|
//# sourceMappingURL=record.d.ts.map
|
package/lib/parser/record.js
CHANGED
|
@@ -5,7 +5,7 @@ import { attempt } from './util.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* @returns A parser that parses something coming in a key-value pair form. e.g. SNBT objects, entity selector arguments.
|
|
7
7
|
*/
|
|
8
|
-
export function record({ start, pair, end }) {
|
|
8
|
+
export function record({ start, pair, end, }) {
|
|
9
9
|
return (src, ctx) => {
|
|
10
10
|
const ans = {
|
|
11
11
|
type: 'record',
|
|
@@ -26,8 +26,10 @@ export function record({ start, pair, end }) {
|
|
|
26
26
|
}
|
|
27
27
|
// Key.
|
|
28
28
|
const keyStart = src.cursor;
|
|
29
|
-
const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd } = attempt(pair.key, src, ctx);
|
|
30
|
-
if (keyResult === Failure ||
|
|
29
|
+
const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd, } = attempt(pair.key, src, ctx);
|
|
30
|
+
if (keyResult === Failure ||
|
|
31
|
+
(keyEnd - keyStart === 0 &&
|
|
32
|
+
![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
|
|
31
33
|
ctx.err.report(localize('expected', localize('parser.record.key')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
|
|
32
34
|
}
|
|
33
35
|
else {
|
|
@@ -45,10 +47,14 @@ export function record({ start, pair, end }) {
|
|
|
45
47
|
}
|
|
46
48
|
// Value.
|
|
47
49
|
src.skipWhitespace();
|
|
48
|
-
const valueParser = typeof pair.value === 'function'
|
|
50
|
+
const valueParser = typeof pair.value === 'function'
|
|
51
|
+
? pair.value
|
|
52
|
+
: pair.value.get(ans, key);
|
|
49
53
|
const valueStart = src.cursor;
|
|
50
|
-
const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd } = attempt(valueParser, src, ctx);
|
|
51
|
-
if (valueResult === Failure ||
|
|
54
|
+
const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd, } = attempt(valueParser, src, ctx);
|
|
55
|
+
if (valueResult === Failure ||
|
|
56
|
+
(valueEnd - valueStart === 0 &&
|
|
57
|
+
![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
|
|
52
58
|
ctx.err.report(localize('expected', localize('parser.record.value')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
|
|
53
59
|
}
|
|
54
60
|
else {
|
|
@@ -59,14 +65,18 @@ export function record({ start, pair, end }) {
|
|
|
59
65
|
let endCharRange = undefined;
|
|
60
66
|
src.skipWhitespace();
|
|
61
67
|
requiresPairEnd = true;
|
|
62
|
-
if (hasPairEnd = src.peek(pair.end.length) === pair.end) {
|
|
68
|
+
if ((hasPairEnd = src.peek(pair.end.length) === pair.end)) {
|
|
63
69
|
endCharRange = Range.create(src, () => src.skip(pair.end.length));
|
|
64
70
|
}
|
|
65
71
|
// Create pair.
|
|
66
72
|
ans.children.push({
|
|
67
73
|
type: 'pair',
|
|
68
74
|
range: Range.create(pairStart, src),
|
|
69
|
-
...(key || value
|
|
75
|
+
...(key || value
|
|
76
|
+
? {
|
|
77
|
+
children: [key, value].filter((v) => !!v),
|
|
78
|
+
}
|
|
79
|
+
: {}),
|
|
70
80
|
key,
|
|
71
81
|
sep: sepCharRange,
|
|
72
82
|
value,
|
|
@@ -1,11 +1,62 @@
|
|
|
1
1
|
import { arrayToMessage, localize } from '@spyglassmc/locales';
|
|
2
2
|
import { ResourceLocation } from '../common/index.js';
|
|
3
3
|
import { Range } from '../source/index.js';
|
|
4
|
-
const Terminators = new Set([
|
|
4
|
+
const Terminators = new Set([
|
|
5
|
+
' ',
|
|
6
|
+
'\r',
|
|
7
|
+
'\n',
|
|
8
|
+
'=',
|
|
9
|
+
',',
|
|
10
|
+
'"',
|
|
11
|
+
"'",
|
|
12
|
+
'{',
|
|
13
|
+
'}',
|
|
14
|
+
'[',
|
|
15
|
+
']',
|
|
16
|
+
'(',
|
|
17
|
+
')',
|
|
18
|
+
';',
|
|
19
|
+
]);
|
|
5
20
|
const LegalCharacters = new Set([
|
|
6
|
-
'a',
|
|
7
|
-
'
|
|
8
|
-
'
|
|
21
|
+
'a',
|
|
22
|
+
'b',
|
|
23
|
+
'c',
|
|
24
|
+
'd',
|
|
25
|
+
'e',
|
|
26
|
+
'f',
|
|
27
|
+
'g',
|
|
28
|
+
'h',
|
|
29
|
+
'i',
|
|
30
|
+
'j',
|
|
31
|
+
'k',
|
|
32
|
+
'l',
|
|
33
|
+
'm',
|
|
34
|
+
'n',
|
|
35
|
+
'o',
|
|
36
|
+
'p',
|
|
37
|
+
'q',
|
|
38
|
+
'r',
|
|
39
|
+
's',
|
|
40
|
+
't',
|
|
41
|
+
'u',
|
|
42
|
+
'v',
|
|
43
|
+
'w',
|
|
44
|
+
'x',
|
|
45
|
+
'y',
|
|
46
|
+
'z',
|
|
47
|
+
'0',
|
|
48
|
+
'1',
|
|
49
|
+
'2',
|
|
50
|
+
'3',
|
|
51
|
+
'4',
|
|
52
|
+
'5',
|
|
53
|
+
'6',
|
|
54
|
+
'7',
|
|
55
|
+
'8',
|
|
56
|
+
'9',
|
|
57
|
+
'_',
|
|
58
|
+
'-',
|
|
59
|
+
'.',
|
|
9
60
|
]);
|
|
10
61
|
export function resourceLocation(options) {
|
|
11
62
|
return (src, ctx) => {
|
|
@@ -35,10 +86,12 @@ export function resourceLocation(options) {
|
|
|
35
86
|
ans.path = rawPath.split(ResourceLocation.PathSep);
|
|
36
87
|
// Check characters.
|
|
37
88
|
/* istanbul ignore next */
|
|
38
|
-
const illegalChars = [
|
|
39
|
-
|
|
40
|
-
...[...
|
|
41
|
-
|
|
89
|
+
const illegalChars = [
|
|
90
|
+
...new Set([
|
|
91
|
+
...[...(ans.namespace ?? [])].filter((c) => !LegalCharacters.has(c)),
|
|
92
|
+
...[...rawPath].filter((c) => c !== '/' && !LegalCharacters.has(c)),
|
|
93
|
+
]),
|
|
94
|
+
];
|
|
42
95
|
if (illegalChars.length) {
|
|
43
96
|
ctx.err.report(localize('parser.resource-location.illegal', arrayToMessage(illegalChars, true, 'and')), ans);
|
|
44
97
|
}
|
package/lib/parser/string.js
CHANGED
|
@@ -22,7 +22,9 @@ export function string(options) {
|
|
|
22
22
|
const cStart = src.cursor;
|
|
23
23
|
src.skip();
|
|
24
24
|
const c2 = src.read();
|
|
25
|
-
if (c2 === '\\' ||
|
|
25
|
+
if (c2 === '\\' ||
|
|
26
|
+
c2 === currentQuote ||
|
|
27
|
+
EscapeChar.is(options.escapable.characters, c2)) {
|
|
26
28
|
ans.valueMap.push({
|
|
27
29
|
inner: Range.create(ans.value.length, ans.value.length + 1),
|
|
28
30
|
outer: Range.create(cStart, src),
|
|
@@ -73,7 +75,8 @@ export function string(options) {
|
|
|
73
75
|
start = contentStart;
|
|
74
76
|
}
|
|
75
77
|
else if (options.unquotable) {
|
|
76
|
-
while (src.canRead() &&
|
|
78
|
+
while (src.canRead() &&
|
|
79
|
+
isAllowedCharacter(src.peek(), options.unquotable)) {
|
|
77
80
|
ans.value += src.read();
|
|
78
81
|
}
|
|
79
82
|
if (!ans.value && !options.unquotable.allowEmpty) {
|
|
@@ -83,7 +86,10 @@ export function string(options) {
|
|
|
83
86
|
else {
|
|
84
87
|
ctx.err.report(localize('expected', options.quotes), src);
|
|
85
88
|
}
|
|
86
|
-
ans.valueMap.unshift({
|
|
89
|
+
ans.valueMap.unshift({
|
|
90
|
+
inner: Range.create(0),
|
|
91
|
+
outer: Range.create(start),
|
|
92
|
+
});
|
|
87
93
|
if (options.value?.parser) {
|
|
88
94
|
const valueResult = parseStringValue(options.value.parser, ans.value, ans.valueMap, ctx);
|
|
89
95
|
/* istanbul ignore else */
|
|
@@ -105,14 +111,79 @@ export function parseStringValue(parser, value, map, ctx) {
|
|
|
105
111
|
return parser(valueSrc, valueCtx);
|
|
106
112
|
}
|
|
107
113
|
export const BrigadierUnquotableCharacters = Object.freeze([
|
|
108
|
-
'0',
|
|
109
|
-
'
|
|
110
|
-
'
|
|
111
|
-
'
|
|
114
|
+
'0',
|
|
115
|
+
'1',
|
|
116
|
+
'2',
|
|
117
|
+
'3',
|
|
118
|
+
'4',
|
|
119
|
+
'5',
|
|
120
|
+
'6',
|
|
121
|
+
'7',
|
|
122
|
+
'8',
|
|
123
|
+
'9',
|
|
124
|
+
'A',
|
|
125
|
+
'B',
|
|
126
|
+
'C',
|
|
127
|
+
'D',
|
|
128
|
+
'E',
|
|
129
|
+
'F',
|
|
130
|
+
'G',
|
|
131
|
+
'H',
|
|
132
|
+
'I',
|
|
133
|
+
'J',
|
|
134
|
+
'K',
|
|
135
|
+
'L',
|
|
136
|
+
'M',
|
|
137
|
+
'N',
|
|
138
|
+
'O',
|
|
139
|
+
'P',
|
|
140
|
+
'Q',
|
|
141
|
+
'R',
|
|
142
|
+
'S',
|
|
143
|
+
'T',
|
|
144
|
+
'U',
|
|
145
|
+
'V',
|
|
146
|
+
'W',
|
|
147
|
+
'X',
|
|
148
|
+
'Y',
|
|
149
|
+
'Z',
|
|
150
|
+
'a',
|
|
151
|
+
'b',
|
|
152
|
+
'c',
|
|
153
|
+
'd',
|
|
154
|
+
'e',
|
|
155
|
+
'f',
|
|
156
|
+
'g',
|
|
157
|
+
'h',
|
|
158
|
+
'i',
|
|
159
|
+
'j',
|
|
160
|
+
'k',
|
|
161
|
+
'l',
|
|
162
|
+
'm',
|
|
163
|
+
'n',
|
|
164
|
+
'o',
|
|
165
|
+
'p',
|
|
166
|
+
'q',
|
|
167
|
+
'r',
|
|
168
|
+
's',
|
|
169
|
+
't',
|
|
170
|
+
'u',
|
|
171
|
+
'v',
|
|
172
|
+
'w',
|
|
173
|
+
'x',
|
|
174
|
+
'y',
|
|
175
|
+
'z',
|
|
176
|
+
'_',
|
|
177
|
+
'.',
|
|
178
|
+
'+',
|
|
179
|
+
'-',
|
|
112
180
|
]);
|
|
113
181
|
export const BrigadierUnquotableCharacterSet = new Set(BrigadierUnquotableCharacters);
|
|
114
182
|
export const BrigadierUnquotablePattern = /^[0-9A-Za-z_\.\+\-]*$/;
|
|
115
|
-
export const BrigadierUnquotableOption = {
|
|
183
|
+
export const BrigadierUnquotableOption = {
|
|
184
|
+
allowEmpty: true,
|
|
185
|
+
allowList: BrigadierUnquotableCharacterSet,
|
|
186
|
+
};
|
|
116
187
|
export const BrigadierStringOptions = {
|
|
117
188
|
escapable: {},
|
|
118
189
|
quotes: ['"', "'"],
|
package/lib/parser/util.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { SequenceUtil } from '../node/index.js';
|
|
|
3
3
|
import type { ParserContext } from '../service/index.js';
|
|
4
4
|
import type { ErrorSeverity, ReadonlySource, Source } from '../source/index.js';
|
|
5
5
|
import type { InfallibleParser, Parser, Result, Returnable } from './Parser.js';
|
|
6
|
-
|
|
6
|
+
type ExtractNodeType<P extends Parser<Returnable>> = P extends Parser<infer V> ? V : never;
|
|
7
7
|
/**
|
|
8
8
|
* @template PA Parser array.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
type ExtractNodeTypes<PA extends Parser<Returnable>[]> = ExtractNodeType<PA[number]>;
|
|
11
11
|
export interface AttemptResult<N extends Returnable = AstNode> {
|
|
12
12
|
result: Result<N>;
|
|
13
13
|
updateSrcAndCtx: () => void;
|
|
@@ -27,10 +27,10 @@ interface InfallibleAttemptResult<N extends Returnable = AstNode> extends Attemp
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function attempt<N extends Returnable = AstNode>(parser: InfallibleParser<N>, src: Source, ctx: ParserContext): InfallibleAttemptResult<N>;
|
|
29
29
|
export declare function attempt<N extends Returnable = AstNode>(parser: Parser<N>, src: Source, ctx: ParserContext): AttemptResult<N>;
|
|
30
|
-
|
|
30
|
+
type SP<CN extends AstNode> = SIP<CN> | Parser<CN | SequenceUtil<CN> | undefined> | {
|
|
31
31
|
get: (result: SequenceUtil<CN>) => Parser<CN | SequenceUtil<CN> | undefined> | undefined;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
type SIP<CN extends AstNode> = InfallibleParser<CN | SequenceUtil<CN> | undefined> | {
|
|
34
34
|
get: (result: SequenceUtil<CN>) => InfallibleParser<CN | SequenceUtil<CN> | undefined> | undefined;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
@@ -102,13 +102,13 @@ export declare function recover<N extends Returnable>(parser: InfallibleParser<N
|
|
|
102
102
|
_inputParserIsInfallible: never;
|
|
103
103
|
} & void;
|
|
104
104
|
export declare function recover<N extends Returnable>(parser: Parser<N>, defaultValue: (src: Source, ctx: ParserContext) => N): InfallibleParser<N>;
|
|
105
|
-
|
|
105
|
+
type GettableParser = Parser<Returnable> | {
|
|
106
106
|
get: () => Parser<Returnable>;
|
|
107
107
|
};
|
|
108
|
-
|
|
108
|
+
type ExtractFromGettableParser<T extends GettableParser> = T extends {
|
|
109
109
|
get: () => infer V;
|
|
110
110
|
} ? V : T extends Parser<Returnable> ? T : never;
|
|
111
|
-
|
|
111
|
+
type Case = {
|
|
112
112
|
predicate?: (this: void, src: ReadonlySource) => boolean;
|
|
113
113
|
prefix?: string;
|
|
114
114
|
regex?: RegExp;
|
package/lib/parser/util.js
CHANGED
|
@@ -82,9 +82,13 @@ export function repeat(parser, parseGap) {
|
|
|
82
82
|
export function any(parsers, out) {
|
|
83
83
|
return (src, ctx) => {
|
|
84
84
|
const results = parsers
|
|
85
|
-
.map((parser, i) => ({
|
|
85
|
+
.map((parser, i) => ({
|
|
86
|
+
attempt: attempt(parser, src, ctx),
|
|
87
|
+
index: i,
|
|
88
|
+
}))
|
|
86
89
|
.filter(({ attempt }) => attempt.result !== Failure)
|
|
87
|
-
.sort((a, b) =>
|
|
90
|
+
.sort((a, b) => b.attempt.endCursor - a.attempt.endCursor ||
|
|
91
|
+
a.attempt.errorAmount - b.attempt.errorAmount);
|
|
88
92
|
if (results.length === 0) {
|
|
89
93
|
if (out) {
|
|
90
94
|
out.index = -1;
|
|
@@ -151,8 +155,13 @@ export function recover(parser, defaultValue) {
|
|
|
151
155
|
export function select(cases) {
|
|
152
156
|
return (src, ctx) => {
|
|
153
157
|
for (const { predicate, prefix, parser, regex } of cases) {
|
|
154
|
-
if (predicate?.(src) ??
|
|
155
|
-
|
|
158
|
+
if (predicate?.(src) ??
|
|
159
|
+
(prefix !== undefined ? src.tryPeek(prefix) : undefined) ??
|
|
160
|
+
(regex && src.matchPattern(regex)) ??
|
|
161
|
+
true) {
|
|
162
|
+
const callableParser = typeof parser === 'object'
|
|
163
|
+
? parser.get()
|
|
164
|
+
: parser;
|
|
156
165
|
return callableParser(src, ctx);
|
|
157
166
|
}
|
|
158
167
|
}
|
|
@@ -170,7 +179,7 @@ export function map(parser, fn) {
|
|
|
170
179
|
};
|
|
171
180
|
}
|
|
172
181
|
export function setType(type, parser) {
|
|
173
|
-
return map(parser, res => {
|
|
182
|
+
return map(parser, (res) => {
|
|
174
183
|
const { type: _type, ...restResult } = res;
|
|
175
184
|
const ans = {
|
|
176
185
|
type,
|
|
@@ -6,7 +6,7 @@ export interface ColorInfo {
|
|
|
6
6
|
/**
|
|
7
7
|
* An array of four decimal numbers within the interval [0, 1] that represent R, G, B, and A respectively.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type Color = [number, number, number, number];
|
|
10
10
|
export declare namespace Color {
|
|
11
11
|
const NamedColors: Map<string, number>;
|
|
12
12
|
const ColorNames: string[];
|
|
@@ -71,12 +71,12 @@ export declare enum ColorFormat {
|
|
|
71
71
|
*/
|
|
72
72
|
CompositeInt = 6
|
|
73
73
|
}
|
|
74
|
-
export
|
|
74
|
+
export type FormattableColor = {
|
|
75
75
|
value: Color;
|
|
76
76
|
format: ColorFormat[];
|
|
77
77
|
range?: Range;
|
|
78
78
|
};
|
|
79
|
-
export
|
|
79
|
+
export type ColorPresentation = {
|
|
80
80
|
label: string;
|
|
81
81
|
text: string;
|
|
82
82
|
range: Range;
|
|
@@ -119,19 +119,34 @@ export var ColorPresentation;
|
|
|
119
119
|
const round = (num) => parseFloat(num.toFixed(3));
|
|
120
120
|
switch (format) {
|
|
121
121
|
case ColorFormat.DecRGBA:
|
|
122
|
-
return color.map(c => round(c)).join(' ');
|
|
122
|
+
return color.map((c) => round(c)).join(' ');
|
|
123
123
|
case ColorFormat.DecRGB:
|
|
124
|
-
return color
|
|
124
|
+
return color
|
|
125
|
+
.slice(0, 3)
|
|
126
|
+
.map((c) => round(c))
|
|
127
|
+
.join(' ');
|
|
125
128
|
case ColorFormat.IntRGBA:
|
|
126
|
-
return color.map(c => Math.round(c * 255)).join(' ');
|
|
129
|
+
return color.map((c) => Math.round(c * 255)).join(' ');
|
|
127
130
|
case ColorFormat.IntRGB:
|
|
128
|
-
return color
|
|
131
|
+
return color
|
|
132
|
+
.slice(0, 3)
|
|
133
|
+
.map((c) => Math.round(c * 255))
|
|
134
|
+
.join(' ');
|
|
129
135
|
case ColorFormat.HexRGBA:
|
|
130
|
-
return `#${Math.round((color[0] * 255 << 24) +
|
|
136
|
+
return `#${Math.round((((color[0] * 255) << 24) +
|
|
137
|
+
((color[1] * 255) << 16) +
|
|
138
|
+
color[2] * 255) <<
|
|
139
|
+
(8 + color[3] * 255))
|
|
140
|
+
.toString(16)
|
|
141
|
+
.padStart(8, '0')}`;
|
|
131
142
|
case ColorFormat.HexRGB:
|
|
132
|
-
return `#${Math.round((color[0] * 255 << 16) + (color[1] * 255 << 8) +
|
|
143
|
+
return `#${Math.round(((color[0] * 255) << 16) + ((color[1] * 255) << 8) +
|
|
144
|
+
color[2] * 255)
|
|
145
|
+
.toString(16)
|
|
146
|
+
.padStart(6, '0')}`;
|
|
133
147
|
case ColorFormat.CompositeInt:
|
|
134
|
-
return `${Math.round((color[0] * 255 << 16) + (color[1] * 255 << 8) +
|
|
148
|
+
return `${Math.round(((color[0] * 255) << 16) + ((color[1] * 255) << 8) +
|
|
149
|
+
color[2] * 255)}`;
|
|
135
150
|
}
|
|
136
151
|
}
|
|
137
152
|
})(ColorPresentation || (ColorPresentation = {}));
|
|
@@ -5,5 +5,5 @@ export interface InlayHint {
|
|
|
5
5
|
offset: number;
|
|
6
6
|
text: string;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type InlayHintProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: ProcessorContext) => readonly InlayHint[];
|
|
9
9
|
//# sourceMappingURL=InlayHintProvider.d.ts.map
|
|
@@ -15,5 +15,5 @@ export interface ParameterInfo {
|
|
|
15
15
|
label: [number, number];
|
|
16
16
|
documentation?: string;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export type SignatureHelpProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: SignatureHelpProviderContext) => SignatureHelp | undefined;
|
|
19
19
|
//# sourceMappingURL=SignatureHelpProvider.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AstNode } from '../../node/index.js';
|
|
2
2
|
import type { BinderContext } from '../../service/index.js';
|
|
3
3
|
declare const IsAsync: unique symbol;
|
|
4
|
-
export
|
|
4
|
+
export type Binder<N extends AstNode> = SyncBinder<N> | AsyncBinder<N>;
|
|
5
5
|
export interface SyncBinderInitializer<N extends AstNode> {
|
|
6
6
|
(node: N, ctx: BinderContext): void;
|
|
7
7
|
}
|
|
@@ -3,13 +3,13 @@ import { ResourceLocationNode } from '../../node/index.js';
|
|
|
3
3
|
import type { BinderContext, MetaRegistry } from '../../service/index.js';
|
|
4
4
|
import type { Binder } from './Binder.js';
|
|
5
5
|
import { AsyncBinder, SyncBinder } from './Binder.js';
|
|
6
|
-
export
|
|
6
|
+
export type AttemptResult = {
|
|
7
7
|
errorAmount: number;
|
|
8
8
|
totalErrorSpan: number;
|
|
9
9
|
updateNodeAndCtx: () => void;
|
|
10
10
|
};
|
|
11
11
|
export declare function attempt<B extends Binder<never>>(binder: B, node: B extends Binder<infer N extends AstNode> ? N : never, ctx: BinderContext): B extends SyncBinder<any> ? AttemptResult : Promise<AttemptResult>;
|
|
12
|
-
|
|
12
|
+
type ExtractBinder<B extends Binder<never>> = B extends Binder<infer N extends AstNode> ? N : never;
|
|
13
13
|
export declare function any<Binders extends Binder<never>[]>(binders: Binders): Binders extends SyncBinder<never>[] ? SyncBinder<ExtractBinder<Binders[number]>> : AsyncBinder<ExtractBinder<Binders[number]>>;
|
|
14
14
|
/**
|
|
15
15
|
* No operation.
|