@spyglassmc/core 0.1.1 → 0.1.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/TwoWayMap.d.ts +21 -0
- package/lib/common/TwoWayMap.js +75 -0
- package/lib/common/index.js +5 -1
- package/lib/common/util.d.ts +3 -20
- package/lib/common/util.js +6 -40
- package/lib/index.js +5 -1
- package/lib/node/LiteralNode.d.ts +1 -1
- package/lib/node/LiteralNode.js +1 -1
- package/lib/node/ResourceLocationNode.d.ts +2 -4
- package/lib/node/Sequence.d.ts +2 -1
- package/lib/node/Sequence.js +3 -2
- package/lib/node/SymbolNode.d.ts +1 -1
- package/lib/node/SymbolNode.js +1 -1
- package/lib/node/index.js +5 -1
- package/lib/parser/float.js +1 -1
- package/lib/parser/index.js +5 -1
- package/lib/parser/integer.js +1 -1
- package/lib/parser/long.js +1 -1
- package/lib/parser/string.js +4 -2
- package/lib/parser/util.d.ts +25 -7
- package/lib/parser/util.js +50 -17
- package/lib/processor/checker/builtin.js +1 -1
- package/lib/processor/checker/index.js +5 -1
- package/lib/processor/colorizer/index.js +5 -1
- package/lib/processor/completer/builtin.js +16 -16
- package/lib/processor/completer/index.js +5 -1
- package/lib/processor/formatter/index.js +5 -1
- package/lib/processor/index.js +5 -1
- package/lib/processor/linter/builtin/undeclaredSymbol.js +3 -3
- package/lib/processor/linter/builtin.js +1 -1
- package/lib/processor/linter/index.js +5 -1
- package/lib/service/Config.d.ts +6 -4
- package/lib/service/Config.js +6 -6
- package/lib/service/Context.d.ts +2 -2
- package/lib/service/Context.js +1 -0
- package/lib/service/Downloader.d.ts +1 -0
- package/lib/service/Downloader.js +4 -0
- package/lib/service/ErrorReporter.js +1 -1
- package/lib/service/FileService.d.ts +29 -4
- package/lib/service/FileService.js +82 -19
- package/lib/service/Project.d.ts +1 -0
- package/lib/service/Project.js +23 -11
- package/lib/service/Service.d.ts +2 -2
- package/lib/service/Service.js +25 -15
- package/lib/service/fileUtil.d.ts +15 -5
- package/lib/service/fileUtil.js +39 -4
- package/lib/service/index.js +5 -1
- package/lib/source/LanguageError.js +1 -1
- package/lib/source/Source.d.ts +6 -1
- package/lib/source/Source.js +30 -2
- package/lib/source/index.js +5 -1
- package/lib/symbol/Symbol.d.ts +10 -10
- package/lib/symbol/Symbol.js +7 -6
- package/lib/symbol/SymbolUtil.d.ts +1 -8
- package/lib/symbol/SymbolUtil.js +12 -12
- package/lib/symbol/index.js +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class TwoWayMap<K, V> implements Map<K, V> {
|
|
2
|
+
_map: Map<K, V>;
|
|
3
|
+
_reversedMap: Map<V, K>;
|
|
4
|
+
constructor(values?: [K, V][]);
|
|
5
|
+
get size(): number;
|
|
6
|
+
clear(): void;
|
|
7
|
+
delete(key: K): boolean;
|
|
8
|
+
deleteValue(value: V): boolean;
|
|
9
|
+
get(key: K): V | undefined;
|
|
10
|
+
getKey(value: V): K | undefined;
|
|
11
|
+
has(key: K): boolean;
|
|
12
|
+
hasValue(value: V): boolean;
|
|
13
|
+
set(key: K, value: V): this;
|
|
14
|
+
forEach(callbackfn: (value: V, key: K, map: TwoWayMap<K, V>) => void, thisArg?: any): void;
|
|
15
|
+
entries(): IterableIterator<[K, V]>;
|
|
16
|
+
keys(): IterableIterator<K>;
|
|
17
|
+
values(): IterableIterator<V>;
|
|
18
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
19
|
+
[Symbol.toStringTag]: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=TwoWayMap.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TwoWayMap = void 0;
|
|
5
|
+
class TwoWayMap {
|
|
6
|
+
constructor(values = []) {
|
|
7
|
+
this._map = new Map();
|
|
8
|
+
this._reversedMap = new Map();
|
|
9
|
+
this[_a] = 'TwoWayMap';
|
|
10
|
+
for (const [k, v] of values) {
|
|
11
|
+
this._map.set(k, v);
|
|
12
|
+
this._reversedMap.set(v, k);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
get size() {
|
|
16
|
+
return this._map.size;
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this._map.clear();
|
|
20
|
+
this._reversedMap.clear();
|
|
21
|
+
}
|
|
22
|
+
delete(key) {
|
|
23
|
+
const value = this._map.get(key);
|
|
24
|
+
const ans = this._map.delete(key);
|
|
25
|
+
if (value !== undefined) {
|
|
26
|
+
this._reversedMap.delete(value);
|
|
27
|
+
}
|
|
28
|
+
return ans;
|
|
29
|
+
}
|
|
30
|
+
deleteValue(value) {
|
|
31
|
+
const key = this._reversedMap.get(value);
|
|
32
|
+
const ans = this._reversedMap.delete(value);
|
|
33
|
+
if (key !== undefined) {
|
|
34
|
+
this._map.delete(key);
|
|
35
|
+
}
|
|
36
|
+
return ans;
|
|
37
|
+
}
|
|
38
|
+
get(key) {
|
|
39
|
+
return this._map.get(key);
|
|
40
|
+
}
|
|
41
|
+
getKey(value) {
|
|
42
|
+
return this._reversedMap.get(value);
|
|
43
|
+
}
|
|
44
|
+
has(key) {
|
|
45
|
+
return this._map.has(key);
|
|
46
|
+
}
|
|
47
|
+
hasValue(value) {
|
|
48
|
+
return this._reversedMap.has(value);
|
|
49
|
+
}
|
|
50
|
+
set(key, value) {
|
|
51
|
+
this._map.set(key, value);
|
|
52
|
+
this._reversedMap.set(value, key);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
forEach(callbackfn, thisArg) {
|
|
56
|
+
for (const [key, value] of this._map) {
|
|
57
|
+
callbackfn.apply(thisArg, [value, key, this]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
entries() {
|
|
61
|
+
return this._map.entries();
|
|
62
|
+
}
|
|
63
|
+
keys() {
|
|
64
|
+
return this._map.keys();
|
|
65
|
+
}
|
|
66
|
+
values() {
|
|
67
|
+
return this._map.values();
|
|
68
|
+
}
|
|
69
|
+
[Symbol.iterator]() {
|
|
70
|
+
return this._map.entries();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.TwoWayMap = TwoWayMap;
|
|
74
|
+
_a = Symbol.toStringTag;
|
|
75
|
+
//# sourceMappingURL=TwoWayMap.js.map
|
package/lib/common/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/common/util.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import externalBinarySearch from 'binary-search';
|
|
3
|
-
import type {
|
|
4
|
-
import type { ProcessorContext, RootUriString } from '../service';
|
|
3
|
+
import type { ProcessorContext } from '../service';
|
|
5
4
|
export { URL as Uri } from 'url';
|
|
6
5
|
/**
|
|
7
6
|
* @param getCacheKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
@@ -13,9 +12,9 @@ export { URL as Uri } from 'url';
|
|
|
13
12
|
*/
|
|
14
13
|
export declare function CachePromise(getCacheKey?: (args: any[]) => any): MethodDecorator;
|
|
15
14
|
/**
|
|
16
|
-
* This is a decorator for
|
|
15
|
+
* This is a decorator for methods. Decorated methods will return the same non-`undefined` value no matter what.
|
|
17
16
|
*/
|
|
18
|
-
export declare const
|
|
17
|
+
export declare const Singleton: MethodDecorator;
|
|
19
18
|
/**
|
|
20
19
|
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
21
20
|
* The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
|
|
@@ -24,22 +23,6 @@ export declare const SingletonPromise: MethodDecorator;
|
|
|
24
23
|
* Decorated methods will be scheduled to run after `ms` milliseconds. The timer will reset when the method is called again.
|
|
25
24
|
*/
|
|
26
25
|
export declare function Delay(ms: number, getKey?: (args: any[]) => any): MethodDecorator;
|
|
27
|
-
export declare namespace SpyglassUri {
|
|
28
|
-
const Protocol = "spyglassmc:";
|
|
29
|
-
namespace Archive {
|
|
30
|
-
const Hostname = "archive";
|
|
31
|
-
function get(archiveUri: string): RootUriString;
|
|
32
|
-
function get(archiveUri: string, pathInArchive: string): string;
|
|
33
|
-
function is(uri: Uri): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* @throws When `uri` has the wrong protocol or hostname.
|
|
36
|
-
*/
|
|
37
|
-
function decode(uri: Uri): {
|
|
38
|
-
archiveUri: string;
|
|
39
|
-
pathInArchive: string;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
26
|
export declare type FullResourceLocation = `${string}:${string}`;
|
|
44
27
|
export interface ResourceLocation {
|
|
45
28
|
isTag: boolean;
|
package/lib/common/util.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isIterable = exports.binarySearch = exports.getStates = exports.Lazy = exports.merge = exports.isObject = exports.parseGzippedJson = exports.zip = exports.unzip = exports.promisifyAsyncIterable = exports.TypePredicates = exports.Arrayable = exports.isEnoent = exports.isErrorCode = exports.getSha1 = exports.base64ToString = exports.stringToBase64 = exports.bufferToString = exports.ResourceLocation = exports.
|
|
6
|
+
exports.isIterable = exports.binarySearch = exports.getStates = exports.Lazy = exports.merge = exports.isObject = exports.parseGzippedJson = exports.zip = exports.unzip = exports.promisifyAsyncIterable = exports.TypePredicates = exports.Arrayable = exports.isEnoent = exports.isErrorCode = exports.getSha1 = exports.base64ToString = exports.stringToBase64 = exports.bufferToString = exports.ResourceLocation = exports.Delay = exports.Singleton = exports.CachePromise = exports.Uri = void 0;
|
|
7
7
|
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const rfdc_1 = __importDefault(require("rfdc"));
|
|
@@ -39,18 +39,18 @@ function CachePromise(getCacheKey = args => args[0]) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.CachePromise = CachePromise;
|
|
41
41
|
/**
|
|
42
|
-
* This is a decorator for
|
|
42
|
+
* This is a decorator for methods. Decorated methods will return the same non-`undefined` value no matter what.
|
|
43
43
|
*/
|
|
44
|
-
const
|
|
45
|
-
let
|
|
44
|
+
const Singleton = (_target, _key, descripter) => {
|
|
45
|
+
let value;
|
|
46
46
|
const decoratedMethod = descripter.value;
|
|
47
47
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
|
48
48
|
descripter.value = function (...args) {
|
|
49
|
-
return
|
|
49
|
+
return value ?? (value = decoratedMethod.apply(this, args));
|
|
50
50
|
};
|
|
51
51
|
return descripter;
|
|
52
52
|
};
|
|
53
|
-
exports.
|
|
53
|
+
exports.Singleton = Singleton;
|
|
54
54
|
/**
|
|
55
55
|
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
56
56
|
* The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
|
|
@@ -77,40 +77,6 @@ function Delay(ms, getKey = args => args[0]) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
exports.Delay = Delay;
|
|
80
|
-
var SpyglassUri;
|
|
81
|
-
(function (SpyglassUri) {
|
|
82
|
-
SpyglassUri.Protocol = 'spyglassmc:';
|
|
83
|
-
let Archive;
|
|
84
|
-
(function (Archive) {
|
|
85
|
-
Archive.Hostname = 'archive';
|
|
86
|
-
function get(archiveUri, pathInArchive = '') {
|
|
87
|
-
return `${SpyglassUri.Protocol}//${Archive.Hostname}/${encodeURIComponent(archiveUri)}/${pathInArchive.replace(/\\/g, '/')}`;
|
|
88
|
-
}
|
|
89
|
-
Archive.get = get;
|
|
90
|
-
function is(uri) {
|
|
91
|
-
return uri.protocol === SpyglassUri.Protocol && uri.hostname === Archive.Hostname;
|
|
92
|
-
}
|
|
93
|
-
Archive.is = is;
|
|
94
|
-
/**
|
|
95
|
-
* @throws When `uri` has the wrong protocol or hostname.
|
|
96
|
-
*/
|
|
97
|
-
function decode(uri) {
|
|
98
|
-
if (uri.protocol !== SpyglassUri.Protocol) {
|
|
99
|
-
throw new Error(`Expected protocol “${SpyglassUri.Protocol}” in “${uri.toString()}”`);
|
|
100
|
-
}
|
|
101
|
-
if (uri.hostname !== Archive.Hostname) {
|
|
102
|
-
throw new Error(`Expected hostname “${Archive.Hostname}” in “${uri.toString()}”`);
|
|
103
|
-
}
|
|
104
|
-
// Ex. `pathname`: `/QzpcYS50YXIuZ3o=/foo/bar.json`
|
|
105
|
-
const paths = uri.pathname.split('/');
|
|
106
|
-
return {
|
|
107
|
-
archiveUri: decodeURIComponent(paths[1]),
|
|
108
|
-
pathInArchive: paths.slice(2).join('/'),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
Archive.decode = decode;
|
|
112
|
-
})(Archive = SpyglassUri.Archive || (SpyglassUri.Archive = {}));
|
|
113
|
-
})(SpyglassUri = exports.SpyglassUri || (exports.SpyglassUri = {}));
|
|
114
80
|
var ResourceLocation;
|
|
115
81
|
(function (ResourceLocation) {
|
|
116
82
|
/**
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,7 +13,7 @@ export interface LiteralNode extends LiteralBaseNode {
|
|
|
13
13
|
readonly type: 'literal';
|
|
14
14
|
}
|
|
15
15
|
export declare namespace LiteralNode {
|
|
16
|
-
function is(obj: object): obj is LiteralNode;
|
|
16
|
+
function is(obj: object | undefined): obj is LiteralNode;
|
|
17
17
|
function mock(range: RangeLike, options: LiteralOptions): LiteralNode;
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=LiteralNode.d.ts.map
|
package/lib/node/LiteralNode.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FullResourceLocation } from '../common';
|
|
2
|
+
import { ResourceLocation } from '../common';
|
|
2
3
|
import type { RangeLike } from '../source';
|
|
3
4
|
import type { ResourceLocationCategory, SymbolAccessType, SymbolUsageType, TaggableResourceLocationCategory } from '../symbol';
|
|
4
5
|
import type { AstNode } from './AstNode';
|
|
@@ -23,11 +24,8 @@ export declare type ResourceLocationOptions = {
|
|
|
23
24
|
allowTag?: false;
|
|
24
25
|
allowUnknown?: boolean;
|
|
25
26
|
});
|
|
26
|
-
export interface ResourceLocationBaseNode extends AstNode {
|
|
27
|
+
export interface ResourceLocationBaseNode extends AstNode, Partial<ResourceLocation> {
|
|
27
28
|
readonly options: ResourceLocationOptions;
|
|
28
|
-
readonly isTag?: boolean;
|
|
29
|
-
readonly namespace?: string;
|
|
30
|
-
readonly path?: string[];
|
|
31
29
|
}
|
|
32
30
|
export interface ResourceLocationNode extends ResourceLocationBaseNode {
|
|
33
31
|
readonly type: 'resource_location';
|
package/lib/node/Sequence.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ export interface SequenceNode<CN extends AstNode = AstNode> extends AstNode {
|
|
|
6
6
|
*/
|
|
7
7
|
children: CN[];
|
|
8
8
|
}
|
|
9
|
+
export declare const SequenceUtilDiscriminator: unique symbol;
|
|
9
10
|
/**
|
|
10
11
|
* A utility object for temporarily storing a sequence rule.
|
|
11
12
|
*
|
|
12
13
|
* @template CN Child node.
|
|
13
14
|
*/
|
|
14
15
|
export interface SequenceUtil<CN extends AstNode = AstNode> {
|
|
15
|
-
|
|
16
|
+
[SequenceUtilDiscriminator]: true;
|
|
16
17
|
range: Range;
|
|
17
18
|
children: CN[];
|
|
18
19
|
}
|
package/lib/node/Sequence.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SequenceUtil = void 0;
|
|
3
|
+
exports.SequenceUtil = exports.SequenceUtilDiscriminator = void 0;
|
|
4
|
+
exports.SequenceUtilDiscriminator = Symbol('SequenceUtilDiscriminator');
|
|
4
5
|
var SequenceUtil;
|
|
5
6
|
(function (SequenceUtil) {
|
|
6
7
|
function is(obj) {
|
|
7
|
-
return !!obj && obj.
|
|
8
|
+
return !!obj && obj[exports.SequenceUtilDiscriminator];
|
|
8
9
|
}
|
|
9
10
|
SequenceUtil.is = is;
|
|
10
11
|
})(SequenceUtil = exports.SequenceUtil || (exports.SequenceUtil = {}));
|
package/lib/node/SymbolNode.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface SymbolNode extends SymbolBaseNode {
|
|
|
15
15
|
readonly type: 'symbol';
|
|
16
16
|
}
|
|
17
17
|
export declare namespace SymbolNode {
|
|
18
|
-
function is(obj:
|
|
18
|
+
function is(obj: AstNode | undefined): obj is SymbolNode;
|
|
19
19
|
function mock(range: RangeLike, options: SymbolOptions): SymbolNode;
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=SymbolNode.d.ts.map
|
package/lib/node/SymbolNode.js
CHANGED
package/lib/node/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parser/float.js
CHANGED
|
@@ -5,7 +5,7 @@ const locales_1 = require("@spyglassmc/locales");
|
|
|
5
5
|
const source_1 = require("../source");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
7
7
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* Error */);
|
|
8
|
+
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
9
|
};
|
|
10
10
|
function float(options) {
|
|
11
11
|
return (src, ctx) => {
|
package/lib/parser/index.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
/* istanbul ignore file */
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
package/lib/parser/integer.js
CHANGED
|
@@ -5,7 +5,7 @@ const locales_1 = require("@spyglassmc/locales");
|
|
|
5
5
|
const source_1 = require("../source");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
7
7
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* Error */);
|
|
8
|
+
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
9
|
};
|
|
10
10
|
function integer(options) {
|
|
11
11
|
return (src, ctx) => {
|
package/lib/parser/long.js
CHANGED
|
@@ -5,7 +5,7 @@ const locales_1 = require("@spyglassmc/locales");
|
|
|
5
5
|
const source_1 = require("../source");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
7
7
|
const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
|
|
8
|
-
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* Error */);
|
|
8
|
+
ctx.err.report((0, locales_1.localize)('expected', (0, locales_1.localize)('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
|
|
9
9
|
};
|
|
10
10
|
function long(options) {
|
|
11
11
|
return (src, ctx) => {
|
package/lib/parser/string.js
CHANGED
|
@@ -20,9 +20,10 @@ function string(options) {
|
|
|
20
20
|
const currentQuote = src.read();
|
|
21
21
|
const contentStart = src.cursor;
|
|
22
22
|
while (src.canRead() && src.peek() !== currentQuote) {
|
|
23
|
-
const
|
|
24
|
-
const c = src.read();
|
|
23
|
+
const c = src.peek();
|
|
25
24
|
if (options.escapable && c === '\\') {
|
|
25
|
+
const cStart = src.cursor;
|
|
26
|
+
src.skip();
|
|
26
27
|
const c2 = src.read();
|
|
27
28
|
if (c2 === '\\' || c2 === currentQuote || node_1.EscapeChar.is(options.escapable.characters, c2)) {
|
|
28
29
|
ans.valueMap.push({
|
|
@@ -62,6 +63,7 @@ function string(options) {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
else {
|
|
66
|
+
src.skip();
|
|
65
67
|
ans.value += c;
|
|
66
68
|
}
|
|
67
69
|
}
|
package/lib/parser/util.d.ts
CHANGED
|
@@ -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
|
package/lib/parser/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.acceptOnly = exports.stopBefore = exports.validate = exports.setType = exports.map = exports.select = exports.recover = exports.optional = exports.failOnEmpty = exports.any = exports.repeat = exports.sequence = exports.attempt = void 0;
|
|
3
|
+
exports.acceptIf = exports.acceptOnly = exports.stopBefore = exports.validate = exports.setType = exports.map = exports.select = exports.recover = exports.optional = exports.failOnError = exports.failOnEmpty = exports.any = exports.repeat = exports.sequence = exports.attempt = void 0;
|
|
4
4
|
const node_1 = require("../node");
|
|
5
5
|
const service_1 = require("../service");
|
|
6
6
|
const source_1 = require("../source");
|
|
@@ -28,7 +28,7 @@ exports.attempt = attempt;
|
|
|
28
28
|
function sequence(parsers, parseGap) {
|
|
29
29
|
return (src, ctx) => {
|
|
30
30
|
const ans = {
|
|
31
|
-
|
|
31
|
+
[node_1.SequenceUtilDiscriminator]: true,
|
|
32
32
|
children: [],
|
|
33
33
|
range: source_1.Range.create(src),
|
|
34
34
|
};
|
|
@@ -62,7 +62,7 @@ exports.sequence = sequence;
|
|
|
62
62
|
function repeat(parser, parseGap) {
|
|
63
63
|
return (src, ctx) => {
|
|
64
64
|
const ans = {
|
|
65
|
-
|
|
65
|
+
[node_1.SequenceUtilDiscriminator]: true,
|
|
66
66
|
children: [],
|
|
67
67
|
range: source_1.Range.create(src),
|
|
68
68
|
};
|
|
@@ -122,12 +122,23 @@ function failOnEmpty(parser) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
exports.failOnEmpty = failOnEmpty;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// ])
|
|
125
|
+
/**
|
|
126
|
+
* @returns A parser that fails when the passed-in parser produced any errors.
|
|
127
|
+
*/
|
|
128
|
+
function failOnError(parser) {
|
|
130
129
|
return (src, ctx) => {
|
|
130
|
+
const start = src.cursor;
|
|
131
|
+
const { errorAmount, updateSrcAndCtx, result } = attempt(parser, src, ctx);
|
|
132
|
+
if (!errorAmount) {
|
|
133
|
+
updateSrcAndCtx();
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
return Parser_1.Failure;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
exports.failOnError = failOnError;
|
|
140
|
+
function optional(parser) {
|
|
141
|
+
return ((src, ctx) => {
|
|
131
142
|
const { result, updateSrcAndCtx } = attempt(parser, src, ctx);
|
|
132
143
|
if (result === Parser_1.Failure) {
|
|
133
144
|
return undefined;
|
|
@@ -136,7 +147,7 @@ function optional(parser) {
|
|
|
136
147
|
updateSrcAndCtx();
|
|
137
148
|
return result;
|
|
138
149
|
}
|
|
139
|
-
};
|
|
150
|
+
});
|
|
140
151
|
}
|
|
141
152
|
exports.optional = optional;
|
|
142
153
|
function recover(parser, defaultValue) {
|
|
@@ -152,12 +163,13 @@ function recover(parser, defaultValue) {
|
|
|
152
163
|
exports.recover = recover;
|
|
153
164
|
function select(cases) {
|
|
154
165
|
return (src, ctx) => {
|
|
155
|
-
for (const { predicate, parser } of cases) {
|
|
156
|
-
if (predicate?.(src) ?? true) {
|
|
157
|
-
|
|
166
|
+
for (const { predicate, prefix, parser } of cases) {
|
|
167
|
+
if (predicate?.(src) ?? (prefix !== undefined ? src.tryPeek(prefix) : undefined) ?? true) {
|
|
168
|
+
const callableParser = typeof parser === 'object' ? parser.get() : parser;
|
|
169
|
+
return callableParser(src, ctx);
|
|
158
170
|
}
|
|
159
171
|
}
|
|
160
|
-
|
|
172
|
+
throw new Error('The select parser util was called with non-exhaustive cases');
|
|
161
173
|
};
|
|
162
174
|
}
|
|
163
175
|
exports.select = select;
|
|
@@ -173,10 +185,15 @@ function map(parser, fn) {
|
|
|
173
185
|
}
|
|
174
186
|
exports.map = map;
|
|
175
187
|
function setType(type, parser) {
|
|
176
|
-
return map(parser, res =>
|
|
177
|
-
...res
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
return map(parser, res => {
|
|
189
|
+
const { type: _type, ...restResult } = res;
|
|
190
|
+
const ans = {
|
|
191
|
+
type,
|
|
192
|
+
...restResult,
|
|
193
|
+
};
|
|
194
|
+
delete ans[node_1.SequenceUtilDiscriminator];
|
|
195
|
+
return ans;
|
|
196
|
+
});
|
|
180
197
|
}
|
|
181
198
|
exports.setType = setType;
|
|
182
199
|
function validate(parser, validator, message, severity) {
|
|
@@ -221,4 +238,20 @@ function acceptOnly(parser, ...characters) {
|
|
|
221
238
|
};
|
|
222
239
|
}
|
|
223
240
|
exports.acceptOnly = acceptOnly;
|
|
241
|
+
function acceptIf(parser, predicate) {
|
|
242
|
+
return ((src, ctx) => {
|
|
243
|
+
const tmpSrc = src.clone();
|
|
244
|
+
// Cut tmpSrc.string before the nearest unacceptable character.
|
|
245
|
+
for (let i = tmpSrc.innerCursor; i < tmpSrc.string.length; i++) {
|
|
246
|
+
if (!predicate(tmpSrc.string.charAt(i))) {
|
|
247
|
+
tmpSrc.string = tmpSrc.string.slice(0, i);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const ans = parser(tmpSrc, ctx);
|
|
252
|
+
src.innerCursor = tmpSrc.innerCursor;
|
|
253
|
+
return ans;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
exports.acceptIf = acceptIf;
|
|
224
257
|
//# sourceMappingURL=util.js.map
|
|
@@ -74,7 +74,7 @@ const resourceLocation = (node, ctx) => {
|
|
|
74
74
|
const full = node_1.ResourceLocationNode.toString(node, 'full');
|
|
75
75
|
if (node.options.pool) {
|
|
76
76
|
if (!node.options.pool.includes(full)) {
|
|
77
|
-
ctx.err.report((0, lib_1.localize)('expected', node.options.pool), node, 3 /* Error */);
|
|
77
|
+
ctx.err.report((0, lib_1.localize)('expected', node.options.pool), node, 3 /* ErrorSeverity.Error */);
|
|
78
78
|
}
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|