@spyglassmc/mcfunction 0.1.2 → 0.2.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/lib/colorizer/index.js +2 -29
- package/lib/completer/index.d.ts +3 -3
- package/lib/completer/index.js +9 -37
- package/lib/index.d.ts +5 -5
- package/lib/index.js +8 -38
- package/lib/node/command.js +7 -33
- package/lib/node/entry.d.ts +1 -1
- package/lib/node/entry.js +2 -5
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +2 -18
- package/lib/parser/argument.d.ts +1 -1
- package/lib/parser/argument.js +1 -5
- package/lib/parser/command.d.ts +3 -3
- package/lib/parser/command.js +20 -50
- package/lib/parser/common.js +4 -31
- package/lib/parser/entry.d.ts +2 -2
- package/lib/parser/entry.js +5 -32
- package/lib/parser/index.d.ts +5 -5
- package/lib/parser/index.js +5 -21
- package/lib/parser/literal.d.ts +1 -1
- package/lib/parser/literal.js +4 -31
- package/lib/tree/index.d.ts +3 -3
- package/lib/tree/index.js +3 -19
- package/lib/tree/registry.d.ts +1 -1
- package/lib/tree/registry.js +11 -29
- package/lib/tree/type.js +1 -2
- package/lib/tree/util.d.ts +1 -1
- package/lib/tree/util.js +3 -9
- package/package.json +4 -3
package/lib/colorizer/index.js
CHANGED
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.register = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
function register(meta) {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
export function register(meta) {
|
|
29
3
|
meta.registerColorizer('mcfunction:command_child/literal', core.colorizer.literal);
|
|
30
4
|
meta.registerColorizer('mcfunction:command_child/trailing', core.colorizer.error);
|
|
31
5
|
}
|
|
32
|
-
exports.register = register;
|
|
33
6
|
//# sourceMappingURL=index.js.map
|
package/lib/completer/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { McfunctionNode } from '../node';
|
|
3
|
-
import { CommandNode } from '../node';
|
|
4
|
-
import type { ArgumentTreeNode, RootTreeNode } from '../tree';
|
|
2
|
+
import type { McfunctionNode } from '../node/index.js';
|
|
3
|
+
import { CommandNode } from '../node/index.js';
|
|
4
|
+
import type { ArgumentTreeNode, RootTreeNode } from '../tree/index.js';
|
|
5
5
|
export declare type MockNodesGetter = (treeNode: ArgumentTreeNode, range: core.RangeLike) => core.Arrayable<core.AstNode>;
|
|
6
6
|
/**
|
|
7
7
|
* @param getMockNodes A function that returns a mock AST Node from given {@link ArgumentTreeNode}. These mock nodes
|
package/lib/completer/index.js
CHANGED
|
@@ -1,50 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.command = exports.entry = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const node_1 = require("../node");
|
|
29
|
-
const tree_1 = require("../tree");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { CommandNode } from '../node/index.js';
|
|
3
|
+
import { categorizeTreeChildren, CommandTreeRegistry, redirect, resolveParentTreeNode } from '../tree/index.js';
|
|
30
4
|
/**
|
|
31
5
|
* @param getMockNodes A function that returns a mock AST Node from given {@link ArgumentTreeNode}. These mock nodes
|
|
32
6
|
* will be used for completing the argument.
|
|
33
7
|
*/
|
|
34
|
-
function entry(commandTreeName, getMockNodes) {
|
|
8
|
+
export function entry(commandTreeName, getMockNodes) {
|
|
35
9
|
return (node, ctx) => {
|
|
36
|
-
const tree =
|
|
10
|
+
const tree = CommandTreeRegistry.instance.get(commandTreeName);
|
|
37
11
|
const childNode = core.AstNode.findChild(node, ctx.offset, true);
|
|
38
12
|
if (core.CommentNode.is(childNode)) {
|
|
39
13
|
return [];
|
|
40
14
|
}
|
|
41
15
|
else {
|
|
42
|
-
return command(tree, getMockNodes)(childNode ??
|
|
16
|
+
return command(tree, getMockNodes)(childNode ?? CommandNode.mock(ctx.offset), ctx);
|
|
43
17
|
}
|
|
44
18
|
};
|
|
45
19
|
}
|
|
46
|
-
|
|
47
|
-
function command(tree, getMockNodes) {
|
|
20
|
+
export function command(tree, getMockNodes) {
|
|
48
21
|
return (node, ctx) => {
|
|
49
22
|
const index = core.AstNode.findChildIndex(node, ctx.offset, true);
|
|
50
23
|
const selectedChildNode = node.children[index]?.children[0];
|
|
@@ -58,11 +31,11 @@ function command(tree, getMockNodes) {
|
|
|
58
31
|
.map(v => core.CompletionItem.create(v, ctx.offset, { kind: 14 /* core.CompletionKind.Keyword */ }));
|
|
59
32
|
}
|
|
60
33
|
const treePath = lastChildNode.path;
|
|
61
|
-
const { treeNode: parentTreeNode } =
|
|
34
|
+
const { treeNode: parentTreeNode } = resolveParentTreeNode(redirect(tree, treePath), tree);
|
|
62
35
|
if (!parentTreeNode?.children) {
|
|
63
36
|
return [];
|
|
64
37
|
}
|
|
65
|
-
const { literalTreeNodes, argumentTreeNodes } =
|
|
38
|
+
const { literalTreeNodes, argumentTreeNodes } = categorizeTreeChildren(parentTreeNode.children);
|
|
66
39
|
return [
|
|
67
40
|
...literalTreeNodes.map(([name]) => core.CompletionItem.create(name, ctx.offset, { kind: 14 /* core.CompletionKind.Keyword */ })),
|
|
68
41
|
...argumentTreeNodes.flatMap(([_name, treeNode]) => core.Arrayable.toArray(getMockNodes(treeNode, ctx.offset))
|
|
@@ -70,5 +43,4 @@ function command(tree, getMockNodes) {
|
|
|
70
43
|
];
|
|
71
44
|
};
|
|
72
45
|
}
|
|
73
|
-
exports.command = command;
|
|
74
46
|
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
export * as colorizer from './colorizer';
|
|
3
|
-
export * as completer from './completer';
|
|
4
|
-
export * from './node';
|
|
5
|
-
export * from './parser';
|
|
6
|
-
export * from './tree';
|
|
2
|
+
export * as colorizer from './colorizer/index.js';
|
|
3
|
+
export * as completer from './completer/index.js';
|
|
4
|
+
export * from './node/index.js';
|
|
5
|
+
export * from './parser/index.js';
|
|
6
|
+
export * from './tree/index.js';
|
|
7
7
|
export declare const initialize: core.ProjectInitializer;
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,43 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.initialize = exports.completer = exports.colorizer = void 0;
|
|
30
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
31
|
-
const colorizer = __importStar(require("./colorizer"));
|
|
32
|
-
exports.colorizer = __importStar(require("./colorizer"));
|
|
33
|
-
exports.completer = __importStar(require("./completer"));
|
|
34
|
-
__exportStar(require("./node"), exports);
|
|
35
|
-
__exportStar(require("./parser"), exports);
|
|
36
|
-
__exportStar(require("./tree"), exports);
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import * as colorizer from './colorizer/index.js';
|
|
3
|
+
export * as colorizer from './colorizer/index.js';
|
|
4
|
+
export * as completer from './completer/index.js';
|
|
5
|
+
export * from './node/index.js';
|
|
6
|
+
export * from './parser/index.js';
|
|
7
|
+
export * from './tree/index.js';
|
|
37
8
|
/* istanbul ignore next */
|
|
38
|
-
const initialize = ({ meta }) => {
|
|
9
|
+
export const initialize = ({ meta }) => {
|
|
39
10
|
colorizer.register(meta);
|
|
40
11
|
meta.registerCompleter('mcfunction:command_child/literal', core.completer.literal);
|
|
41
12
|
};
|
|
42
|
-
exports.initialize = initialize;
|
|
43
13
|
//# sourceMappingURL=index.js.map
|
package/lib/node/command.js
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.LiteralCommandChildNode = exports.CommandChildNode = exports.CommandNode = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
var CommandNode;
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
export var CommandNode;
|
|
29
3
|
(function (CommandNode) {
|
|
30
4
|
/* istanbul ignore next */
|
|
31
5
|
function is(node) {
|
|
@@ -40,19 +14,19 @@ var CommandNode;
|
|
|
40
14
|
};
|
|
41
15
|
}
|
|
42
16
|
CommandNode.mock = mock;
|
|
43
|
-
})(CommandNode
|
|
44
|
-
var CommandChildNode;
|
|
17
|
+
})(CommandNode || (CommandNode = {}));
|
|
18
|
+
export var CommandChildNode;
|
|
45
19
|
(function (CommandChildNode) {
|
|
46
20
|
function is(node) {
|
|
47
21
|
return node.type === 'mcfunction:command_child';
|
|
48
22
|
}
|
|
49
23
|
CommandChildNode.is = is;
|
|
50
|
-
})(CommandChildNode
|
|
51
|
-
var LiteralCommandChildNode;
|
|
24
|
+
})(CommandChildNode || (CommandChildNode = {}));
|
|
25
|
+
export var LiteralCommandChildNode;
|
|
52
26
|
(function (LiteralCommandChildNode) {
|
|
53
27
|
function is(node) {
|
|
54
28
|
return node?.type === 'mcfunction:command_child/literal';
|
|
55
29
|
}
|
|
56
30
|
LiteralCommandChildNode.is = is;
|
|
57
|
-
})(LiteralCommandChildNode
|
|
31
|
+
})(LiteralCommandChildNode || (LiteralCommandChildNode = {}));
|
|
58
32
|
//# sourceMappingURL=command.js.map
|
package/lib/node/entry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as core from '@spyglassmc/core';
|
|
2
|
-
import type { CommandNode } from './command';
|
|
2
|
+
import type { CommandNode } from './command.js';
|
|
3
3
|
export interface McfunctionNode extends core.SequenceNode<CommandNode | core.CommentNode> {
|
|
4
4
|
type: 'mcfunction:entry';
|
|
5
5
|
}
|
package/lib/node/entry.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.McfunctionNode = void 0;
|
|
4
|
-
var McfunctionNode;
|
|
1
|
+
export var McfunctionNode;
|
|
5
2
|
(function (McfunctionNode) {
|
|
6
3
|
/* istanbul ignore next */
|
|
7
4
|
function is(node) {
|
|
8
5
|
return node?.type === 'mcfunction:entry';
|
|
9
6
|
}
|
|
10
7
|
McfunctionNode.is = is;
|
|
11
|
-
})(McfunctionNode
|
|
8
|
+
})(McfunctionNode || (McfunctionNode = {}));
|
|
12
9
|
//# sourceMappingURL=entry.js.map
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './command';
|
|
2
|
-
export * from './entry';
|
|
1
|
+
export * from './command.js';
|
|
2
|
+
export * from './entry.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/node/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./command"), exports);
|
|
18
|
-
__exportStar(require("./entry"), exports);
|
|
1
|
+
export * from './command.js';
|
|
2
|
+
export * from './entry.js';
|
|
19
3
|
//# sourceMappingURL=index.js.map
|
package/lib/parser/argument.d.ts
CHANGED
package/lib/parser/argument.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.argumentTreeNodeToString = void 0;
|
|
4
|
-
function argumentTreeNodeToString(name, treeNode) {
|
|
1
|
+
export function argumentTreeNodeToString(name, treeNode) {
|
|
5
2
|
const parserName = treeNode.parser.slice(treeNode.parser.indexOf(':') + 1);
|
|
6
3
|
return `<${name}: ${parserName}>`;
|
|
7
4
|
}
|
|
8
|
-
exports.argumentTreeNodeToString = argumentTreeNodeToString;
|
|
9
5
|
//# sourceMappingURL=argument.js.map
|
package/lib/parser/command.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { CommandNode } from '../node';
|
|
3
|
-
import type { RootTreeNode, TreeNode } from '../tree/type';
|
|
4
|
-
import type { ArgumentParserGetter } from './argument';
|
|
2
|
+
import type { CommandNode } from '../node/index.js';
|
|
3
|
+
import type { RootTreeNode, TreeNode } from '../tree/type.js';
|
|
4
|
+
import type { ArgumentParserGetter } from './argument.js';
|
|
5
5
|
/**
|
|
6
6
|
* @returns A parser that always takes a whole line (excluding line turn characters) and tries to parse it as a command.
|
|
7
7
|
*/
|
package/lib/parser/command.js
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.treeNodeToString = exports.treeNodeChildrenToString = exports.treeNodeChildrenToStringArray = exports.command = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
29
|
-
const tree_1 = require("../tree");
|
|
30
|
-
const argument_1 = require("./argument");
|
|
31
|
-
const common_1 = require("./common");
|
|
32
|
-
const literal_1 = require("./literal");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
import { categorizeTreeChildren, resolveParentTreeNode } from '../tree/index.js';
|
|
4
|
+
import { argumentTreeNodeToString } from './argument.js';
|
|
5
|
+
import { sep } from './common.js';
|
|
6
|
+
import { literal } from './literal.js';
|
|
33
7
|
/**
|
|
34
8
|
* @returns A parser that always takes a whole line (excluding line turn characters) and tries to parse it as a command.
|
|
35
9
|
*/
|
|
36
|
-
function command(tree, argument) {
|
|
10
|
+
export function command(tree, argument) {
|
|
37
11
|
return (src, ctx) => {
|
|
38
12
|
const ans = {
|
|
39
13
|
type: 'mcfunction:command',
|
|
@@ -59,7 +33,6 @@ function command(tree, argument) {
|
|
|
59
33
|
return ans;
|
|
60
34
|
};
|
|
61
35
|
}
|
|
62
|
-
exports.command = command;
|
|
63
36
|
/**
|
|
64
37
|
* Dispatch and parse based on the specified command tree node's children.
|
|
65
38
|
*
|
|
@@ -68,19 +41,19 @@ exports.command = command;
|
|
|
68
41
|
function dispatch(ans, src, ctx, path, rootTreeNode, parentTreeNode, argument) {
|
|
69
42
|
// Convention: suffix `Node` is for AST nodes; `TreeNode` is for command tree nodes.
|
|
70
43
|
function _dispatch(path, parentTreeNode) {
|
|
71
|
-
const { treeNode: parent, path: resolvedPath } =
|
|
44
|
+
const { treeNode: parent, path: resolvedPath } = resolveParentTreeNode(parentTreeNode, rootTreeNode, path);
|
|
72
45
|
path = resolvedPath;
|
|
73
46
|
const children = parent?.children;
|
|
74
47
|
if (!children) {
|
|
75
48
|
return false;
|
|
76
49
|
}
|
|
77
|
-
const { literalTreeNodes, argumentTreeNodes } =
|
|
50
|
+
const { literalTreeNodes, argumentTreeNodes } = categorizeTreeChildren(children);
|
|
78
51
|
const argumentParsers = argumentTreeNodes.map(([name, treeNode]) => ({
|
|
79
52
|
name,
|
|
80
53
|
parser: argument(treeNode) ?? unknown(treeNode),
|
|
81
54
|
}));
|
|
82
55
|
const literalParser = literalTreeNodes.length
|
|
83
|
-
?
|
|
56
|
+
? literal(literalTreeNodes.map(([name, _treeNode]) => name), parent.type === 'root')
|
|
84
57
|
: undefined;
|
|
85
58
|
const parsers = [
|
|
86
59
|
...literalParser ? [literalParser] : [],
|
|
@@ -104,7 +77,7 @@ function dispatch(ans, src, ctx, path, rootTreeNode, parentTreeNode, argument) {
|
|
|
104
77
|
}
|
|
105
78
|
const requiredPermissionLevel = childTreeNode.permission ?? 2;
|
|
106
79
|
if (ctx.config.env.permissionLevel < requiredPermissionLevel) {
|
|
107
|
-
ctx.err.report(
|
|
80
|
+
ctx.err.report(localize('mcfunction.parser.no-permission', requiredPermissionLevel, ctx.config.env.permissionLevel), result);
|
|
108
81
|
}
|
|
109
82
|
if (result.type === 'mcfunction:command_child/unknown') {
|
|
110
83
|
// Encountered an unsupported parser. Stop parsing this command.
|
|
@@ -112,19 +85,19 @@ function dispatch(ans, src, ctx, path, rootTreeNode, parentTreeNode, argument) {
|
|
|
112
85
|
}
|
|
113
86
|
if (src.canReadInLine()) {
|
|
114
87
|
// Skip command argument separation (a space).
|
|
115
|
-
|
|
88
|
+
sep(src, ctx);
|
|
116
89
|
return { childPath, childTreeNode };
|
|
117
90
|
}
|
|
118
91
|
else {
|
|
119
92
|
// End-of-command.
|
|
120
93
|
if (!childTreeNode.executable) {
|
|
121
|
-
ctx.err.report(
|
|
94
|
+
ctx.err.report(localize('mcfunction.parser.eoc-unexpected'), src);
|
|
122
95
|
}
|
|
123
96
|
}
|
|
124
97
|
}
|
|
125
98
|
else {
|
|
126
99
|
// Failed to parse as any arguments.
|
|
127
|
-
ctx.err.report(
|
|
100
|
+
ctx.err.report(localize('expected', treeNodeChildrenToString(children)), core.Range.create(src));
|
|
128
101
|
}
|
|
129
102
|
return false;
|
|
130
103
|
}
|
|
@@ -138,7 +111,7 @@ function unknown(treeNode) {
|
|
|
138
111
|
const start = src.cursor;
|
|
139
112
|
const value = src.readUntilLineEnd();
|
|
140
113
|
const range = core.Range.create(start, src);
|
|
141
|
-
ctx.err.report(
|
|
114
|
+
ctx.err.report(localize('mcfunction.parser.unknown-parser', localeQuote(treeNode.parser)), range, 0 /* core.ErrorSeverity.Hint */);
|
|
142
115
|
return {
|
|
143
116
|
type: 'mcfunction:command_child/unknown',
|
|
144
117
|
range,
|
|
@@ -150,7 +123,7 @@ const trailing = (src, ctx) => {
|
|
|
150
123
|
const start = src.cursor;
|
|
151
124
|
const value = src.readUntilLineEnd();
|
|
152
125
|
const range = core.Range.create(start, src);
|
|
153
|
-
ctx.err.report(
|
|
126
|
+
ctx.err.report(localize('mcfunction.parser.trailing', localeQuote(value)), range);
|
|
154
127
|
return {
|
|
155
128
|
type: 'mcfunction:command_child/trailing',
|
|
156
129
|
range,
|
|
@@ -160,26 +133,23 @@ const trailing = (src, ctx) => {
|
|
|
160
133
|
function wrapWithBrackets(syntax, executable) {
|
|
161
134
|
return executable ? `[${syntax}]` : syntax;
|
|
162
135
|
}
|
|
163
|
-
function treeNodeChildrenToStringArray(children, executable = false) {
|
|
136
|
+
export function treeNodeChildrenToStringArray(children, executable = false) {
|
|
164
137
|
const entries = Object.entries(children)
|
|
165
138
|
.map(([name, treeNode]) => wrapWithBrackets(treeNodeToString(name, treeNode), executable));
|
|
166
139
|
return entries;
|
|
167
140
|
}
|
|
168
|
-
|
|
169
|
-
function treeNodeChildrenToString(children) {
|
|
141
|
+
export function treeNodeChildrenToString(children) {
|
|
170
142
|
const entries = treeNodeChildrenToStringArray(children);
|
|
171
143
|
return entries.length > 5
|
|
172
144
|
? `${entries.slice(0, 3).join('|')}|...|${entries.slice(-2).join('|')}`
|
|
173
145
|
: entries.join('|');
|
|
174
146
|
}
|
|
175
|
-
|
|
176
|
-
function treeNodeToString(name, treeNode) {
|
|
147
|
+
export function treeNodeToString(name, treeNode) {
|
|
177
148
|
if (treeNode.type === 'argument') {
|
|
178
|
-
return
|
|
149
|
+
return argumentTreeNodeToString(name, treeNode);
|
|
179
150
|
}
|
|
180
151
|
else {
|
|
181
152
|
return name;
|
|
182
153
|
}
|
|
183
154
|
}
|
|
184
|
-
exports.treeNodeToString = treeNodeToString;
|
|
185
155
|
//# sourceMappingURL=command.js.map
|
package/lib/parser/common.js
CHANGED
|
@@ -1,43 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.sep = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
29
3
|
/**
|
|
30
4
|
* A parser that takes a continuous sequence of spaces and tabs, and marks an error if it is not a single space.
|
|
31
5
|
*
|
|
32
6
|
* @returns The accepted spaces and tabs.
|
|
33
7
|
*/
|
|
34
|
-
const sep = (src, ctx) => {
|
|
8
|
+
export const sep = (src, ctx) => {
|
|
35
9
|
const start = src.cursor;
|
|
36
10
|
const ans = src.readSpace();
|
|
37
11
|
if (ans !== ' ') {
|
|
38
|
-
ctx.err.report(
|
|
12
|
+
ctx.err.report(localize('expected', localize('mcfunction.parser.sep', localeQuote(' '))), core.Range.create(start, src));
|
|
39
13
|
}
|
|
40
14
|
return ans;
|
|
41
15
|
};
|
|
42
|
-
exports.sep = sep;
|
|
43
16
|
//# sourceMappingURL=common.js.map
|
package/lib/parser/entry.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { McfunctionNode } from '../node';
|
|
3
|
-
import type { ArgumentParserGetter } from './argument';
|
|
2
|
+
import type { McfunctionNode } from '../node/index.js';
|
|
3
|
+
import type { ArgumentParserGetter } from './argument.js';
|
|
4
4
|
/**
|
|
5
5
|
* @throws When there's no command tree associated with `commandTreeName`.
|
|
6
6
|
*/
|
package/lib/parser/entry.js
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.entry = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const tree_1 = require("../tree");
|
|
29
|
-
const command_1 = require("./command");
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { CommandTreeRegistry } from '../tree/index.js';
|
|
3
|
+
import { command } from './command.js';
|
|
30
4
|
/**
|
|
31
5
|
* @throws When there's no command tree associated with `commandTreeName`.
|
|
32
6
|
*/
|
|
33
|
-
function entry(commandTreeName, argument) {
|
|
7
|
+
export function entry(commandTreeName, argument) {
|
|
34
8
|
return (src, ctx) => {
|
|
35
9
|
const ans = {
|
|
36
10
|
type: 'mcfunction:entry',
|
|
@@ -43,7 +17,7 @@ function entry(commandTreeName, argument) {
|
|
|
43
17
|
result = comment(src, ctx);
|
|
44
18
|
}
|
|
45
19
|
else {
|
|
46
|
-
result =
|
|
20
|
+
result = command(CommandTreeRegistry.instance.get(commandTreeName), argument)(src, ctx);
|
|
47
21
|
}
|
|
48
22
|
ans.children.push(result);
|
|
49
23
|
src.nextLine();
|
|
@@ -52,7 +26,6 @@ function entry(commandTreeName, argument) {
|
|
|
52
26
|
return ans;
|
|
53
27
|
};
|
|
54
28
|
}
|
|
55
|
-
exports.entry = entry;
|
|
56
29
|
const comment = core.comment({
|
|
57
30
|
singleLinePrefixes: new Set(['#']),
|
|
58
31
|
});
|
package/lib/parser/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './argument';
|
|
2
|
-
export * from './command';
|
|
3
|
-
export * from './common';
|
|
4
|
-
export * from './entry';
|
|
5
|
-
export * from './literal';
|
|
1
|
+
export * from './argument.js';
|
|
2
|
+
export * from './command.js';
|
|
3
|
+
export * from './common.js';
|
|
4
|
+
export * from './entry.js';
|
|
5
|
+
export * from './literal.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/parser/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./argument"), exports);
|
|
18
|
-
__exportStar(require("./command"), exports);
|
|
19
|
-
__exportStar(require("./common"), exports);
|
|
20
|
-
__exportStar(require("./entry"), exports);
|
|
21
|
-
__exportStar(require("./literal"), exports);
|
|
1
|
+
export * from './argument.js';
|
|
2
|
+
export * from './command.js';
|
|
3
|
+
export * from './common.js';
|
|
4
|
+
export * from './entry.js';
|
|
5
|
+
export * from './literal.js';
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/lib/parser/literal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { LiteralCommandChildNode } from '../node';
|
|
2
|
+
import type { LiteralCommandChildNode } from '../node/index.js';
|
|
3
3
|
export declare function literal(names: string[], isRoot?: boolean): core.Parser<LiteralCommandChildNode>;
|
|
4
4
|
//# sourceMappingURL=literal.d.ts.map
|
package/lib/parser/literal.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.literal = void 0;
|
|
27
|
-
const core = __importStar(require("@spyglassmc/core"));
|
|
28
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
29
|
-
function literal(names, isRoot = false) {
|
|
1
|
+
import * as core from '@spyglassmc/core';
|
|
2
|
+
import { localize } from '@spyglassmc/locales';
|
|
3
|
+
export function literal(names, isRoot = false) {
|
|
30
4
|
const options = {
|
|
31
5
|
pool: names,
|
|
32
6
|
colorTokenType: isRoot ? 'keyword' : 'literal',
|
|
@@ -44,10 +18,9 @@ function literal(names, isRoot = false) {
|
|
|
44
18
|
value,
|
|
45
19
|
};
|
|
46
20
|
if (!names.includes(value)) {
|
|
47
|
-
ctx.err.report(
|
|
21
|
+
ctx.err.report(localize('expected', names), ans);
|
|
48
22
|
}
|
|
49
23
|
return ans;
|
|
50
24
|
};
|
|
51
25
|
}
|
|
52
|
-
exports.literal = literal;
|
|
53
26
|
//# sourceMappingURL=literal.js.map
|
package/lib/tree/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './registry';
|
|
2
|
-
export * from './type';
|
|
3
|
-
export * from './util';
|
|
1
|
+
export * from './registry.js';
|
|
2
|
+
export * from './type.js';
|
|
3
|
+
export * from './util.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/tree/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./registry"), exports);
|
|
18
|
-
__exportStar(require("./type"), exports);
|
|
19
|
-
__exportStar(require("./util"), exports);
|
|
1
|
+
export * from './registry.js';
|
|
2
|
+
export * from './type.js';
|
|
3
|
+
export * from './util.js';
|
|
20
4
|
//# sourceMappingURL=index.js.map
|
package/lib/tree/registry.d.ts
CHANGED
package/lib/tree/registry.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _CommandTreeRegistry_trees;
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.CommandTreeRegistry = void 0;
|
|
10
|
-
const core_1 = require("@spyglassmc/core");
|
|
1
|
+
import { merge } from '@spyglassmc/core';
|
|
11
2
|
/* istanbul ignore next */
|
|
12
3
|
/**
|
|
13
4
|
* The registry for mcfunction command trees.
|
|
14
5
|
* This is a singleton; use the `instance` static property to get an instance.
|
|
15
6
|
*/
|
|
16
|
-
class CommandTreeRegistry {
|
|
17
|
-
|
|
18
|
-
_CommandTreeRegistry_trees.set(this, new Map()
|
|
19
|
-
/**
|
|
20
|
-
* Register command tree for an arbitrary version.
|
|
21
|
-
*
|
|
22
|
-
* @param version The game version. e.g. `1.15-tdn`.
|
|
23
|
-
* @param tree The command tree for this version.
|
|
24
|
-
* @param treePatch A custom command tree patch that will be merged onto `tree`.
|
|
25
|
-
*/
|
|
26
|
-
);
|
|
27
|
-
if (CommandTreeRegistry._instance) {
|
|
28
|
-
throw new Error('Use the `instance` static property to get an instance.');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
7
|
+
export class CommandTreeRegistry {
|
|
8
|
+
#trees = new Map();
|
|
31
9
|
/**
|
|
32
10
|
* Register command tree for an arbitrary version.
|
|
33
11
|
*
|
|
@@ -36,13 +14,13 @@ class CommandTreeRegistry {
|
|
|
36
14
|
* @param treePatch A custom command tree patch that will be merged onto `tree`.
|
|
37
15
|
*/
|
|
38
16
|
register(version, tree, treePatch) {
|
|
39
|
-
|
|
17
|
+
this.#trees.set(version, treePatch ? merge(tree, treePatch) : tree);
|
|
40
18
|
}
|
|
41
19
|
/**
|
|
42
20
|
* @throws When there's no command tree associated with the version.
|
|
43
21
|
*/
|
|
44
22
|
get(version) {
|
|
45
|
-
const ans =
|
|
23
|
+
const ans = this.#trees.get(version);
|
|
46
24
|
if (!ans) {
|
|
47
25
|
throw new Error(`No command tree exist for version “${version}”`);
|
|
48
26
|
}
|
|
@@ -54,7 +32,11 @@ class CommandTreeRegistry {
|
|
|
54
32
|
static get instance() {
|
|
55
33
|
return this._instance ?? (this._instance = new CommandTreeRegistry());
|
|
56
34
|
}
|
|
35
|
+
constructor() {
|
|
36
|
+
if (CommandTreeRegistry._instance) {
|
|
37
|
+
throw new Error('Use the `instance` static property to get an instance.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static _instance;
|
|
57
41
|
}
|
|
58
|
-
exports.CommandTreeRegistry = CommandTreeRegistry;
|
|
59
|
-
_CommandTreeRegistry_trees = new WeakMap();
|
|
60
42
|
//# sourceMappingURL=registry.js.map
|
package/lib/tree/type.js
CHANGED
package/lib/tree/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ArgumentTreeNode, LiteralTreeNode, RootTreeNode, TreeNode } from './type';
|
|
1
|
+
import type { ArgumentTreeNode, LiteralTreeNode, RootTreeNode, TreeNode } from './type.js';
|
|
2
2
|
export declare function redirect(rootTreeNode: TreeNode, path: readonly string[]): TreeNode | undefined;
|
|
3
3
|
/**
|
|
4
4
|
* @returns A `TreeNode` whose `children` property, if exists, contains its subsequent `TreeNode`s.
|
package/lib/tree/util.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.categorizeTreeChildren = exports.resolveParentTreeNode = exports.redirect = void 0;
|
|
4
|
-
function redirect(rootTreeNode, path) {
|
|
1
|
+
export function redirect(rootTreeNode, path) {
|
|
5
2
|
return path.reduce((p, c) => p?.children?.[c], rootTreeNode);
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
function resolveParentTreeNode(parentTreeNode, rootTreeNode, parentPath) {
|
|
4
|
+
export function resolveParentTreeNode(parentTreeNode, rootTreeNode, parentPath) {
|
|
9
5
|
if (parentTreeNode?.redirect) {
|
|
10
6
|
return { treeNode: redirect(rootTreeNode, parentTreeNode.redirect), path: [...parentTreeNode.redirect] };
|
|
11
7
|
}
|
|
@@ -18,11 +14,10 @@ function resolveParentTreeNode(parentTreeNode, rootTreeNode, parentPath) {
|
|
|
18
14
|
return { treeNode: parentTreeNode, path: parentPath };
|
|
19
15
|
}
|
|
20
16
|
}
|
|
21
|
-
exports.resolveParentTreeNode = resolveParentTreeNode;
|
|
22
17
|
/**
|
|
23
18
|
* Categorize command tree children to literal entries and argument entries.
|
|
24
19
|
*/
|
|
25
|
-
function categorizeTreeChildren(children) {
|
|
20
|
+
export function categorizeTreeChildren(children) {
|
|
26
21
|
const ans = {
|
|
27
22
|
literalTreeNodes: [],
|
|
28
23
|
argumentTreeNodes: [],
|
|
@@ -38,5 +33,4 @@ function categorizeTreeChildren(children) {
|
|
|
38
33
|
}
|
|
39
34
|
return ans;
|
|
40
35
|
}
|
|
41
|
-
exports.categorizeTreeChildren = categorizeTreeChildren;
|
|
42
36
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcfunction",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "lib/index.js",
|
|
5
6
|
"types": "lib/index.d.ts",
|
|
6
7
|
"author": "SPGoding",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@spyglassmc/core": "0.
|
|
28
|
-
"@spyglassmc/locales": "0.
|
|
28
|
+
"@spyglassmc/core": "0.2.0",
|
|
29
|
+
"@spyglassmc/locales": "0.2.0"
|
|
29
30
|
}
|
|
30
31
|
}
|