@spyglassmc/core 0.1.1 → 0.3.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.
- package/README.md +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +2 -0
- package/lib/common/Dev.d.ts +11 -0
- package/lib/common/Dev.js +90 -0
- package/lib/{service → common}/Logger.d.ts +0 -0
- package/lib/{service → common}/Logger.js +2 -5
- package/lib/common/Operations.d.ts +12 -0
- package/lib/common/Operations.js +33 -0
- package/lib/common/ReadonlyProxy.d.ts +9 -0
- package/lib/common/ReadonlyProxy.js +23 -0
- package/lib/common/StateProxy.d.ts +35 -0
- package/lib/common/StateProxy.js +69 -0
- package/lib/common/TwoWayMap.d.ts +21 -0
- package/lib/common/TwoWayMap.js +69 -0
- package/lib/common/externals/BrowserExternals.d.ts +3 -0
- package/lib/common/externals/BrowserExternals.js +191 -0
- package/lib/common/externals/NodeJsExternals.d.ts +3 -0
- package/lib/common/externals/NodeJsExternals.js +152 -0
- package/lib/common/externals/downloader.d.ts +31 -0
- package/lib/common/externals/downloader.js +32 -0
- package/lib/common/externals/index.d.ts +96 -0
- package/lib/common/externals/index.js +2 -0
- package/lib/common/index.d.ts +8 -1
- package/lib/common/index.js +8 -13
- package/lib/common/util.d.ts +50 -39
- package/lib/common/util.js +73 -122
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -19
- package/lib/node/AstNode.d.ts +12 -11
- package/lib/node/AstNode.js +10 -16
- package/lib/node/BooleanNode.d.ts +2 -2
- package/lib/node/BooleanNode.js +4 -7
- package/lib/node/CommentNode.d.ts +6 -5
- package/lib/node/CommentNode.js +4 -9
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +8 -4
- package/lib/node/FileNode.js +3 -6
- package/lib/node/FloatNode.d.ts +3 -3
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +3 -3
- package/lib/node/IntegerNode.js +4 -7
- package/lib/node/ListNode.d.ts +2 -2
- package/lib/node/ListNode.js +2 -5
- package/lib/node/LiteralNode.d.ts +5 -5
- package/lib/node/LiteralNode.js +5 -8
- package/lib/node/LongNode.d.ts +3 -3
- package/lib/node/LongNode.js +4 -7
- package/lib/node/RecordNode.d.ts +2 -2
- package/lib/node/RecordNode.js +2 -5
- package/lib/node/ResourceLocationNode.d.ts +8 -10
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +4 -3
- package/lib/node/Sequence.js +4 -6
- package/lib/node/StringNode.d.ts +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +5 -5
- package/lib/node/SymbolNode.js +5 -8
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -27
- package/lib/nodejs.d.ts +2 -0
- package/lib/nodejs.js +2 -0
- package/lib/parser/Parser.d.ts +3 -3
- package/lib/parser/Parser.js +1 -4
- package/lib/parser/boolean.d.ts +2 -2
- package/lib/parser/boolean.js +3 -6
- package/lib/parser/comment.d.ts +2 -2
- package/lib/parser/comment.js +5 -9
- package/lib/parser/empty.d.ts +1 -1
- package/lib/parser/empty.js +1 -5
- package/lib/parser/error.d.ts +2 -2
- package/lib/parser/error.js +5 -9
- package/lib/parser/file.d.ts +3 -3
- package/lib/parser/file.js +9 -13
- package/lib/parser/float.d.ts +4 -4
- package/lib/parser/float.js +12 -16
- package/lib/parser/index.d.ts +16 -16
- package/lib/parser/index.js +16 -34
- package/lib/parser/integer.d.ts +4 -4
- package/lib/parser/integer.js +10 -14
- package/lib/parser/list.d.ts +2 -2
- package/lib/parser/list.js +15 -19
- package/lib/parser/literal.d.ts +2 -2
- package/lib/parser/literal.js +5 -9
- package/lib/parser/long.d.ts +4 -4
- package/lib/parser/long.js +10 -14
- package/lib/parser/record.d.ts +3 -3
- package/lib/parser/record.js +20 -24
- package/lib/parser/resourceLocation.d.ts +2 -2
- package/lib/parser/resourceLocation.js +12 -24
- package/lib/parser/string.d.ts +7 -7
- package/lib/parser/string.js +40 -44
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +30 -12
- package/lib/parser/util.js +78 -65
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +4 -3
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +4 -3
- package/lib/processor/SignatureHelpProvider.js +1 -2
- package/lib/processor/binder/Binder.d.ts +26 -0
- package/lib/processor/binder/Binder.js +18 -0
- package/lib/processor/binder/builtin.d.ts +27 -0
- package/lib/processor/binder/builtin.js +116 -0
- package/lib/processor/binder/index.d.ts +3 -0
- package/lib/processor/binder/index.js +3 -0
- package/lib/processor/checker/Checker.d.ts +2 -2
- package/lib/processor/checker/Checker.js +1 -5
- package/lib/processor/checker/builtin.d.ts +4 -4
- package/lib/processor/checker/builtin.js +22 -33
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -27
- package/lib/processor/colorizer/Colorizer.d.ts +6 -5
- package/lib/processor/colorizer/Colorizer.js +8 -11
- package/lib/processor/colorizer/builtin.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +33 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -27
- package/lib/processor/completer/Completer.d.ts +6 -5
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +10 -9
- package/lib/processor/completer/builtin.js +59 -75
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -27
- package/lib/processor/formatter/Formatter.d.ts +4 -3
- package/lib/processor/formatter/Formatter.js +2 -7
- package/lib/processor/formatter/builtin.d.ts +3 -3
- package/lib/processor/formatter/builtin.js +22 -36
- package/lib/processor/formatter/index.d.ts +2 -2
- package/lib/processor/formatter/index.js +2 -27
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -21
- package/lib/processor/linter/Linter.d.ts +4 -3
- package/lib/processor/linter/Linter.js +1 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
- package/lib/processor/linter/builtin.d.ts +4 -3
- package/lib/processor/linter/builtin.js +19 -26
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -27
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +8 -6
- package/lib/service/CacheService.js +35 -56
- package/lib/service/Config.d.ts +17 -16
- package/lib/service/Config.js +56 -51
- package/lib/service/Context.d.ts +24 -21
- package/lib/service/Context.js +40 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -39
- package/lib/service/Downloader.js +37 -106
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +11 -15
- package/lib/service/FileService.d.ts +40 -14
- package/lib/service/FileService.js +107 -81
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/MetaRegistry.d.ts +17 -12
- package/lib/service/MetaRegistry.js +81 -73
- package/lib/service/Profiler.d.ts +3 -2
- package/lib/service/Profiler.js +81 -45
- package/lib/service/Project.d.ts +101 -73
- package/lib/service/Project.js +438 -367
- package/lib/service/Service.d.ts +19 -29
- package/lib/service/Service.js +57 -53
- package/lib/service/SymbolLocations.d.ts +3 -3
- package/lib/service/SymbolLocations.js +4 -7
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/SymbolRegistrar.js +1 -2
- package/lib/service/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/fileUtil.d.ts +21 -41
- package/lib/service/fileUtil.js +59 -129
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -31
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +2 -2
- package/lib/source/LanguageError.js +3 -6
- package/lib/source/Location.d.ts +3 -3
- package/lib/source/Location.js +6 -9
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Offset.js +4 -7
- package/lib/source/Position.js +2 -5
- package/lib/source/PositionRange.d.ts +2 -2
- package/lib/source/PositionRange.js +14 -17
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +9 -4
- package/lib/source/Source.js +58 -31
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -20
- package/lib/symbol/Symbol.d.ts +15 -14
- package/lib/symbol/Symbol.js +53 -68
- package/lib/symbol/SymbolUtil.d.ts +30 -39
- package/lib/symbol/SymbolUtil.js +189 -168
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -15
- package/package.json +7 -4
- package/lib/service/Operations.d.ts +0 -8
- package/lib/service/Operations.js +0 -26
- package/lib/symbol/UriBinder.d.ts +0 -3
- package/lib/symbol/UriBinder.js +0 -3
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
const common_1 = require("../common");
|
|
6
|
-
const source_1 = require("../source");
|
|
1
|
+
import { arrayToMessage, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { ResourceLocation } from '../common/index.js';
|
|
3
|
+
import { Range } from '../source/index.js';
|
|
7
4
|
const Terminators = new Set([' ', '\r', '\n', '=', ',', '"', "'", '{', '}', '[', ']', '(', ')', ';']);
|
|
8
5
|
const LegalCharacters = new Set([
|
|
9
6
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
10
7
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
11
8
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '.',
|
|
12
9
|
]);
|
|
13
|
-
function resourceLocation(options) {
|
|
10
|
+
export function resourceLocation(options) {
|
|
14
11
|
return (src, ctx) => {
|
|
15
12
|
const ans = {
|
|
16
13
|
type: 'resource_location',
|
|
17
|
-
range:
|
|
14
|
+
range: Range.create(src),
|
|
18
15
|
options,
|
|
19
16
|
};
|
|
20
|
-
if (src.trySkip(
|
|
17
|
+
if (src.trySkip(ResourceLocation.TagPrefix)) {
|
|
21
18
|
ans.isTag = true;
|
|
22
19
|
}
|
|
23
20
|
const start = src.cursor;
|
|
@@ -27,15 +24,15 @@ function resourceLocation(options) {
|
|
|
27
24
|
const raw = src.sliceToCursor(start);
|
|
28
25
|
ans.range.end = src.cursor;
|
|
29
26
|
if (raw.length === 0) {
|
|
30
|
-
ctx.err.report(
|
|
27
|
+
ctx.err.report(localize('expected', localize('resource-location')), ans);
|
|
31
28
|
}
|
|
32
29
|
else {
|
|
33
|
-
const sepIndex = raw.indexOf(options.namespacePathSep ??
|
|
30
|
+
const sepIndex = raw.indexOf(options.namespacePathSep ?? ResourceLocation.NamespacePathSep);
|
|
34
31
|
if (sepIndex >= 0) {
|
|
35
32
|
ans.namespace = raw.slice(0, sepIndex);
|
|
36
33
|
}
|
|
37
34
|
const rawPath = raw.slice(sepIndex + 1);
|
|
38
|
-
ans.path = rawPath.split(
|
|
35
|
+
ans.path = rawPath.split(ResourceLocation.PathSep);
|
|
39
36
|
// Check characters.
|
|
40
37
|
/* istanbul ignore next */
|
|
41
38
|
const illegalChars = [...new Set([
|
|
@@ -43,25 +40,16 @@ function resourceLocation(options) {
|
|
|
43
40
|
...[...rawPath].filter(c => c !== '/' && !LegalCharacters.has(c)),
|
|
44
41
|
])];
|
|
45
42
|
if (illegalChars.length) {
|
|
46
|
-
ctx.err.report(
|
|
43
|
+
ctx.err.report(localize('parser.resource-location.illegal', arrayToMessage(illegalChars, true, 'and')), ans);
|
|
47
44
|
}
|
|
48
45
|
if (ans.isTag && !options.allowTag) {
|
|
49
|
-
ctx.err.report(
|
|
46
|
+
ctx.err.report(localize('parser.resource-location.tag-diallowed'), ans);
|
|
50
47
|
}
|
|
51
48
|
if (!ans.namespace && options.isPredicate) {
|
|
52
|
-
ctx.err.report(
|
|
53
|
-
}
|
|
54
|
-
if (options.category) {
|
|
55
|
-
const fullRaw = common_1.ResourceLocation.lengthen(options.namespacePathSep === '.'
|
|
56
|
-
? raw.replace('.', common_1.ResourceLocation.NamespacePathSep)
|
|
57
|
-
: raw);
|
|
58
|
-
ctx.symbols
|
|
59
|
-
.query(ctx.doc, ans.isTag ? `tag/${options.category}` : options.category, fullRaw)
|
|
60
|
-
.enter({ usage: { type: options.usageType, node: ans, accessType: options.accessType } });
|
|
49
|
+
ctx.err.report(localize('parser.resource-location.namespace-expected'), ans);
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
return ans;
|
|
64
53
|
};
|
|
65
54
|
}
|
|
66
|
-
exports.resourceLocation = resourceLocation;
|
|
67
55
|
//# sourceMappingURL=resourceLocation.js.map
|
package/lib/parser/string.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { StringNode, StringOptions } from '../node';
|
|
2
|
-
import type { InfallibleParser } from '../parser';
|
|
3
|
-
import type { ParserContext } from '../service';
|
|
4
|
-
import type { IndexMap } from '../source';
|
|
5
|
-
import type { Parser, Result, Returnable } from './Parser';
|
|
1
|
+
import type { StringNode, StringOptions } from '../node/index.js';
|
|
2
|
+
import type { InfallibleParser } from '../parser/index.js';
|
|
3
|
+
import type { ParserContext } from '../service/index.js';
|
|
4
|
+
import type { IndexMap } from '../source/index.js';
|
|
5
|
+
import type { Parser, Result, Returnable } from './Parser.js';
|
|
6
6
|
export declare function string(options: StringOptions): InfallibleParser<StringNode>;
|
|
7
7
|
export declare function parseStringValue<T extends Returnable>(parser: Parser<T>, value: string, map: IndexMap, ctx: ParserContext): Result<T>;
|
|
8
8
|
export declare const BrigadierUnquotableCharacters: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "_", ".", "+", "-"];
|
|
9
|
-
export declare const BrigadierUnquotableCharacterSet: Set<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "
|
|
9
|
+
export declare const BrigadierUnquotableCharacterSet: Set<"0" | "k" | "v" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "l" | "m" | "n" | "o" | "q" | "r" | "s" | "t" | "u" | "w" | "x" | "y" | "z" | "_" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z">;
|
|
10
10
|
export declare const BrigadierUnquotablePattern: RegExp;
|
|
11
11
|
export declare const BrigadierUnquotableOption: {
|
|
12
12
|
allowEmpty: boolean;
|
|
13
|
-
allowList: Set<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "
|
|
13
|
+
allowList: Set<"0" | "k" | "v" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "l" | "m" | "n" | "o" | "q" | "r" | "s" | "t" | "u" | "w" | "x" | "y" | "z" | "_" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z">;
|
|
14
14
|
};
|
|
15
15
|
export declare const BrigadierStringOptions: StringOptions;
|
|
16
16
|
export declare const brigadierString: InfallibleParser<StringNode>;
|
package/lib/parser/string.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const source_1 = require("../source");
|
|
8
|
-
const Parser_1 = require("./Parser");
|
|
9
|
-
function string(options) {
|
|
1
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import { EscapeChar, EscapeTable } from '../node/index.js';
|
|
4
|
+
import { Range, Source } from '../source/index.js';
|
|
5
|
+
import { Failure } from './Parser.js';
|
|
6
|
+
export function string(options) {
|
|
10
7
|
return (src, ctx) => {
|
|
11
8
|
const ans = {
|
|
12
9
|
type: 'string',
|
|
13
|
-
range:
|
|
10
|
+
range: Range.create(src),
|
|
14
11
|
options,
|
|
15
12
|
value: '',
|
|
16
13
|
valueMap: [],
|
|
@@ -20,56 +17,58 @@ function string(options) {
|
|
|
20
17
|
const currentQuote = src.read();
|
|
21
18
|
const contentStart = src.cursor;
|
|
22
19
|
while (src.canRead() && src.peek() !== currentQuote) {
|
|
23
|
-
const
|
|
24
|
-
const c = src.read();
|
|
20
|
+
const c = src.peek();
|
|
25
21
|
if (options.escapable && c === '\\') {
|
|
22
|
+
const cStart = src.cursor;
|
|
23
|
+
src.skip();
|
|
26
24
|
const c2 = src.read();
|
|
27
|
-
if (c2 === '\\' || c2 === currentQuote ||
|
|
25
|
+
if (c2 === '\\' || c2 === currentQuote || EscapeChar.is(options.escapable.characters, c2)) {
|
|
28
26
|
ans.valueMap.push({
|
|
29
|
-
inner:
|
|
30
|
-
outer:
|
|
27
|
+
inner: Range.create(ans.value.length, ans.value.length + 1),
|
|
28
|
+
outer: Range.create(cStart, src),
|
|
31
29
|
});
|
|
32
|
-
ans.value +=
|
|
30
|
+
ans.value += EscapeTable.get(c2);
|
|
33
31
|
}
|
|
34
32
|
else if (options.escapable.unicode && c2 === 'u') {
|
|
35
33
|
const hex = src.peek(4);
|
|
36
34
|
if (/^[0-9a-f]{4}$/i.test(hex)) {
|
|
37
35
|
src.skip(4);
|
|
38
36
|
ans.valueMap.push({
|
|
39
|
-
inner:
|
|
40
|
-
outer:
|
|
37
|
+
inner: Range.create(ans.value.length, ans.value.length + 1),
|
|
38
|
+
outer: Range.create(cStart, src),
|
|
41
39
|
});
|
|
42
40
|
ans.value += String.fromCharCode(parseInt(hex, 16));
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
ctx.err.report(
|
|
43
|
+
ctx.err.report(localize('parser.string.illegal-unicode-escape'), Range.create(src, src.getCharRange(3).end));
|
|
46
44
|
ans.valueMap.push({
|
|
47
|
-
inner:
|
|
48
|
-
outer:
|
|
45
|
+
inner: Range.create(ans.value.length, ans.value.length + 1),
|
|
46
|
+
outer: Range.create(cStart, src),
|
|
49
47
|
});
|
|
50
48
|
ans.value += c2;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
else {
|
|
54
52
|
if (!options.escapable.allowUnknown) {
|
|
55
|
-
ctx.err.report(
|
|
53
|
+
ctx.err.report(localize('parser.string.illegal-escape', localeQuote(c2)), src.getCharRange(-1));
|
|
56
54
|
}
|
|
57
55
|
ans.valueMap.push({
|
|
58
|
-
inner:
|
|
59
|
-
outer:
|
|
56
|
+
inner: Range.create(ans.value.length, ans.value.length + 1),
|
|
57
|
+
outer: Range.create(cStart, src),
|
|
60
58
|
});
|
|
61
59
|
ans.value += c2;
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
else {
|
|
63
|
+
src.skip();
|
|
65
64
|
ans.value += c;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
if (!src.trySkip(currentQuote)) {
|
|
69
|
-
ctx.err.report(
|
|
68
|
+
ctx.err.report(localize('expected', localeQuote(currentQuote)), src);
|
|
70
69
|
}
|
|
71
70
|
if (!options.quotes.includes(currentQuote)) {
|
|
72
|
-
ctx.err.report(
|
|
71
|
+
ctx.err.report(localize('parser.string.illegal-quote', options.quotes), ans);
|
|
73
72
|
}
|
|
74
73
|
start = contentStart;
|
|
75
74
|
}
|
|
@@ -78,17 +77,17 @@ function string(options) {
|
|
|
78
77
|
ans.value += src.read();
|
|
79
78
|
}
|
|
80
79
|
if (!ans.value && !options.unquotable.allowEmpty) {
|
|
81
|
-
ctx.err.report(
|
|
80
|
+
ctx.err.report(localize('expected', localize('string')), src);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
else {
|
|
85
|
-
ctx.err.report(
|
|
84
|
+
ctx.err.report(localize('expected', options.quotes), src);
|
|
86
85
|
}
|
|
87
|
-
ans.valueMap.unshift({ inner:
|
|
86
|
+
ans.valueMap.unshift({ inner: Range.create(0), outer: Range.create(start) });
|
|
88
87
|
if (options.value?.parser) {
|
|
89
88
|
const valueResult = parseStringValue(options.value.parser, ans.value, ans.valueMap, ctx);
|
|
90
89
|
/* istanbul ignore else */
|
|
91
|
-
if (valueResult !==
|
|
90
|
+
if (valueResult !== Failure) {
|
|
92
91
|
ans.children = [valueResult];
|
|
93
92
|
}
|
|
94
93
|
}
|
|
@@ -96,34 +95,31 @@ function string(options) {
|
|
|
96
95
|
return ans;
|
|
97
96
|
};
|
|
98
97
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const valueSrc = new source_1.Source(value, map);
|
|
98
|
+
export function parseStringValue(parser, value, map, ctx) {
|
|
99
|
+
const valueSrc = new Source(value, map);
|
|
102
100
|
const valueCtx = {
|
|
103
101
|
...ctx,
|
|
104
|
-
doc:
|
|
102
|
+
doc: TextDocument.create(ctx.doc.uri, ctx.doc.languageId, ctx.doc.version, value),
|
|
105
103
|
};
|
|
106
104
|
// TODO: Mark trailing string as errors.
|
|
107
105
|
return parser(valueSrc, valueCtx);
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
exports.BrigadierUnquotableCharacters = Object.freeze([
|
|
107
|
+
export const BrigadierUnquotableCharacters = Object.freeze([
|
|
111
108
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
112
109
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
113
110
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
114
111
|
'_', '.', '+', '-',
|
|
115
112
|
]);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
export const BrigadierUnquotableCharacterSet = new Set(BrigadierUnquotableCharacters);
|
|
114
|
+
export const BrigadierUnquotablePattern = /^[0-9A-Za-z_\.\+\-]*$/;
|
|
115
|
+
export const BrigadierUnquotableOption = { allowEmpty: true, allowList: BrigadierUnquotableCharacterSet };
|
|
116
|
+
export const BrigadierStringOptions = {
|
|
120
117
|
escapable: {},
|
|
121
118
|
quotes: ['"', "'"],
|
|
122
|
-
unquotable:
|
|
119
|
+
unquotable: BrigadierUnquotableOption,
|
|
123
120
|
};
|
|
124
|
-
|
|
125
|
-
function isAllowedCharacter(c, options) {
|
|
121
|
+
export const brigadierString = string(BrigadierStringOptions);
|
|
122
|
+
export function isAllowedCharacter(c, options) {
|
|
126
123
|
return options.allowList?.has(c) ?? !options.blockList?.has(c);
|
|
127
124
|
}
|
|
128
|
-
exports.isAllowedCharacter = isAllowedCharacter;
|
|
129
125
|
//# sourceMappingURL=string.js.map
|
package/lib/parser/symbol.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { SymbolNode, SymbolOptions } from '../node/SymbolNode';
|
|
2
|
-
import type { AllCategory } from '../symbol';
|
|
3
|
-
import type { InfallibleParser } from './Parser';
|
|
1
|
+
import type { SymbolNode, SymbolOptions } from '../node/SymbolNode.js';
|
|
2
|
+
import type { AllCategory } from '../symbol/index.js';
|
|
3
|
+
import type { InfallibleParser } from './Parser.js';
|
|
4
4
|
/**
|
|
5
5
|
* This parser reads _everything_ until the end of the {@link Source}.
|
|
6
6
|
*
|
package/lib/parser/symbol.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.symbol = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
function symbol(param) {
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export function symbol(param) {
|
|
6
3
|
const options = getOptions(param);
|
|
7
|
-
return (src,
|
|
4
|
+
return (src, _ctx) => {
|
|
8
5
|
const ans = {
|
|
9
6
|
type: 'symbol',
|
|
10
|
-
range:
|
|
7
|
+
range: Range.create(src),
|
|
11
8
|
options,
|
|
12
9
|
value: src.readRemaining(),
|
|
13
10
|
};
|
|
14
|
-
if (ans.value) {
|
|
15
|
-
const path = options.parentPath ? [...options.parentPath, ans.value] : [ans.value];
|
|
16
|
-
ctx.symbols
|
|
17
|
-
.query(ctx.doc, options.category, ...path)
|
|
18
|
-
.enter({ usage: { type: options.usageType, node: ans, accessType: options.accessType } });
|
|
19
|
-
}
|
|
20
11
|
ans.range.end = src.cursor;
|
|
21
12
|
return ans;
|
|
22
13
|
};
|
|
23
14
|
}
|
|
24
|
-
exports.symbol = symbol;
|
|
25
15
|
function getOptions(param) {
|
|
26
16
|
if (typeof param === 'string') {
|
|
27
17
|
return { category: param };
|
package/lib/parser/util.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AstNode } from '../node';
|
|
2
|
-
import { SequenceUtil } from '../node';
|
|
3
|
-
import type { ParserContext } from '../service';
|
|
4
|
-
import type { ErrorSeverity, ReadonlySource, Source } from '../source';
|
|
5
|
-
import type { InfallibleParser, Parser, Result, Returnable } from './Parser';
|
|
1
|
+
import type { AstNode } from '../node/index.js';
|
|
2
|
+
import { SequenceUtil } from '../node/index.js';
|
|
3
|
+
import type { ParserContext } from '../service/index.js';
|
|
4
|
+
import type { ErrorSeverity, ReadonlySource, Source } from '../source/index.js';
|
|
5
|
+
import type { InfallibleParser, Parser, Result, Returnable } from './Parser.js';
|
|
6
6
|
declare type ExtractNodeType<P extends Parser<Returnable>> = P extends Parser<infer V> ? V : never;
|
|
7
7
|
/**
|
|
8
8
|
* @template PA Parser array.
|
|
@@ -57,7 +57,9 @@ export declare function sequence<GN extends AstNode = never, PA extends SP<AstNo
|
|
|
57
57
|
*
|
|
58
58
|
* @returns A parser that takes a sequence with the passed-in parser being repeated zero or more times.
|
|
59
59
|
*/
|
|
60
|
-
export declare function repeat<CN extends AstNode>(parser: InfallibleParser<CN | SequenceUtil<CN>>, parseGap?: InfallibleParser<CN[]>):
|
|
60
|
+
export declare function repeat<CN extends AstNode>(parser: InfallibleParser<CN | SequenceUtil<CN>>, parseGap?: InfallibleParser<CN[]>): {
|
|
61
|
+
_inputParserIsInfallible: never;
|
|
62
|
+
} & void;
|
|
61
63
|
export declare function repeat<CN extends AstNode>(parser: Parser<CN | SequenceUtil<CN>>, parseGap?: InfallibleParser<CN[]>): InfallibleParser<SequenceUtil<CN>>;
|
|
62
64
|
export interface AnyOutObject {
|
|
63
65
|
/**
|
|
@@ -80,26 +82,41 @@ export declare function any<PA extends Parser<Returnable>[]>(parsers: PA, out?:
|
|
|
80
82
|
* @returns A parser that fails when the passed-in parser didn't move the cursor at all.
|
|
81
83
|
*/
|
|
82
84
|
export declare function failOnEmpty<T extends Returnable>(parser: Parser<T>): Parser<T>;
|
|
85
|
+
/**
|
|
86
|
+
* @returns A parser that fails when the passed-in parser produced any errors.
|
|
87
|
+
*/
|
|
88
|
+
export declare function failOnError<T extends Returnable>(parser: Parser<T>): Parser<T>;
|
|
83
89
|
/**
|
|
84
90
|
* @returns A parser that takes an optional syntax component.
|
|
85
91
|
*/
|
|
86
|
-
export declare function optional<N extends Returnable>(parser: InfallibleParser<N>):
|
|
92
|
+
export declare function optional<N extends Returnable>(parser: InfallibleParser<N>): {
|
|
93
|
+
_inputParserIsInfallible: never;
|
|
94
|
+
} & void;
|
|
87
95
|
export declare function optional<N extends Returnable>(parser: Parser<N>): InfallibleParser<N | undefined>;
|
|
88
96
|
/**
|
|
89
97
|
* @param parser Must be fallible.
|
|
90
98
|
*
|
|
91
99
|
* @returns A parser that returns the return value of the `parser`, or the return value of `defaultValue` it it's a `Failure`.
|
|
92
100
|
*/
|
|
93
|
-
export declare function recover<N extends Returnable>(parser: InfallibleParser<N>, defaultValue: (src: Source, ctx: ParserContext) => N):
|
|
101
|
+
export declare function recover<N extends Returnable>(parser: InfallibleParser<N>, defaultValue: (src: Source, ctx: ParserContext) => N): {
|
|
102
|
+
_inputParserIsInfallible: never;
|
|
103
|
+
} & void;
|
|
94
104
|
export declare function recover<N extends Returnable>(parser: Parser<N>, defaultValue: (src: Source, ctx: ParserContext) => N): InfallibleParser<N>;
|
|
105
|
+
declare type GettableParser = Parser<Returnable> | {
|
|
106
|
+
get: () => Parser<Returnable>;
|
|
107
|
+
};
|
|
108
|
+
declare type ExtractFromGettableParser<T extends GettableParser> = T extends {
|
|
109
|
+
get: () => infer V;
|
|
110
|
+
} ? V : T extends Parser<Returnable> ? T : never;
|
|
95
111
|
declare type Case = {
|
|
96
112
|
predicate?: (this: void, src: ReadonlySource) => boolean;
|
|
97
|
-
|
|
113
|
+
prefix?: string;
|
|
114
|
+
parser: GettableParser;
|
|
98
115
|
};
|
|
99
116
|
/**
|
|
100
117
|
* @template CA Case array.
|
|
101
118
|
*/
|
|
102
|
-
export declare function select<CA extends readonly Case[]>(cases: CA): Parser<ExtractNodeType<CA[number]['parser']
|
|
119
|
+
export declare function select<CA extends readonly Case[]>(cases: CA): ExtractFromGettableParser<CA[number]['parser']> extends InfallibleParser<Returnable> ? InfallibleParser<ExtractNodeType<ExtractFromGettableParser<CA[number]['parser']>>> : Parser<ExtractNodeType<ExtractFromGettableParser<CA[number]['parser']>>>;
|
|
103
120
|
/**
|
|
104
121
|
* @returns A parser that returns the return value of `fn`.
|
|
105
122
|
*
|
|
@@ -107,10 +124,10 @@ export declare function select<CA extends readonly Case[]>(cases: CA): Parser<Ex
|
|
|
107
124
|
*/
|
|
108
125
|
export declare function map<NA extends Returnable, NB extends Returnable = NA>(parser: InfallibleParser<NA>, fn: (res: NA, src: Source, ctx: ParserContext) => NB): InfallibleParser<NB>;
|
|
109
126
|
export declare function map<NA extends Returnable, NB extends Returnable = NA>(parser: Parser<NA>, fn: (res: NA, src: Source, ctx: ParserContext) => NB): Parser<NB>;
|
|
110
|
-
export declare function setType<N extends AstNode, T extends string>(type: T, parser: InfallibleParser<N>): InfallibleParser<Omit<N, 'type'> & {
|
|
127
|
+
export declare function setType<N extends Omit<AstNode, 'type'>, T extends string>(type: T, parser: InfallibleParser<N>): InfallibleParser<Omit<N, 'type'> & {
|
|
111
128
|
type: T;
|
|
112
129
|
}>;
|
|
113
|
-
export declare function setType<N extends AstNode, T extends string>(type: T, parser: Parser<N>): Parser<Omit<N, 'type'> & {
|
|
130
|
+
export declare function setType<N extends Omit<AstNode, 'type'>, T extends string>(type: T, parser: Parser<N>): Parser<Omit<N, 'type'> & {
|
|
114
131
|
type: T;
|
|
115
132
|
}>;
|
|
116
133
|
/**
|
|
@@ -130,5 +147,6 @@ export declare function stopBefore<N extends Returnable>(parser: Parser<N>, ...t
|
|
|
130
147
|
*/
|
|
131
148
|
export declare function acceptOnly<N extends Returnable>(parser: InfallibleParser<N>, ...characters: (string | readonly string[])[]): InfallibleParser<N>;
|
|
132
149
|
export declare function acceptOnly<N extends Returnable>(parser: Parser<N>, ...characters: (string | readonly string[])[]): Parser<N>;
|
|
150
|
+
export declare function acceptIf<P extends Parser<AstNode>>(parser: P, predicate: (this: void, char: string) => boolean): P extends InfallibleParser<infer N> ? InfallibleParser<N> : P extends Parser<infer N> ? Parser<N> : never;
|
|
133
151
|
export {};
|
|
134
152
|
//# sourceMappingURL=util.d.ts.map
|