@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,31 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringRange = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class StringRange {
|
|
5
|
+
constructor(start, end) {
|
|
6
6
|
this.start = start;
|
|
7
7
|
this.end = end;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
static at(pos) {
|
|
10
10
|
return new StringRange(pos, pos);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
}
|
|
12
|
+
static encompassing(a, b) {
|
|
13
|
+
const start = Math.min(a.getStart(), b.getStart());
|
|
14
|
+
const end = Math.max(a.getEnd(), b.getEnd());
|
|
15
15
|
return new StringRange(start, end);
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
}
|
|
17
|
+
getStart() {
|
|
18
18
|
return this.start;
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
}
|
|
20
|
+
getEnd() {
|
|
21
21
|
return this.end;
|
|
22
|
-
}
|
|
23
|
-
|
|
22
|
+
}
|
|
23
|
+
isEmpty() {
|
|
24
24
|
return this.start === this.end;
|
|
25
|
-
}
|
|
26
|
-
|
|
25
|
+
}
|
|
26
|
+
getLength() {
|
|
27
27
|
return this.end - this.start;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
31
30
|
exports.StringRange = StringRange;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuggestionContext = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class SuggestionContext {
|
|
5
|
+
constructor(parent, startPos) {
|
|
6
6
|
this.parent = parent;
|
|
7
7
|
this.startPos = startPos;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
}());
|
|
9
|
+
}
|
|
11
10
|
exports.SuggestionContext = SuggestionContext;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CommandSyntaxError, StringReader } from "..";
|
|
1
|
+
import { CommandSyntaxError, type StringReader } from "..";
|
|
2
2
|
type CommandErrorFunction = (...args: any[]) => string;
|
|
3
3
|
export declare class CommandErrorType {
|
|
4
4
|
private func;
|
|
5
5
|
constructor(func: CommandErrorFunction);
|
|
6
|
-
create(...args:
|
|
7
|
-
createWithContext(reader: StringReader, ...args:
|
|
6
|
+
create(...args: unknown[]): CommandSyntaxError;
|
|
7
|
+
createWithContext(reader: StringReader, ...args: unknown[]): CommandSyntaxError;
|
|
8
8
|
}
|
|
9
9
|
export {};
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandErrorType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class CommandErrorType {
|
|
6
|
+
constructor(func) {
|
|
7
7
|
this.func = func;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
-
args[_i] = arguments[_i];
|
|
13
|
-
}
|
|
14
|
-
var message = this.func.apply(this, args);
|
|
9
|
+
create(...args) {
|
|
10
|
+
const message = this.func(...args);
|
|
15
11
|
return new __1.CommandSyntaxError(message);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
20
|
-
args[_i - 1] = arguments[_i];
|
|
21
|
-
}
|
|
22
|
-
var message = this.func.apply(this, args);
|
|
12
|
+
}
|
|
13
|
+
createWithContext(reader, ...args) {
|
|
14
|
+
const message = this.func(...args);
|
|
23
15
|
return new __1.CommandSyntaxError(message, reader.getString(), reader.getCursor());
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
27
18
|
exports.CommandErrorType = CommandErrorType;
|
|
@@ -1,61 +1,43 @@
|
|
|
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.CommandSyntaxError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_this.cursor = cursor;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const CONTEXT_AMOUNT = 10;
|
|
6
|
+
class CommandSyntaxError extends Error {
|
|
7
|
+
constructor(message, input, cursor) {
|
|
8
|
+
super(message);
|
|
9
|
+
Object.setPrototypeOf(this, CommandSyntaxError.prototype);
|
|
10
|
+
this.input = input;
|
|
11
|
+
this.cursor = cursor;
|
|
28
12
|
if (input && cursor >= 0) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
this.message += ` at position ${cursor}: `;
|
|
14
|
+
const cursor2 = Math.min(this.input.length, this.cursor);
|
|
15
|
+
this.message += cursor > CONTEXT_AMOUNT ? "..." : "";
|
|
16
|
+
this.message += this.input.substring(Math.max(0, cursor2 - CONTEXT_AMOUNT), cursor2);
|
|
17
|
+
this.message += "<--[HERE]";
|
|
34
18
|
}
|
|
35
|
-
return _this;
|
|
36
19
|
}
|
|
37
|
-
|
|
38
|
-
CommandSyntaxError.DOUBLE_TOO_BIG = new __1.CommandErrorType(function (found, max) { return "Double must not be more than ".concat(max, ", found ").concat(found); });
|
|
39
|
-
CommandSyntaxError.FLOAT_TOO_SMALL = new __1.CommandErrorType(function (found, min) { return "Float must not be less than ".concat(min, ", found ").concat(found); });
|
|
40
|
-
CommandSyntaxError.FLOAT_TOO_BIG = new __1.CommandErrorType(function (found, max) { return "Float must not be more than ".concat(max, ", found ").concat(found); });
|
|
41
|
-
CommandSyntaxError.INTEGER_TOO_SMALL = new __1.CommandErrorType(function (found, min) { return "Integer must not be less than ".concat(min, ", found ").concat(found); });
|
|
42
|
-
CommandSyntaxError.INTEGER_TOO_BIG = new __1.CommandErrorType(function (found, max) { return "Integer must not be more than ".concat(max, ", found ").concat(found); });
|
|
43
|
-
CommandSyntaxError.LONG_TOO_SMALL = new __1.CommandErrorType(function (found, min) { return "Long must not be less than ".concat(min, ", found ").concat(found); });
|
|
44
|
-
CommandSyntaxError.LONG_TOO_BIG = new __1.CommandErrorType(function (found, max) { return "Long must not be more than ".concat(max, ", found ").concat(found); });
|
|
45
|
-
CommandSyntaxError.LITERAL_INCORRECT = new __1.CommandErrorType(function (expected) { return "Expected literal ".concat(expected); });
|
|
46
|
-
CommandSyntaxError.READER_EXPECTED_START_OF_QUOTE = new __1.CommandErrorType(function () { return "Expected quote to start a string"; });
|
|
47
|
-
CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE = new __1.CommandErrorType(function () { return "Unclosed quoted string"; });
|
|
48
|
-
CommandSyntaxError.READER_INVALID_ESCAPE = new __1.CommandErrorType(function (character) { return "Invalid escape sequence '".concat(character, "' in quoted string"); });
|
|
49
|
-
CommandSyntaxError.READER_INVALID_BOOL = new __1.CommandErrorType(function (value) { return "Invalid bool, expected true or false but found '".concat(value, "'"); });
|
|
50
|
-
CommandSyntaxError.READER_EXPECTED_BOOL = new __1.CommandErrorType(function () { return "Expected bool"; });
|
|
51
|
-
CommandSyntaxError.READER_INVALID_INT = new __1.CommandErrorType(function (value) { return "Invalid integer '".concat(value, "'"); });
|
|
52
|
-
CommandSyntaxError.READER_EXPECTED_INT = new __1.CommandErrorType(function () { return "Expected integer"; });
|
|
53
|
-
CommandSyntaxError.READER_INVALID_FLOAT = new __1.CommandErrorType(function (value) { return "Invalid float '".concat(value, "'"); });
|
|
54
|
-
CommandSyntaxError.READER_EXPECTED_FLOAT = new __1.CommandErrorType(function () { return "Expected float"; });
|
|
55
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND = new __1.CommandErrorType(function () { return "Unknown Command"; });
|
|
56
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT = new __1.CommandErrorType(function () { return "Incorrect argument for command"; });
|
|
57
|
-
CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new __1.CommandErrorType(function () { return "Expected whitespace to end one argument, but found trailing data"; });
|
|
58
|
-
CommandSyntaxError.DISPATCHER_PARSE_ERROR = new __1.CommandErrorType(function (message) { return "Could not parse command: ".concat(message); });
|
|
59
|
-
return CommandSyntaxError;
|
|
60
|
-
}(Error));
|
|
20
|
+
}
|
|
61
21
|
exports.CommandSyntaxError = CommandSyntaxError;
|
|
22
|
+
CommandSyntaxError.DOUBLE_TOO_SMALL = new __1.CommandErrorType((found, min) => `Double must not be less than ${min}, found ${found}`);
|
|
23
|
+
CommandSyntaxError.DOUBLE_TOO_BIG = new __1.CommandErrorType((found, max) => `Double must not be more than ${max}, found ${found}`);
|
|
24
|
+
CommandSyntaxError.FLOAT_TOO_SMALL = new __1.CommandErrorType((found, min) => `Float must not be less than ${min}, found ${found}`);
|
|
25
|
+
CommandSyntaxError.FLOAT_TOO_BIG = new __1.CommandErrorType((found, max) => `Float must not be more than ${max}, found ${found}`);
|
|
26
|
+
CommandSyntaxError.INTEGER_TOO_SMALL = new __1.CommandErrorType((found, min) => `Integer must not be less than ${min}, found ${found}`);
|
|
27
|
+
CommandSyntaxError.INTEGER_TOO_BIG = new __1.CommandErrorType((found, max) => `Integer must not be more than ${max}, found ${found}`);
|
|
28
|
+
CommandSyntaxError.LONG_TOO_SMALL = new __1.CommandErrorType((found, min) => `Long must not be less than ${min}, found ${found}`);
|
|
29
|
+
CommandSyntaxError.LONG_TOO_BIG = new __1.CommandErrorType((found, max) => `Long must not be more than ${max}, found ${found}`);
|
|
30
|
+
CommandSyntaxError.LITERAL_INCORRECT = new __1.CommandErrorType((expected) => `Expected literal ${expected}`);
|
|
31
|
+
CommandSyntaxError.READER_EXPECTED_START_OF_QUOTE = new __1.CommandErrorType(() => `Expected quote to start a string`);
|
|
32
|
+
CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE = new __1.CommandErrorType(() => `Unclosed quoted string`);
|
|
33
|
+
CommandSyntaxError.READER_INVALID_ESCAPE = new __1.CommandErrorType((character) => `Invalid escape sequence '${character}' in quoted string`);
|
|
34
|
+
CommandSyntaxError.READER_INVALID_BOOL = new __1.CommandErrorType((value) => `Invalid bool, expected true or false but found '${value}'`);
|
|
35
|
+
CommandSyntaxError.READER_EXPECTED_BOOL = new __1.CommandErrorType(() => `Expected bool`);
|
|
36
|
+
CommandSyntaxError.READER_INVALID_INT = new __1.CommandErrorType((value) => `Invalid integer '${value}'`);
|
|
37
|
+
CommandSyntaxError.READER_EXPECTED_INT = new __1.CommandErrorType(() => `Expected integer`);
|
|
38
|
+
CommandSyntaxError.READER_INVALID_FLOAT = new __1.CommandErrorType((value) => `Invalid float '${value}'`);
|
|
39
|
+
CommandSyntaxError.READER_EXPECTED_FLOAT = new __1.CommandErrorType(() => `Expected float`);
|
|
40
|
+
CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND = new __1.CommandErrorType(() => `Unknown Command`);
|
|
41
|
+
CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT = new __1.CommandErrorType(() => `Incorrect argument for command`);
|
|
42
|
+
CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new __1.CommandErrorType(() => `Expected whitespace to end one argument, but found trailing data`);
|
|
43
|
+
CommandSyntaxError.DISPATCHER_PARSE_ERROR = new __1.CommandErrorType((message) => `Could not parse command: ${message}`);
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Suggestion = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Suggestion {
|
|
5
|
+
constructor(range, text, tooltip) {
|
|
6
6
|
this.range = range;
|
|
7
7
|
this.text = text;
|
|
8
8
|
this.tooltip = tooltip;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
getRange() {
|
|
11
11
|
return this.range;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
getText() {
|
|
14
14
|
return this.text;
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
getTooltip() {
|
|
17
17
|
return this.tooltip;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (this.range.getStart()
|
|
18
|
+
}
|
|
19
|
+
apply(input) {
|
|
20
|
+
if (this.range.getStart() === 0 && this.range.getEnd() === input.length) {
|
|
21
21
|
return this.text;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
let result = "";
|
|
24
24
|
if (this.range.getStart() > 0) {
|
|
25
25
|
result += input.substring(0, this.range.getStart());
|
|
26
26
|
}
|
|
@@ -29,12 +29,12 @@ var Suggestion = /** @class */ (function () {
|
|
|
29
29
|
result += input.substring(this.range.getEnd());
|
|
30
30
|
}
|
|
31
31
|
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
}
|
|
33
|
+
expand(command, range) {
|
|
34
34
|
if (range === this.range) {
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
let result = "";
|
|
38
38
|
if (range.getStart() < this.range.getStart()) {
|
|
39
39
|
result += command.substring(range.getStart(), this.range.getStart());
|
|
40
40
|
}
|
|
@@ -43,7 +43,6 @@ var Suggestion = /** @class */ (function () {
|
|
|
43
43
|
result += command.substring(this.range.getEnd(), range.getEnd());
|
|
44
44
|
}
|
|
45
45
|
return new Suggestion(range, result, this.tooltip);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
49
48
|
exports.Suggestion = Suggestion;
|
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Suggestions = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class Suggestions {
|
|
6
|
+
constructor(range, suggestions) {
|
|
7
7
|
this.range = range;
|
|
8
8
|
this.suggestions = suggestions;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
getRange() {
|
|
11
11
|
return this.range;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
getList() {
|
|
14
14
|
return this.suggestions;
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
isEmpty() {
|
|
17
17
|
return this.suggestions.length === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
18
|
+
}
|
|
19
|
+
static empty() {
|
|
20
20
|
return Promise.resolve(Suggestions.EMPTY);
|
|
21
|
-
}
|
|
22
|
-
|
|
21
|
+
}
|
|
22
|
+
static merge(command, input) {
|
|
23
23
|
if (input.length === 0) {
|
|
24
24
|
return Suggestions.EMPTY;
|
|
25
25
|
}
|
|
26
26
|
else if (input.length === 1) {
|
|
27
27
|
return input[0];
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
for (
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const texts = new Set();
|
|
30
|
+
for (const suggestions of input) {
|
|
31
|
+
suggestions.getList().forEach((s) => {
|
|
32
|
+
texts.add(s);
|
|
33
|
+
});
|
|
33
34
|
}
|
|
34
35
|
return Suggestions.create(command, Array.from(texts));
|
|
35
|
-
}
|
|
36
|
-
|
|
36
|
+
}
|
|
37
|
+
static create(command, suggestions) {
|
|
37
38
|
if (suggestions.length === 0) {
|
|
38
39
|
return Suggestions.EMPTY;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (
|
|
43
|
-
var suggestion = suggestions_1[_i];
|
|
41
|
+
let start = Infinity;
|
|
42
|
+
let end = -Infinity;
|
|
43
|
+
for (const suggestion of suggestions) {
|
|
44
44
|
start = Math.min(suggestion.getRange().getStart(), start);
|
|
45
45
|
end = Math.max(suggestion.getRange().getEnd(), end);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (
|
|
50
|
-
var suggestion = suggestions_2[_a];
|
|
47
|
+
const range = new __1.StringRange(start, end);
|
|
48
|
+
const texts = [];
|
|
49
|
+
for (const suggestion of suggestions) {
|
|
51
50
|
texts.push(suggestion.expand(command, range));
|
|
52
51
|
}
|
|
53
52
|
return new Suggestions(range, texts.sort());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return Suggestions;
|
|
57
|
-
}());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
58
55
|
exports.Suggestions = Suggestions;
|
|
56
|
+
Suggestions.EMPTY = new Suggestions(__1.StringRange.at(0), []);
|
|
@@ -13,5 +13,5 @@ export declare class SuggestionsBuilder {
|
|
|
13
13
|
suggest(text: string, tooltip?: string): SuggestionsBuilder;
|
|
14
14
|
add(other: SuggestionsBuilder): SuggestionsBuilder;
|
|
15
15
|
createOffset(start: number): SuggestionsBuilder;
|
|
16
|
-
restart(
|
|
16
|
+
restart(): SuggestionsBuilder;
|
|
17
17
|
}
|
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuggestionsBuilder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class SuggestionsBuilder {
|
|
6
|
+
constructor(input, start) {
|
|
7
7
|
this.input = input;
|
|
8
8
|
this.start = start;
|
|
9
9
|
this.remaining = input.substring(start);
|
|
10
10
|
this.result = [];
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
getInput() {
|
|
13
13
|
return this.input;
|
|
14
|
-
}
|
|
15
|
-
|
|
14
|
+
}
|
|
15
|
+
getStart() {
|
|
16
16
|
return this.start;
|
|
17
|
-
}
|
|
18
|
-
|
|
17
|
+
}
|
|
18
|
+
getRemaining() {
|
|
19
19
|
return this.remaining;
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
}
|
|
21
|
+
build() {
|
|
22
22
|
return __1.Suggestions.create(this.input, this.result);
|
|
23
|
-
}
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
buildPromise() {
|
|
25
25
|
return Promise.resolve(this.build());
|
|
26
|
-
}
|
|
27
|
-
|
|
26
|
+
}
|
|
27
|
+
suggest(text, tooltip) {
|
|
28
28
|
if (text === this.remaining) {
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
31
|
this.result.push(new __1.Suggestion(new __1.StringRange(this.start, this.input.length), text, tooltip));
|
|
32
32
|
return this;
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
}
|
|
34
|
+
add(other) {
|
|
35
35
|
this.result.concat(other.result);
|
|
36
36
|
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
37
|
+
}
|
|
38
|
+
createOffset(start) {
|
|
39
39
|
return new SuggestionsBuilder(this.input, start);
|
|
40
|
-
}
|
|
41
|
-
|
|
40
|
+
}
|
|
41
|
+
restart() {
|
|
42
42
|
return new SuggestionsBuilder(this.input, this.start);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
46
45
|
exports.SuggestionsBuilder = SuggestionsBuilder;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArgumentType, CommandNode, StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, Suggestions, SuggestionsBuilder } from
|
|
1
|
+
import { type ArgumentType, CommandNode, type StringReader, type Command, type CommandContext, type CommandContextBuilder, type Predicate, type RedirectModifier, type Suggestions, type SuggestionsBuilder } from "..";
|
|
2
2
|
export declare class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
|
3
3
|
name: string;
|
|
4
4
|
type: ArgumentType<T>;
|
|
@@ -1,49 +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.ArgumentCommandNode = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_this.type = type;
|
|
26
|
-
return _this;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class ArgumentCommandNode extends __1.CommandNode {
|
|
6
|
+
constructor(name, type, command, requirement, redirect, modifier, forks) {
|
|
7
|
+
super(command, requirement, redirect, modifier, forks);
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.type = type;
|
|
27
10
|
}
|
|
28
|
-
|
|
11
|
+
getType() {
|
|
29
12
|
return this.type;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
}
|
|
14
|
+
parse(reader, contextBuilder) {
|
|
15
|
+
const start = reader.getCursor();
|
|
16
|
+
const result = this.type.parse(reader);
|
|
17
|
+
const parsed = new __1.ParsedArgument(start, reader.getCursor(), result);
|
|
35
18
|
contextBuilder.withArgument(this.name, parsed);
|
|
36
19
|
contextBuilder.withNode(this, parsed.getRange());
|
|
37
|
-
}
|
|
38
|
-
|
|
20
|
+
}
|
|
21
|
+
getName() {
|
|
39
22
|
return this.name;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}(__1.CommandNode));
|
|
23
|
+
}
|
|
24
|
+
getUsageText() {
|
|
25
|
+
return `<${this.name}>`;
|
|
26
|
+
}
|
|
27
|
+
listSuggestions(context, builder) {
|
|
28
|
+
return this.type.listSuggestions(context, builder);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
49
31
|
exports.ArgumentCommandNode = ArgumentCommandNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, SuggestionsBuilder, Suggestions } from
|
|
1
|
+
import { type StringReader, type Command, type CommandContext, type CommandContextBuilder, type Predicate, type RedirectModifier, type SuggestionsBuilder, type Suggestions } from "..";
|
|
2
2
|
export declare abstract class CommandNode<S> {
|
|
3
3
|
private children;
|
|
4
4
|
private literals;
|
package/dist/tree/CommandNode.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class CommandNode {
|
|
6
|
+
constructor(command, requirement, redirect, modifier, forks) {
|
|
7
7
|
this.children = new Map();
|
|
8
8
|
this.literals = new Map();
|
|
9
9
|
this.arguments = new Map();
|
|
@@ -13,34 +13,34 @@ var CommandNode = /** @class */ (function () {
|
|
|
13
13
|
this.modifier = modifier;
|
|
14
14
|
this.forks = forks;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
getCommand() {
|
|
17
17
|
return this.command;
|
|
18
|
-
}
|
|
19
|
-
|
|
18
|
+
}
|
|
19
|
+
getChildren() {
|
|
20
20
|
return Array.from(this.children.values());
|
|
21
|
-
}
|
|
22
|
-
|
|
21
|
+
}
|
|
22
|
+
getChild(name) {
|
|
23
23
|
return this.children.get(name);
|
|
24
|
-
}
|
|
25
|
-
|
|
24
|
+
}
|
|
25
|
+
getRedirect() {
|
|
26
26
|
return this.redirect;
|
|
27
|
-
}
|
|
28
|
-
|
|
27
|
+
}
|
|
28
|
+
getRedirectModifier() {
|
|
29
29
|
return this.modifier;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
isFork() {
|
|
32
32
|
return this.forks;
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
}
|
|
34
|
+
canUse(source) {
|
|
35
35
|
return this.requirement(source);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
}
|
|
37
|
+
addChild(node) {
|
|
38
|
+
const child = this.children.get(node.getName());
|
|
39
39
|
if (child != null) {
|
|
40
40
|
if (node.getCommand() != null) {
|
|
41
41
|
child.command = node.getCommand();
|
|
42
42
|
}
|
|
43
|
-
node.getChildren().forEach(
|
|
43
|
+
node.getChildren().forEach((grandChild) => {
|
|
44
44
|
child.addChild(grandChild);
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -53,22 +53,21 @@ var CommandNode = /** @class */ (function () {
|
|
|
53
53
|
this.arguments.set(node.getName(), node);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
}
|
|
57
|
+
getRelevantNodes(input) {
|
|
58
58
|
if (this.literals.size > 0) {
|
|
59
|
-
|
|
60
|
-
while (input.canRead() && input.peek()
|
|
59
|
+
const cursor = input.getCursor();
|
|
60
|
+
while (input.canRead() && input.peek() !== " ") {
|
|
61
61
|
input.skip();
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
const text = input.getString().substring(cursor, input.getCursor());
|
|
64
64
|
input.setCursor(cursor);
|
|
65
|
-
|
|
65
|
+
const literal = this.literals.get(text);
|
|
66
66
|
if (literal != null) {
|
|
67
67
|
return [literal];
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return Array.from(this.arguments.values());
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
74
73
|
exports.CommandNode = CommandNode;
|