@wq2/brigadier-ts 1.0.0 → 1.0.1
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 +1 -0
- package/dist/Command.d.ts +2 -2
- package/dist/CommandDispatcher.d.ts +1 -1
- package/dist/CommandDispatcher.js +231 -357
- package/dist/ParseResults.d.ts +1 -1
- package/dist/ParseResults.js +9 -10
- package/dist/StringReader.d.ts +1 -1
- package/dist/StringReader.js +75 -77
- package/dist/arguments/ArgumentType.d.ts +1 -1
- package/dist/arguments/ArgumentType.js +9 -8
- package/dist/arguments/BoolArgumentType.d.ts +5 -1
- package/dist/arguments/BoolArgumentType.js +9 -27
- package/dist/arguments/FloatArgumentType.d.ts +1 -1
- package/dist/arguments/FloatArgumentType.js +11 -30
- package/dist/arguments/IntegerArgumentType.d.ts +1 -1
- package/dist/arguments/IntegerArgumentType.js +11 -30
- package/dist/arguments/LongArgumentType.d.ts +3 -3
- package/dist/arguments/LongArgumentType.js +13 -32
- package/dist/arguments/NumberArgumentType.d.ts +2 -2
- package/dist/arguments/NumberArgumentType.js +15 -33
- package/dist/arguments/StringArgumentType.d.ts +1 -1
- package/dist/arguments/StringArgumentType.js +11 -29
- package/dist/builder/ArgumentBuilder.d.ts +1 -1
- package/dist/builder/ArgumentBuilder.js +31 -71
- package/dist/builder/LiteralArgumentBuilder.js +14 -33
- package/dist/builder/RequiredArgumentBuilder.d.ts +1 -1
- package/dist/builder/RequiredArgumentBuilder.js +18 -37
- package/dist/context/CommandContext.d.ts +1 -1
- package/dist/context/CommandContext.js +31 -32
- package/dist/context/CommandContextBuilder.d.ts +1 -1
- package/dist/context/CommandContextBuilder.js +47 -50
- package/dist/context/ParsedArgument.js +8 -9
- package/dist/context/ParsedCommandNode.d.ts +1 -1
- package/dist/context/ParsedCommandNode.js +7 -8
- package/dist/context/StringRange.js +17 -18
- package/dist/context/SuggestionContext.d.ts +1 -1
- package/dist/context/SuggestionContext.js +3 -4
- package/dist/exceptions/CommandErrorType.d.ts +3 -3
- package/dist/exceptions/CommandErrorType.js +10 -19
- package/dist/exceptions/CommandSyntaxError.js +36 -54
- package/dist/suggestion/Suggestion.d.ts +1 -1
- package/dist/suggestion/Suggestion.js +16 -17
- package/dist/suggestion/Suggestions.d.ts +1 -1
- package/dist/suggestion/Suggestions.js +28 -30
- package/dist/suggestion/SuggestionsBuilder.d.ts +1 -1
- package/dist/suggestion/SuggestionsBuilder.js +22 -23
- package/dist/tree/ArgumentCommandNode.d.ts +1 -1
- package/dist/tree/ArgumentCommandNode.js +22 -40
- package/dist/tree/CommandNode.d.ts +1 -1
- package/dist/tree/CommandNode.js +28 -29
- package/dist/tree/LiteralCommandNode.d.ts +1 -1
- package/dist/tree/LiteralCommandNode.js +28 -41
- package/dist/tree/RootCommandNode.d.ts +1 -1
- package/dist/tree/RootCommandNode.js +17 -69
- package/jest.config.js +5 -5
- package/package.json +32 -32
- package/src/Command.ts +2 -2
- package/src/CommandDispatcher.ts +397 -295
- package/src/ParseResults.ts +26 -22
- package/src/StringReader.ts +212 -193
- package/src/arguments/ArgumentType.ts +13 -8
- package/src/arguments/BoolArgumentType.ts +22 -21
- package/src/arguments/FloatArgumentType.ts +13 -14
- package/src/arguments/IntegerArgumentType.ts +13 -14
- package/src/arguments/LongArgumentType.ts +16 -17
- package/src/arguments/NumberArgumentType.ts +48 -38
- package/src/arguments/StringArgumentType.ts +26 -26
- package/src/builder/ArgumentBuilder.ts +80 -75
- package/src/builder/LiteralArgumentBuilder.ts +31 -21
- package/src/builder/RequiredArgumentBuilder.ts +42 -32
- package/src/context/CommandContext.ts +99 -76
- package/src/context/CommandContextBuilder.ts +169 -143
- package/src/context/ParsedArgument.ts +13 -13
- package/src/context/ParsedCommandNode.ts +14 -14
- package/src/context/StringRange.ts +26 -26
- package/src/context/SuggestionContext.ts +7 -7
- package/src/exceptions/CommandErrorType.ts +20 -13
- package/src/exceptions/CommandSyntaxError.ts +78 -37
- package/src/index.ts +30 -30
- package/src/suggestion/Suggestion.ts +46 -46
- package/src/suggestion/Suggestions.ts +59 -57
- package/src/suggestion/SuggestionsBuilder.ts +59 -57
- package/src/tree/ArgumentCommandNode.ts +51 -40
- package/src/tree/CommandNode.ts +96 -87
- package/src/tree/LiteralCommandNode.ts +78 -57
- package/src/tree/RootCommandNode.ts +33 -23
- package/test/Arguments.test.ts +47 -33
- package/test/CommandDispatcher.test.ts +18 -22
- package/test/StringReader.test.ts +47 -47
- package/tsconfig.json +9 -14
|
@@ -1,38 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.StringArgumentType = void 0;
|
|
19
4
|
exports.word = word;
|
|
20
5
|
exports.string = string;
|
|
21
6
|
exports.greedyString = greedyString;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_this.type = type;
|
|
28
|
-
return _this;
|
|
7
|
+
const __1 = require("..");
|
|
8
|
+
class StringArgumentType extends __1.ArgumentType {
|
|
9
|
+
constructor(type) {
|
|
10
|
+
super();
|
|
11
|
+
this.type = type;
|
|
29
12
|
}
|
|
30
|
-
|
|
13
|
+
getType() {
|
|
31
14
|
return this.type;
|
|
32
|
-
}
|
|
33
|
-
|
|
15
|
+
}
|
|
16
|
+
parse(reader) {
|
|
34
17
|
if (this.type === "greedy_phrase") {
|
|
35
|
-
|
|
18
|
+
const text = reader.getRemaining();
|
|
36
19
|
reader.setCursor(reader.getTotalLength());
|
|
37
20
|
return text;
|
|
38
21
|
}
|
|
@@ -42,9 +25,8 @@ var StringArgumentType = /** @class */ (function (_super) {
|
|
|
42
25
|
else {
|
|
43
26
|
return reader.readString();
|
|
44
27
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}(__1.ArgumentType));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
48
30
|
exports.StringArgumentType = StringArgumentType;
|
|
49
31
|
function word() {
|
|
50
32
|
return new StringArgumentType("single_word");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandNode, Command, Predicate, CommandContext } from "..";
|
|
1
|
+
import { CommandNode, type Command, type Predicate, type CommandContext } from "..";
|
|
2
2
|
export type RedirectModifier<S> = (context: CommandContext<S>) => S | S[];
|
|
3
3
|
export declare abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
|
4
4
|
private arguments;
|
|
@@ -1,95 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.ArgumentBuilder = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _this = this;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class ArgumentBuilder {
|
|
6
|
+
constructor() {
|
|
44
7
|
this.arguments = new __1.RootCommandNode();
|
|
45
|
-
this.requirement =
|
|
46
|
-
return [2 /*return*/, true];
|
|
47
|
-
}); }); };
|
|
8
|
+
this.requirement = async (_) => true;
|
|
48
9
|
}
|
|
49
|
-
|
|
50
|
-
|
|
10
|
+
// biome-ignore lint/suspicious/noThenProperty: proof?
|
|
11
|
+
then(argument) {
|
|
12
|
+
const child = argument instanceof __1.CommandNode ? argument : argument.build();
|
|
51
13
|
this.arguments.addChild(child);
|
|
52
14
|
return this.getThis();
|
|
53
|
-
}
|
|
54
|
-
|
|
15
|
+
}
|
|
16
|
+
executes(command) {
|
|
55
17
|
this.command = command;
|
|
56
18
|
return this.getThis();
|
|
57
|
-
}
|
|
58
|
-
|
|
19
|
+
}
|
|
20
|
+
requires(requirement) {
|
|
59
21
|
this.requirement = requirement;
|
|
60
22
|
return this.getThis();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (modifier === void 0) { modifier = null; }
|
|
23
|
+
}
|
|
24
|
+
redirect(target, modifier = null) {
|
|
64
25
|
return this.forward(target, modifier, false);
|
|
65
|
-
}
|
|
66
|
-
|
|
26
|
+
}
|
|
27
|
+
fork(target, modifier) {
|
|
67
28
|
return this.forward(target, modifier, true);
|
|
68
|
-
}
|
|
69
|
-
|
|
29
|
+
}
|
|
30
|
+
forward(target, modifier, forks) {
|
|
70
31
|
this.target = target;
|
|
71
32
|
this.modifier = modifier;
|
|
72
33
|
this.forks = forks;
|
|
73
34
|
return this.getThis();
|
|
74
|
-
}
|
|
75
|
-
|
|
35
|
+
}
|
|
36
|
+
getArguments() {
|
|
76
37
|
return this.arguments.getChildren();
|
|
77
|
-
}
|
|
78
|
-
|
|
38
|
+
}
|
|
39
|
+
getCommand() {
|
|
79
40
|
return this.command;
|
|
80
|
-
}
|
|
81
|
-
|
|
41
|
+
}
|
|
42
|
+
getRequirement() {
|
|
82
43
|
return this.requirement;
|
|
83
|
-
}
|
|
84
|
-
|
|
44
|
+
}
|
|
45
|
+
getRedirect() {
|
|
85
46
|
return this.target;
|
|
86
|
-
}
|
|
87
|
-
|
|
47
|
+
}
|
|
48
|
+
getRedirectModifier() {
|
|
88
49
|
return this.modifier;
|
|
89
|
-
}
|
|
90
|
-
|
|
50
|
+
}
|
|
51
|
+
isFork() {
|
|
91
52
|
return this.forks;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
95
55
|
exports.ArgumentBuilder = ArgumentBuilder;
|
|
@@ -1,46 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.LiteralArgumentBuilder = void 0;
|
|
19
4
|
exports.literal = literal;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_this.literal = literal;
|
|
26
|
-
return _this;
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
class LiteralArgumentBuilder extends __1.ArgumentBuilder {
|
|
7
|
+
constructor(literal) {
|
|
8
|
+
super();
|
|
9
|
+
this.literal = literal;
|
|
27
10
|
}
|
|
28
|
-
|
|
11
|
+
getThis() {
|
|
29
12
|
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
13
|
+
}
|
|
14
|
+
getLiteral() {
|
|
32
15
|
return this.literal;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (
|
|
37
|
-
var argument = _a[_i];
|
|
16
|
+
}
|
|
17
|
+
build() {
|
|
18
|
+
const result = new __1.LiteralCommandNode(this.getLiteral(), this.getCommand(), this.getRequirement(), this.getRedirect(), this.getRedirectModifier(), this.isFork());
|
|
19
|
+
for (const argument of this.getArguments()) {
|
|
38
20
|
result.addChild(argument);
|
|
39
21
|
}
|
|
40
22
|
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}(__1.ArgumentBuilder));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
44
25
|
exports.LiteralArgumentBuilder = LiteralArgumentBuilder;
|
|
45
26
|
function literal(name) {
|
|
46
27
|
return new LiteralArgumentBuilder(name);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArgumentBuilder, ArgumentType, ArgumentCommandNode } from "..";
|
|
1
|
+
import { ArgumentBuilder, type ArgumentType, ArgumentCommandNode } from "..";
|
|
2
2
|
export declare class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
|
|
3
3
|
private name;
|
|
4
4
|
private type;
|
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.RequiredArgumentBuilder = void 0;
|
|
19
4
|
exports.argument = argument;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_this.type = type;
|
|
27
|
-
return _this;
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
class RequiredArgumentBuilder extends __1.ArgumentBuilder {
|
|
7
|
+
constructor(name, type) {
|
|
8
|
+
super();
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.type = type;
|
|
28
11
|
}
|
|
29
|
-
|
|
12
|
+
getThis() {
|
|
30
13
|
return this;
|
|
31
|
-
}
|
|
32
|
-
|
|
14
|
+
}
|
|
15
|
+
getName() {
|
|
33
16
|
return this.name;
|
|
34
|
-
}
|
|
35
|
-
|
|
17
|
+
}
|
|
18
|
+
getType() {
|
|
36
19
|
return this.type;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
result.addChild(argument_1);
|
|
20
|
+
}
|
|
21
|
+
build() {
|
|
22
|
+
const result = new __1.ArgumentCommandNode(this.getName(), this.getType(), this.getCommand(), this.getRequirement(), this.getRedirect(), this.getRedirectModifier(), this.isFork());
|
|
23
|
+
for (const argument of this.getArguments()) {
|
|
24
|
+
result.addChild(argument);
|
|
43
25
|
}
|
|
44
26
|
return result;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}(__1.ArgumentBuilder));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
48
29
|
exports.RequiredArgumentBuilder = RequiredArgumentBuilder;
|
|
49
30
|
function argument(name, type) {
|
|
50
31
|
return new RequiredArgumentBuilder(name, type);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandNode, StringRange, ParsedArgument, ParsedCommandNode, RedirectModifier } from "..";
|
|
1
|
+
import type { Command, CommandNode, StringRange, ParsedArgument, ParsedCommandNode, RedirectModifier } from "..";
|
|
2
2
|
export declare class CommandContext<S> {
|
|
3
3
|
private source;
|
|
4
4
|
private input;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandContext = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class CommandContext {
|
|
5
|
+
constructor(source, input, parsedArguments, command, rootNode, nodes, range, child, modifier, forks) {
|
|
6
6
|
this.source = source;
|
|
7
7
|
this.input = input;
|
|
8
8
|
this.arguments = parsedArguments;
|
|
@@ -14,54 +14,53 @@ var CommandContext = /** @class */ (function () {
|
|
|
14
14
|
this.modifier = modifier;
|
|
15
15
|
this.forks = forks;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
copyFor(source) {
|
|
18
18
|
if (this.source === source) {
|
|
19
19
|
return this;
|
|
20
20
|
}
|
|
21
21
|
return new CommandContext(source, this.input, this.arguments, this.command, this.rootNode, this.nodes, this.range, this.child, this.modifier, this.forks);
|
|
22
|
-
}
|
|
23
|
-
|
|
22
|
+
}
|
|
23
|
+
getChild() {
|
|
24
24
|
return this.child;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
}
|
|
26
|
+
getLastChild() {
|
|
27
|
+
let result = this;
|
|
28
28
|
while (result.getChild() != null) {
|
|
29
29
|
result = result.getChild();
|
|
30
30
|
}
|
|
31
31
|
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
}
|
|
33
|
+
getCommand() {
|
|
34
34
|
return this.command;
|
|
35
|
-
}
|
|
36
|
-
|
|
35
|
+
}
|
|
36
|
+
getSource() {
|
|
37
37
|
return this.source;
|
|
38
|
-
}
|
|
39
|
-
|
|
38
|
+
}
|
|
39
|
+
getRootNode() {
|
|
40
40
|
return this.rootNode;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
}
|
|
42
|
+
get(name) {
|
|
43
|
+
const argument = this.arguments.get(name);
|
|
44
44
|
// TODO: Throw exception when argument is null
|
|
45
45
|
return argument.getResult();
|
|
46
|
-
}
|
|
47
|
-
|
|
46
|
+
}
|
|
47
|
+
getRedirectModifier() {
|
|
48
48
|
return this.modifier;
|
|
49
|
-
}
|
|
50
|
-
|
|
49
|
+
}
|
|
50
|
+
getRange() {
|
|
51
51
|
return this.range;
|
|
52
|
-
}
|
|
53
|
-
|
|
52
|
+
}
|
|
53
|
+
getInput() {
|
|
54
54
|
return this.input;
|
|
55
|
-
}
|
|
56
|
-
|
|
55
|
+
}
|
|
56
|
+
getNodes() {
|
|
57
57
|
return this.nodes;
|
|
58
|
-
}
|
|
59
|
-
|
|
58
|
+
}
|
|
59
|
+
hasNodes() {
|
|
60
60
|
return this.nodes.length !== 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
61
|
+
}
|
|
62
|
+
isForked() {
|
|
63
63
|
return this.forks;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}());
|
|
64
|
+
}
|
|
65
|
+
}
|
|
67
66
|
exports.CommandContext = CommandContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandNode, CommandDispatcher, Command, CommandContext, StringRange, ParsedCommandNode, ParsedArgument, SuggestionContext } from "..";
|
|
1
|
+
import { type CommandNode, type CommandDispatcher, type Command, CommandContext, StringRange, ParsedCommandNode, type ParsedArgument, SuggestionContext } from "..";
|
|
2
2
|
export declare class CommandContextBuilder<S> {
|
|
3
3
|
private source;
|
|
4
4
|
private arguments;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandContextBuilder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class CommandContextBuilder {
|
|
6
|
+
constructor(dispatcher, source, rootNode, start) {
|
|
7
7
|
this.dispatcher = dispatcher;
|
|
8
8
|
this.source = source;
|
|
9
9
|
this.rootNode = rootNode;
|
|
@@ -11,84 +11,83 @@ var CommandContextBuilder = /** @class */ (function () {
|
|
|
11
11
|
this.nodes = [];
|
|
12
12
|
this.arguments = new Map();
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
withSource(source) {
|
|
15
15
|
this.source = source;
|
|
16
16
|
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
getSource() {
|
|
19
19
|
return this.source;
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
}
|
|
21
|
+
getRootNode() {
|
|
22
22
|
return this.rootNode;
|
|
23
|
-
}
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
withArgument(name, argument) {
|
|
25
25
|
this.arguments.set(name, argument);
|
|
26
26
|
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
27
|
+
}
|
|
28
|
+
getArguments() {
|
|
29
29
|
return this.arguments;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
withChild(child) {
|
|
32
32
|
this.child = child;
|
|
33
33
|
return this;
|
|
34
|
-
}
|
|
35
|
-
|
|
34
|
+
}
|
|
35
|
+
getChild() {
|
|
36
36
|
return this.child;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
}
|
|
38
|
+
getLastChild() {
|
|
39
|
+
let result = this;
|
|
40
40
|
while (result.getChild() != null) {
|
|
41
41
|
result = result.getChild();
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
44
|
+
}
|
|
45
|
+
withCommand(command) {
|
|
46
46
|
this.command = command;
|
|
47
47
|
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
48
|
+
}
|
|
49
|
+
getCommand() {
|
|
50
50
|
return this.command;
|
|
51
|
-
}
|
|
52
|
-
|
|
51
|
+
}
|
|
52
|
+
withNode(node, range) {
|
|
53
53
|
this.nodes.push(new __1.ParsedCommandNode(node, range));
|
|
54
54
|
this.range = __1.StringRange.encompassing(this.range, range);
|
|
55
55
|
this.modifier = node.getRedirectModifier();
|
|
56
56
|
this.forks = node.isFork();
|
|
57
57
|
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
58
|
+
}
|
|
59
|
+
getNodes() {
|
|
60
60
|
return this.nodes;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var copy = new CommandContextBuilder(this.dispatcher, this.source, this.rootNode, this.range.getStart());
|
|
61
|
+
}
|
|
62
|
+
copy() {
|
|
63
|
+
const copy = new CommandContextBuilder(this.dispatcher, this.source, this.rootNode, this.range.getStart());
|
|
65
64
|
copy.command = this.command;
|
|
66
65
|
copy.child = this.child;
|
|
67
66
|
copy.range = this.range;
|
|
68
|
-
|
|
69
|
-
this.arguments.forEach(
|
|
67
|
+
copy.nodes.push(...this.nodes);
|
|
68
|
+
this.arguments.forEach((v, k) => {
|
|
70
69
|
copy.arguments.set(k, v);
|
|
71
70
|
});
|
|
72
71
|
return copy;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
}
|
|
73
|
+
build(input) {
|
|
74
|
+
const child = this.child == null ? null : this.child.build(input);
|
|
76
75
|
return new __1.CommandContext(this.source, input, this.arguments, this.command, this.rootNode, this.nodes, this.range, child, this.modifier, this.forks);
|
|
77
|
-
}
|
|
78
|
-
|
|
76
|
+
}
|
|
77
|
+
getDispatcher() {
|
|
79
78
|
return this.dispatcher;
|
|
80
|
-
}
|
|
81
|
-
|
|
79
|
+
}
|
|
80
|
+
getRange() {
|
|
82
81
|
return this.range;
|
|
83
|
-
}
|
|
84
|
-
|
|
82
|
+
}
|
|
83
|
+
findSuggestionContext(cursor) {
|
|
85
84
|
if (this.range.getStart() <= cursor) {
|
|
86
85
|
if (this.range.getEnd() < cursor) {
|
|
87
86
|
if (this.child != null) {
|
|
88
87
|
return this.child.findSuggestionContext(cursor);
|
|
89
88
|
}
|
|
90
89
|
else if (this.nodes.length > 0) {
|
|
91
|
-
|
|
90
|
+
const last = this.nodes[this.nodes.length - 1];
|
|
92
91
|
return new __1.SuggestionContext(last.getNode(), last.getRange().getEnd() + 1);
|
|
93
92
|
}
|
|
94
93
|
else {
|
|
@@ -96,10 +95,9 @@ var CommandContextBuilder = /** @class */ (function () {
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
else {
|
|
99
|
-
|
|
100
|
-
for (
|
|
101
|
-
|
|
102
|
-
var nodeRange = node.getRange();
|
|
98
|
+
let prev = this.rootNode;
|
|
99
|
+
for (const node of this.nodes) {
|
|
100
|
+
const nodeRange = node.getRange();
|
|
103
101
|
if (nodeRange.getStart() <= cursor && cursor <= nodeRange.getEnd()) {
|
|
104
102
|
return new __1.SuggestionContext(prev, nodeRange.getStart());
|
|
105
103
|
}
|
|
@@ -112,7 +110,6 @@ var CommandContextBuilder = /** @class */ (function () {
|
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
throw new Error("Can't find node before cursor");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}());
|
|
113
|
+
}
|
|
114
|
+
}
|
|
118
115
|
exports.CommandContextBuilder = CommandContextBuilder;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedArgument = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class ParsedArgument {
|
|
6
|
+
constructor(start, end, result) {
|
|
7
7
|
this.range = new __1.StringRange(start, end);
|
|
8
8
|
this.result = result;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
getRange() {
|
|
11
11
|
return this.range;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
getResult() {
|
|
14
14
|
return this.result;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
18
17
|
exports.ParsedArgument = ParsedArgument;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedCommandNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class ParsedCommandNode {
|
|
5
|
+
constructor(node, range) {
|
|
6
6
|
this.node = node;
|
|
7
7
|
this.range = range;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
getNode() {
|
|
10
10
|
return this.node;
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
getRange() {
|
|
13
13
|
return this.range;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
17
16
|
exports.ParsedCommandNode = ParsedCommandNode;
|