@spyglassmc/core 0.1.2 → 0.4.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.js +4 -10
- 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 -17
- package/lib/common/util.d.ts +48 -20
- package/lib/common/util.js +71 -86
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- 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 +4 -4
- package/lib/node/LiteralNode.js +4 -7
- 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 +7 -7
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +2 -2
- package/lib/node/Sequence.js +4 -7
- package/lib/node/StringNode.d.ts +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +4 -4
- package/lib/node/SymbolNode.js +4 -7
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -31
- 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 -38
- 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 +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +6 -5
- package/lib/parser/util.js +40 -60
- 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 -31
- 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 +34 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -31
- 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 +47 -63
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- 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 -31
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -25
- 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 +20 -24
- 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 -31
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +13 -8
- package/lib/service/CacheService.js +45 -57
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +23 -20
- package/lib/service/Context.js +39 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -40
- package/lib/service/Downloader.js +37 -110
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +10 -14
- package/lib/service/FileService.d.ts +15 -14
- package/lib/service/FileService.js +55 -92
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/MetaRegistry.d.ts +22 -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 +105 -76
- package/lib/service/Project.js +449 -370
- package/lib/service/Service.d.ts +17 -27
- package/lib/service/Service.js +37 -43
- 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 +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -35
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +20 -6
- package/lib/source/LanguageError.js +16 -9
- 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 +3 -3
- package/lib/source/PositionRange.js +17 -20
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +5 -3
- package/lib/source/Source.js +34 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +5 -4
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +29 -31
- package/lib/symbol/SymbolUtil.js +178 -157
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -19
- 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
package/lib/parser/float.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
const source_1 = require("../source");
|
|
6
|
-
const Parser_1 = require("./Parser");
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range, Source } from '../source/index.js';
|
|
3
|
+
import { Failure } from './Parser.js';
|
|
7
4
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report(
|
|
5
|
+
ctx.err.report(localize('expected', localize('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
6
|
};
|
|
10
|
-
function float(options) {
|
|
7
|
+
export function float(options) {
|
|
11
8
|
return (src, ctx) => {
|
|
12
9
|
const ans = {
|
|
13
10
|
type: 'float',
|
|
14
|
-
range:
|
|
11
|
+
range: Range.create(src),
|
|
15
12
|
value: 0,
|
|
16
13
|
};
|
|
17
14
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
18
15
|
src.skip();
|
|
19
16
|
}
|
|
20
|
-
while (src.canRead() &&
|
|
17
|
+
while (src.canRead() && Source.isDigit(src.peek())) {
|
|
21
18
|
src.skip();
|
|
22
19
|
}
|
|
23
20
|
if (src.trySkip('.')) {
|
|
24
|
-
while (src.canRead() &&
|
|
21
|
+
while (src.canRead() && Source.isDigit(src.peek())) {
|
|
25
22
|
src.skip();
|
|
26
23
|
}
|
|
27
24
|
}
|
|
@@ -30,7 +27,7 @@ function float(options) {
|
|
|
30
27
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
31
28
|
src.skip();
|
|
32
29
|
}
|
|
33
|
-
while (src.canRead() &&
|
|
30
|
+
while (src.canRead() && Source.isDigit(src.peek())) {
|
|
34
31
|
src.skip();
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -39,12 +36,12 @@ function float(options) {
|
|
|
39
36
|
ans.value = parseFloat(raw) || 0;
|
|
40
37
|
if (!raw) {
|
|
41
38
|
if (options.failsOnEmpty) {
|
|
42
|
-
return
|
|
39
|
+
return Failure;
|
|
43
40
|
}
|
|
44
|
-
ctx.err.report(
|
|
41
|
+
ctx.err.report(localize('expected', localize('float')), ans);
|
|
45
42
|
}
|
|
46
43
|
else if (!options.pattern.test(raw)) {
|
|
47
|
-
ctx.err.report(
|
|
44
|
+
ctx.err.report(localize('parser.float.illegal', options.pattern), ans);
|
|
48
45
|
}
|
|
49
46
|
else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
|
|
50
47
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
@@ -53,5 +50,4 @@ function float(options) {
|
|
|
53
50
|
return ans;
|
|
54
51
|
};
|
|
55
52
|
}
|
|
56
|
-
exports.float = float;
|
|
57
53
|
//# sourceMappingURL=float.js.map
|
package/lib/parser/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export * from './boolean';
|
|
2
|
-
export * from './comment';
|
|
3
|
-
export * from './empty';
|
|
4
|
-
export * from './error';
|
|
5
|
-
export * from './file';
|
|
6
|
-
export { float } from './float';
|
|
7
|
-
export { integer } from './integer';
|
|
8
|
-
export { list } from './list';
|
|
9
|
-
export * from './literal';
|
|
10
|
-
export { long } from './long';
|
|
11
|
-
export * from './Parser';
|
|
12
|
-
export { record } from './record';
|
|
13
|
-
export * from './resourceLocation';
|
|
14
|
-
export * from './string';
|
|
15
|
-
export * from './symbol';
|
|
16
|
-
export * from './util';
|
|
1
|
+
export * from './boolean.js';
|
|
2
|
+
export * from './comment.js';
|
|
3
|
+
export * from './empty.js';
|
|
4
|
+
export * from './error.js';
|
|
5
|
+
export * from './file.js';
|
|
6
|
+
export { float } from './float.js';
|
|
7
|
+
export { integer } from './integer.js';
|
|
8
|
+
export { list } from './list.js';
|
|
9
|
+
export * from './literal.js';
|
|
10
|
+
export { long } from './long.js';
|
|
11
|
+
export * from './Parser.js';
|
|
12
|
+
export { record } from './record.js';
|
|
13
|
+
export * from './resourceLocation.js';
|
|
14
|
+
export * from './string.js';
|
|
15
|
+
export * from './symbol.js';
|
|
16
|
+
export * from './util.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/parser/index.js
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* istanbul ignore file */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
__exportStar(require("./boolean"), exports);
|
|
20
|
-
__exportStar(require("./comment"), exports);
|
|
21
|
-
__exportStar(require("./empty"), exports);
|
|
22
|
-
__exportStar(require("./error"), exports);
|
|
23
|
-
__exportStar(require("./file"), exports);
|
|
24
|
-
var float_1 = require("./float");
|
|
25
|
-
Object.defineProperty(exports, "float", { enumerable: true, get: function () { return float_1.float; } });
|
|
26
|
-
var integer_1 = require("./integer");
|
|
27
|
-
Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return integer_1.integer; } });
|
|
28
|
-
var list_1 = require("./list");
|
|
29
|
-
Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_1.list; } });
|
|
30
|
-
__exportStar(require("./literal"), exports);
|
|
31
|
-
var long_1 = require("./long");
|
|
32
|
-
Object.defineProperty(exports, "long", { enumerable: true, get: function () { return long_1.long; } });
|
|
33
|
-
__exportStar(require("./Parser"), exports);
|
|
34
|
-
var record_1 = require("./record");
|
|
35
|
-
Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
|
|
36
|
-
__exportStar(require("./resourceLocation"), exports);
|
|
37
|
-
__exportStar(require("./string"), exports);
|
|
38
|
-
__exportStar(require("./symbol"), exports);
|
|
39
|
-
__exportStar(require("./util"), exports);
|
|
2
|
+
export * from './boolean.js';
|
|
3
|
+
export * from './comment.js';
|
|
4
|
+
export * from './empty.js';
|
|
5
|
+
export * from './error.js';
|
|
6
|
+
export * from './file.js';
|
|
7
|
+
export { float } from './float.js';
|
|
8
|
+
export { integer } from './integer.js';
|
|
9
|
+
export { list } from './list.js';
|
|
10
|
+
export * from './literal.js';
|
|
11
|
+
export { long } from './long.js';
|
|
12
|
+
export * from './Parser.js';
|
|
13
|
+
export { record } from './record.js';
|
|
14
|
+
export * from './resourceLocation.js';
|
|
15
|
+
export * from './string.js';
|
|
16
|
+
export * from './symbol.js';
|
|
17
|
+
export * from './util.js';
|
|
40
18
|
//# sourceMappingURL=index.js.map
|
package/lib/parser/integer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IntegerNode } from '../node';
|
|
2
|
-
import type { ParserContext } from '../service';
|
|
3
|
-
import { Source } from '../source';
|
|
4
|
-
import type { InfallibleParser, Parser } from './Parser';
|
|
1
|
+
import type { IntegerNode } from '../node/index.js';
|
|
2
|
+
import type { ParserContext } from '../service/index.js';
|
|
3
|
+
import { Source } from '../source/index.js';
|
|
4
|
+
import type { InfallibleParser, Parser } from './Parser.js';
|
|
5
5
|
interface OptionsBase {
|
|
6
6
|
pattern: RegExp;
|
|
7
7
|
/**
|
package/lib/parser/integer.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
const source_1 = require("../source");
|
|
6
|
-
const Parser_1 = require("./Parser");
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range, Source } from '../source/index.js';
|
|
3
|
+
import { Failure } from './Parser.js';
|
|
7
4
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report(
|
|
5
|
+
ctx.err.report(localize('expected', localize('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
6
|
};
|
|
10
|
-
function integer(options) {
|
|
7
|
+
export function integer(options) {
|
|
11
8
|
return (src, ctx) => {
|
|
12
9
|
const ans = {
|
|
13
10
|
type: 'integer',
|
|
14
|
-
range:
|
|
11
|
+
range: Range.create(src),
|
|
15
12
|
value: 0,
|
|
16
13
|
};
|
|
17
14
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
18
15
|
src.skip();
|
|
19
16
|
}
|
|
20
|
-
while (src.canRead() &&
|
|
17
|
+
while (src.canRead() && Source.isDigit(src.peek())) {
|
|
21
18
|
src.skip();
|
|
22
19
|
}
|
|
23
20
|
ans.range.end = src.cursor;
|
|
@@ -28,12 +25,12 @@ function integer(options) {
|
|
|
28
25
|
}
|
|
29
26
|
if (!raw) {
|
|
30
27
|
if (options.failsOnEmpty) {
|
|
31
|
-
return
|
|
28
|
+
return Failure;
|
|
32
29
|
}
|
|
33
|
-
ctx.err.report(
|
|
30
|
+
ctx.err.report(localize('expected', localize('integer')), ans);
|
|
34
31
|
}
|
|
35
32
|
else if (!options.pattern.test(raw) || isOnlySign) {
|
|
36
|
-
ctx.err.report(
|
|
33
|
+
ctx.err.report(localize('parser.integer.illegal', options.pattern), ans);
|
|
37
34
|
}
|
|
38
35
|
else if ((options.min !== undefined && ans.value < options.min) || (options.max !== undefined && ans.value > options.max)) {
|
|
39
36
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
@@ -42,5 +39,4 @@ function integer(options) {
|
|
|
42
39
|
return ans;
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
|
-
exports.integer = integer;
|
|
46
42
|
//# sourceMappingURL=integer.js.map
|
package/lib/parser/list.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AstNode, ListNode } from '../node';
|
|
2
|
-
import type { InfallibleParser, Parser } from './Parser';
|
|
1
|
+
import type { AstNode, ListNode } from '../node/index.js';
|
|
2
|
+
import type { InfallibleParser, Parser } from './Parser.js';
|
|
3
3
|
/** @internal For test only */
|
|
4
4
|
export interface Options<V extends AstNode> {
|
|
5
5
|
start: string;
|
package/lib/parser/list.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Parser_1 = require("./Parser");
|
|
7
|
-
const util_1 = require("./util");
|
|
8
|
-
function list({ start, value, sep, trailingSep, end }) {
|
|
1
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range } from '../source/index.js';
|
|
3
|
+
import { Failure } from './Parser.js';
|
|
4
|
+
import { attempt } from './util.js';
|
|
5
|
+
export function list({ start, value, sep, trailingSep, end }) {
|
|
9
6
|
return (src, ctx) => {
|
|
10
7
|
const ans = {
|
|
11
8
|
type: 'list',
|
|
12
|
-
range:
|
|
9
|
+
range: Range.create(src),
|
|
13
10
|
children: [],
|
|
14
11
|
};
|
|
15
12
|
if (src.trySkip(start)) {
|
|
@@ -21,13 +18,13 @@ function list({ start, value, sep, trailingSep, end }) {
|
|
|
21
18
|
let valueNode;
|
|
22
19
|
// Item sep of the last item.
|
|
23
20
|
if (requiresValueSep && !hasValueSep) {
|
|
24
|
-
ctx.err.report(
|
|
21
|
+
ctx.err.report(localize('expected', localeQuote(sep)), src);
|
|
25
22
|
}
|
|
26
23
|
// Value.
|
|
27
24
|
src.skipWhitespace();
|
|
28
|
-
const { result, endCursor, updateSrcAndCtx } =
|
|
29
|
-
if (result ===
|
|
30
|
-
ctx.err.report(
|
|
25
|
+
const { result, endCursor, updateSrcAndCtx } = attempt(value, src, ctx);
|
|
26
|
+
if (result === Failure || endCursor === src.cursor) {
|
|
27
|
+
ctx.err.report(localize('expected', localize('parser.list.value')), Range.create(src, () => src.skipUntilOrEnd(sep, end, '\r', '\n')));
|
|
31
28
|
}
|
|
32
29
|
else {
|
|
33
30
|
updateSrcAndCtx();
|
|
@@ -38,12 +35,12 @@ function list({ start, value, sep, trailingSep, end }) {
|
|
|
38
35
|
src.skipWhitespace();
|
|
39
36
|
requiresValueSep = true;
|
|
40
37
|
if (hasValueSep = src.peek(sep.length) === sep) {
|
|
41
|
-
sepRange =
|
|
38
|
+
sepRange = Range.create(src, () => src.skip(sep.length));
|
|
42
39
|
}
|
|
43
40
|
// Create item.
|
|
44
41
|
ans.children.push({
|
|
45
42
|
type: 'item',
|
|
46
|
-
range:
|
|
43
|
+
range: Range.create(itemStart, src),
|
|
47
44
|
...valueNode ? { children: [valueNode] } : {},
|
|
48
45
|
value: valueNode,
|
|
49
46
|
sep: sepRange,
|
|
@@ -52,19 +49,18 @@ function list({ start, value, sep, trailingSep, end }) {
|
|
|
52
49
|
}
|
|
53
50
|
// Trailing item sep.
|
|
54
51
|
if (hasValueSep && !trailingSep) {
|
|
55
|
-
ctx.err.report(
|
|
52
|
+
ctx.err.report(localize('parser.list.trailing-sep'), ans.children[ans.children.length - 1].sep);
|
|
56
53
|
}
|
|
57
54
|
// End.
|
|
58
55
|
if (!src.trySkip(end)) {
|
|
59
|
-
ctx.err.report(
|
|
56
|
+
ctx.err.report(localize('expected', localeQuote(end)), src);
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
else {
|
|
63
|
-
ctx.err.report(
|
|
60
|
+
ctx.err.report(localize('expected', localeQuote(start)), src);
|
|
64
61
|
}
|
|
65
62
|
ans.range.end = src.cursor;
|
|
66
63
|
return ans;
|
|
67
64
|
};
|
|
68
65
|
}
|
|
69
|
-
exports.list = list;
|
|
70
66
|
//# sourceMappingURL=list.js.map
|
package/lib/parser/literal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LiteralNode, LiteralOptions } from '../node/LiteralNode';
|
|
2
|
-
import type { InfallibleParser } from './Parser';
|
|
1
|
+
import type { LiteralNode, LiteralOptions } from '../node/LiteralNode.js';
|
|
2
|
+
import type { InfallibleParser } from './Parser.js';
|
|
3
3
|
export declare function literal(...pool: string[]): InfallibleParser<LiteralNode>;
|
|
4
4
|
export declare function literal(options: LiteralOptions): InfallibleParser<LiteralNode>;
|
|
5
5
|
//# sourceMappingURL=literal.d.ts.map
|
package/lib/parser/literal.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
const source_1 = require("../source");
|
|
6
|
-
function literal(...param) {
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range } from '../source/index.js';
|
|
3
|
+
export function literal(...param) {
|
|
7
4
|
const options = getOptions(param);
|
|
8
5
|
return (src, ctx) => {
|
|
9
6
|
const ans = {
|
|
10
7
|
type: 'literal',
|
|
11
|
-
range:
|
|
8
|
+
range: Range.create(src),
|
|
12
9
|
options,
|
|
13
10
|
value: '',
|
|
14
11
|
};
|
|
@@ -19,11 +16,10 @@ function literal(...param) {
|
|
|
19
16
|
return ans;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
ctx.err.report(
|
|
19
|
+
ctx.err.report(localize('expected', options.pool), ans);
|
|
23
20
|
return ans;
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
|
-
exports.literal = literal;
|
|
27
23
|
function getOptions(param) {
|
|
28
24
|
let ans;
|
|
29
25
|
if (typeof param[0] === 'object') {
|
package/lib/parser/long.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { LongNode } from '../node';
|
|
2
|
-
import type { ParserContext } from '../service';
|
|
3
|
-
import { Source } from '../source';
|
|
4
|
-
import type { InfallibleParser, Parser } from './Parser';
|
|
1
|
+
import type { LongNode } from '../node/index.js';
|
|
2
|
+
import type { ParserContext } from '../service/index.js';
|
|
3
|
+
import { Source } from '../source/index.js';
|
|
4
|
+
import type { InfallibleParser, Parser } from './Parser.js';
|
|
5
5
|
interface OptionsBase {
|
|
6
6
|
pattern: RegExp;
|
|
7
7
|
/**
|
package/lib/parser/long.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
5
|
-
const source_1 = require("../source");
|
|
6
|
-
const Parser_1 = require("./Parser");
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range, Source } from '../source/index.js';
|
|
3
|
+
import { Failure } from './Parser.js';
|
|
7
4
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report(
|
|
5
|
+
ctx.err.report(localize('expected', localize('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
6
|
};
|
|
10
|
-
function long(options) {
|
|
7
|
+
export function long(options) {
|
|
11
8
|
return (src, ctx) => {
|
|
12
9
|
const ans = {
|
|
13
10
|
type: 'long',
|
|
14
|
-
range:
|
|
11
|
+
range: Range.create(src),
|
|
15
12
|
value: 0n,
|
|
16
13
|
};
|
|
17
14
|
if (src.peek() === '-' || src.peek() === '+') {
|
|
18
15
|
src.skip();
|
|
19
16
|
}
|
|
20
|
-
while (src.canRead() &&
|
|
17
|
+
while (src.canRead() && Source.isDigit(src.peek())) {
|
|
21
18
|
src.skip();
|
|
22
19
|
}
|
|
23
20
|
ans.range.end = src.cursor;
|
|
@@ -32,12 +29,12 @@ function long(options) {
|
|
|
32
29
|
}
|
|
33
30
|
if (!raw) {
|
|
34
31
|
if (options.failsOnEmpty) {
|
|
35
|
-
return
|
|
32
|
+
return Failure;
|
|
36
33
|
}
|
|
37
|
-
ctx.err.report(
|
|
34
|
+
ctx.err.report(localize('expected', localize('long')), ans);
|
|
38
35
|
}
|
|
39
36
|
else if (!options.pattern.test(raw) || isOnlySign) {
|
|
40
|
-
ctx.err.report(
|
|
37
|
+
ctx.err.report(localize('parser.long.illegal', options.pattern), ans);
|
|
41
38
|
}
|
|
42
39
|
else if ((options.min && ans.value < options.min) || (options.max && ans.value > options.max)) {
|
|
43
40
|
const onOutOfRange = options.onOutOfRange ?? fallbackOnOutOfRange;
|
|
@@ -46,5 +43,4 @@ function long(options) {
|
|
|
46
43
|
return ans;
|
|
47
44
|
};
|
|
48
45
|
}
|
|
49
|
-
exports.long = long;
|
|
50
46
|
//# sourceMappingURL=long.js.map
|
package/lib/parser/record.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AstNode } from '../node';
|
|
2
|
-
import type { RecordNode } from '../node/RecordNode';
|
|
3
|
-
import type { InfallibleParser, Parser } from './Parser';
|
|
1
|
+
import type { AstNode } from '../node/index.js';
|
|
2
|
+
import type { RecordNode } from '../node/RecordNode.js';
|
|
3
|
+
import type { InfallibleParser, Parser } from './Parser.js';
|
|
4
4
|
/** @internal For test only */
|
|
5
5
|
export interface Options<K extends AstNode, V extends AstNode> {
|
|
6
6
|
start: string;
|
package/lib/parser/record.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const source_1 = require("../source");
|
|
6
|
-
const Parser_1 = require("./Parser");
|
|
7
|
-
const util_1 = require("./util");
|
|
1
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Range } from '../source/index.js';
|
|
3
|
+
import { Failure } from './Parser.js';
|
|
4
|
+
import { attempt } from './util.js';
|
|
8
5
|
/**
|
|
9
6
|
* @returns A parser that parses something coming in a key-value pair form. e.g. SNBT objects, entity selector arguments.
|
|
10
7
|
*/
|
|
11
|
-
function record({ start, pair, end }) {
|
|
8
|
+
export function record({ start, pair, end }) {
|
|
12
9
|
return (src, ctx) => {
|
|
13
10
|
const ans = {
|
|
14
11
|
type: 'record',
|
|
15
|
-
range:
|
|
12
|
+
range: Range.create(src),
|
|
16
13
|
children: [],
|
|
17
14
|
};
|
|
18
15
|
if (src.trySkip(start)) {
|
|
@@ -25,13 +22,13 @@ function record({ start, pair, end }) {
|
|
|
25
22
|
let value;
|
|
26
23
|
// Pair end of the last pair.
|
|
27
24
|
if (requiresPairEnd && !hasPairEnd) {
|
|
28
|
-
ctx.err.report(
|
|
25
|
+
ctx.err.report(localize('expected', localeQuote(pair.end)), src);
|
|
29
26
|
}
|
|
30
27
|
// Key.
|
|
31
28
|
const keyStart = src.cursor;
|
|
32
|
-
const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd } =
|
|
33
|
-
if (keyResult ===
|
|
34
|
-
ctx.err.report(
|
|
29
|
+
const { result: keyResult, updateSrcAndCtx: updateForKey, endCursor: keyEnd } = attempt(pair.key, src, ctx);
|
|
30
|
+
if (keyResult === Failure || (keyEnd - keyStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
|
|
31
|
+
ctx.err.report(localize('expected', localize('parser.record.key')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
34
|
updateForKey();
|
|
@@ -41,18 +38,18 @@ function record({ start, pair, end }) {
|
|
|
41
38
|
let sepCharRange = undefined;
|
|
42
39
|
src.skipWhitespace();
|
|
43
40
|
if (src.peek(pair.sep.length) === pair.sep) {
|
|
44
|
-
sepCharRange =
|
|
41
|
+
sepCharRange = Range.create(src, () => src.skip(pair.sep.length));
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
ctx.err.report(
|
|
44
|
+
ctx.err.report(localize('expected', localeQuote(pair.sep)), src);
|
|
48
45
|
}
|
|
49
46
|
// Value.
|
|
50
47
|
src.skipWhitespace();
|
|
51
48
|
const valueParser = typeof pair.value === 'function' ? pair.value : pair.value.get(ans, key);
|
|
52
49
|
const valueStart = src.cursor;
|
|
53
|
-
const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd } =
|
|
54
|
-
if (valueResult ===
|
|
55
|
-
ctx.err.report(
|
|
50
|
+
const { result: valueResult, updateSrcAndCtx: updateForValue, endCursor: valueEnd } = attempt(valueParser, src, ctx);
|
|
51
|
+
if (valueResult === Failure || (valueEnd - valueStart === 0 && ![pair.sep, pair.end, end, '\r', '\n', '\t', ' '].includes(src.peek()))) {
|
|
52
|
+
ctx.err.report(localize('expected', localize('parser.record.value')), Range.create(src, () => src.skipUntilOrEnd(pair.sep, pair.end, end, '\r', '\n')));
|
|
56
53
|
}
|
|
57
54
|
else {
|
|
58
55
|
updateForValue();
|
|
@@ -63,12 +60,12 @@ function record({ start, pair, end }) {
|
|
|
63
60
|
src.skipWhitespace();
|
|
64
61
|
requiresPairEnd = true;
|
|
65
62
|
if (hasPairEnd = src.peek(pair.end.length) === pair.end) {
|
|
66
|
-
endCharRange =
|
|
63
|
+
endCharRange = Range.create(src, () => src.skip(pair.end.length));
|
|
67
64
|
}
|
|
68
65
|
// Create pair.
|
|
69
66
|
ans.children.push({
|
|
70
67
|
type: 'pair',
|
|
71
|
-
range:
|
|
68
|
+
range: Range.create(pairStart, src),
|
|
72
69
|
...(key || value) ? { children: [key, value].filter(v => !!v) } : {},
|
|
73
70
|
key,
|
|
74
71
|
sep: sepCharRange,
|
|
@@ -79,19 +76,18 @@ function record({ start, pair, end }) {
|
|
|
79
76
|
}
|
|
80
77
|
// Trailing pair end.
|
|
81
78
|
if (hasPairEnd && !pair.trailingEnd) {
|
|
82
|
-
ctx.err.report(
|
|
79
|
+
ctx.err.report(localize('parser.record.trailing-end'), ans.children[ans.children.length - 1].end);
|
|
83
80
|
}
|
|
84
81
|
// End.
|
|
85
82
|
if (!src.trySkip(end)) {
|
|
86
|
-
ctx.err.report(
|
|
83
|
+
ctx.err.report(localize('expected', localeQuote(end)), src);
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
else {
|
|
90
|
-
ctx.err.report(
|
|
87
|
+
ctx.err.report(localize('expected', localeQuote(start)), src);
|
|
91
88
|
}
|
|
92
89
|
ans.range.end = src.cursor;
|
|
93
90
|
return ans;
|
|
94
91
|
};
|
|
95
92
|
}
|
|
96
|
-
exports.record = record;
|
|
97
93
|
//# sourceMappingURL=record.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResourceLocationNode, ResourceLocationOptions } from '../node';
|
|
2
|
-
import type { InfallibleParser } from './Parser';
|
|
1
|
+
import type { ResourceLocationNode, ResourceLocationOptions } from '../node/index.js';
|
|
2
|
+
import type { InfallibleParser } from './Parser.js';
|
|
3
3
|
export declare function resourceLocation(options: ResourceLocationOptions): InfallibleParser<ResourceLocationNode>;
|
|
4
4
|
//# sourceMappingURL=resourceLocation.d.ts.map
|
|
@@ -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
|