@wq2/brigadier-ts 1.0.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.
Files changed (104) hide show
  1. package/.github/workflows/publish.yml +49 -0
  2. package/.github/workflows/test.yml +23 -0
  3. package/LICENSE +21 -0
  4. package/README.md +131 -0
  5. package/dist/Command.d.ts +2 -0
  6. package/dist/Command.js +2 -0
  7. package/dist/CommandDispatcher.d.ts +20 -0
  8. package/dist/CommandDispatcher.js +416 -0
  9. package/dist/ParseResults.d.ts +10 -0
  10. package/dist/ParseResults.js +21 -0
  11. package/dist/Predicate.d.ts +1 -0
  12. package/dist/Predicate.js +2 -0
  13. package/dist/StringReader.d.ts +26 -0
  14. package/dist/StringReader.js +188 -0
  15. package/dist/arguments/ArgumentType.d.ts +5 -0
  16. package/dist/arguments/ArgumentType.js +13 -0
  17. package/dist/arguments/BoolArgumentType.d.ts +6 -0
  18. package/dist/arguments/BoolArgumentType.js +43 -0
  19. package/dist/arguments/FloatArgumentType.d.ts +7 -0
  20. package/dist/arguments/FloatArgumentType.js +38 -0
  21. package/dist/arguments/IntegerArgumentType.d.ts +7 -0
  22. package/dist/arguments/IntegerArgumentType.js +38 -0
  23. package/dist/arguments/LongArgumentType.d.ts +9 -0
  24. package/dist/arguments/LongArgumentType.js +40 -0
  25. package/dist/arguments/NumberArgumentType.d.ts +12 -0
  26. package/dist/arguments/NumberArgumentType.js +49 -0
  27. package/dist/arguments/StringArgumentType.d.ts +12 -0
  28. package/dist/arguments/StringArgumentType.js +57 -0
  29. package/dist/builder/ArgumentBuilder.d.ts +25 -0
  30. package/dist/builder/ArgumentBuilder.js +95 -0
  31. package/dist/builder/LiteralArgumentBuilder.d.ts +9 -0
  32. package/dist/builder/LiteralArgumentBuilder.js +47 -0
  33. package/dist/builder/RequiredArgumentBuilder.d.ts +11 -0
  34. package/dist/builder/RequiredArgumentBuilder.js +51 -0
  35. package/dist/context/CommandContext.d.ts +27 -0
  36. package/dist/context/CommandContext.js +67 -0
  37. package/dist/context/CommandContextBuilder.d.ts +31 -0
  38. package/dist/context/CommandContextBuilder.js +118 -0
  39. package/dist/context/ParsedArgument.d.ts +8 -0
  40. package/dist/context/ParsedArgument.js +18 -0
  41. package/dist/context/ParsedCommandNode.d.ts +8 -0
  42. package/dist/context/ParsedCommandNode.js +17 -0
  43. package/dist/context/StringRange.d.ts +11 -0
  44. package/dist/context/StringRange.js +31 -0
  45. package/dist/context/SuggestionContext.d.ts +6 -0
  46. package/dist/context/SuggestionContext.js +11 -0
  47. package/dist/exceptions/CommandErrorType.d.ts +9 -0
  48. package/dist/exceptions/CommandErrorType.js +27 -0
  49. package/dist/exceptions/CommandSyntaxError.d.ts +28 -0
  50. package/dist/exceptions/CommandSyntaxError.js +61 -0
  51. package/dist/index.d.ts +30 -0
  52. package/dist/index.js +46 -0
  53. package/dist/suggestion/Suggestion.d.ts +12 -0
  54. package/dist/suggestion/Suggestion.js +49 -0
  55. package/dist/suggestion/Suggestions.d.ts +13 -0
  56. package/dist/suggestion/Suggestions.js +58 -0
  57. package/dist/suggestion/SuggestionsBuilder.d.ts +17 -0
  58. package/dist/suggestion/SuggestionsBuilder.js +46 -0
  59. package/dist/tree/ArgumentCommandNode.d.ts +11 -0
  60. package/dist/tree/ArgumentCommandNode.js +49 -0
  61. package/dist/tree/CommandNode.d.ts +25 -0
  62. package/dist/tree/CommandNode.js +74 -0
  63. package/dist/tree/LiteralCommandNode.d.ts +10 -0
  64. package/dist/tree/LiteralCommandNode.js +68 -0
  65. package/dist/tree/RootCommandNode.d.ts +8 -0
  66. package/dist/tree/RootCommandNode.js +77 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/jest.config.js +12 -0
  69. package/package.json +34 -0
  70. package/src/Command.ts +3 -0
  71. package/src/CommandDispatcher.ts +300 -0
  72. package/src/ParseResults.ts +30 -0
  73. package/src/Predicate.ts +1 -0
  74. package/src/StringReader.ts +197 -0
  75. package/src/arguments/ArgumentType.ts +14 -0
  76. package/src/arguments/BoolArgumentType.ts +28 -0
  77. package/src/arguments/FloatArgumentType.ts +20 -0
  78. package/src/arguments/IntegerArgumentType.ts +20 -0
  79. package/src/arguments/LongArgumentType.ts +23 -0
  80. package/src/arguments/NumberArgumentType.ts +39 -0
  81. package/src/arguments/StringArgumentType.ts +40 -0
  82. package/src/builder/ArgumentBuilder.ts +82 -0
  83. package/src/builder/LiteralArgumentBuilder.ts +30 -0
  84. package/src/builder/RequiredArgumentBuilder.ts +40 -0
  85. package/src/context/CommandContext.ts +94 -0
  86. package/src/context/CommandContextBuilder.ts +148 -0
  87. package/src/context/ParsedArgument.ts +19 -0
  88. package/src/context/ParsedCommandNode.ts +19 -0
  89. package/src/context/StringRange.ts +35 -0
  90. package/src/context/SuggestionContext.ts +11 -0
  91. package/src/exceptions/CommandErrorType.ts +20 -0
  92. package/src/exceptions/CommandSyntaxError.ts +48 -0
  93. package/src/index.ts +30 -0
  94. package/src/suggestion/Suggestion.ts +55 -0
  95. package/src/suggestion/Suggestions.ts +60 -0
  96. package/src/suggestion/SuggestionsBuilder.ts +60 -0
  97. package/src/tree/ArgumentCommandNode.ts +48 -0
  98. package/src/tree/CommandNode.ts +105 -0
  99. package/src/tree/LiteralCommandNode.ts +64 -0
  100. package/src/tree/RootCommandNode.ts +30 -0
  101. package/test/Arguments.test.ts +36 -0
  102. package/test/CommandDispatcher.test.ts +25 -0
  103. package/test/StringReader.test.ts +47 -0
  104. package/tsconfig.json +16 -0
@@ -0,0 +1,61 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CommandSyntaxError = void 0;
19
+ var __1 = require("..");
20
+ var CONTEXT_AMOUNT = 10;
21
+ var CommandSyntaxError = /** @class */ (function (_super) {
22
+ __extends(CommandSyntaxError, _super);
23
+ function CommandSyntaxError(message, input, cursor) {
24
+ var _this = _super.call(this, message) || this;
25
+ Object.setPrototypeOf(_this, CommandSyntaxError.prototype);
26
+ _this.input = input;
27
+ _this.cursor = cursor;
28
+ if (input && cursor >= 0) {
29
+ _this.message += " at position ".concat(cursor, ": ");
30
+ var cursor2 = Math.min(_this.input.length, _this.cursor);
31
+ _this.message += cursor > CONTEXT_AMOUNT ? "..." : "";
32
+ _this.message += _this.input.substring(Math.max(0, cursor2 - CONTEXT_AMOUNT), cursor2);
33
+ _this.message += "<--[HERE]";
34
+ }
35
+ return _this;
36
+ }
37
+ CommandSyntaxError.DOUBLE_TOO_SMALL = new __1.CommandErrorType(function (found, min) { return "Double must not be less than ".concat(min, ", found ").concat(found); });
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));
61
+ exports.CommandSyntaxError = CommandSyntaxError;
@@ -0,0 +1,30 @@
1
+ export * from "./Command";
2
+ export * from "./Predicate";
3
+ export * from "./context/StringRange";
4
+ export * from "./exceptions/CommandErrorType";
5
+ export * from "./exceptions/CommandSyntaxError";
6
+ export * from "./StringReader";
7
+ export * from "./suggestion/Suggestion";
8
+ export * from "./suggestion/Suggestions";
9
+ export * from "./suggestion/SuggestionsBuilder";
10
+ export * from "./tree/CommandNode";
11
+ export * from "./tree/LiteralCommandNode";
12
+ export * from "./tree/ArgumentCommandNode";
13
+ export * from "./tree/RootCommandNode";
14
+ export * from "./arguments/ArgumentType";
15
+ export * from "./arguments/NumberArgumentType";
16
+ export * from "./arguments/FloatArgumentType";
17
+ export * from "./arguments/IntegerArgumentType";
18
+ export * from "./arguments/LongArgumentType";
19
+ export * from "./arguments/BoolArgumentType";
20
+ export * from "./arguments/StringArgumentType";
21
+ export * from "./builder/ArgumentBuilder";
22
+ export * from "./builder/LiteralArgumentBuilder";
23
+ export * from "./builder/RequiredArgumentBuilder";
24
+ export * from "./context/ParsedArgument";
25
+ export * from "./context/ParsedCommandNode";
26
+ export * from "./context/CommandContext";
27
+ export * from "./context/CommandContextBuilder";
28
+ export * from "./context/SuggestionContext";
29
+ export * from "./ParseResults";
30
+ export * from "./CommandDispatcher";
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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("./Predicate"), exports);
19
+ __exportStar(require("./context/StringRange"), exports);
20
+ __exportStar(require("./exceptions/CommandErrorType"), exports);
21
+ __exportStar(require("./exceptions/CommandSyntaxError"), exports);
22
+ __exportStar(require("./StringReader"), exports);
23
+ __exportStar(require("./suggestion/Suggestion"), exports);
24
+ __exportStar(require("./suggestion/Suggestions"), exports);
25
+ __exportStar(require("./suggestion/SuggestionsBuilder"), exports);
26
+ __exportStar(require("./tree/CommandNode"), exports);
27
+ __exportStar(require("./tree/LiteralCommandNode"), exports);
28
+ __exportStar(require("./tree/ArgumentCommandNode"), exports);
29
+ __exportStar(require("./tree/RootCommandNode"), exports);
30
+ __exportStar(require("./arguments/ArgumentType"), exports);
31
+ __exportStar(require("./arguments/NumberArgumentType"), exports);
32
+ __exportStar(require("./arguments/FloatArgumentType"), exports);
33
+ __exportStar(require("./arguments/IntegerArgumentType"), exports);
34
+ __exportStar(require("./arguments/LongArgumentType"), exports);
35
+ __exportStar(require("./arguments/BoolArgumentType"), exports);
36
+ __exportStar(require("./arguments/StringArgumentType"), exports);
37
+ __exportStar(require("./builder/ArgumentBuilder"), exports);
38
+ __exportStar(require("./builder/LiteralArgumentBuilder"), exports);
39
+ __exportStar(require("./builder/RequiredArgumentBuilder"), exports);
40
+ __exportStar(require("./context/ParsedArgument"), exports);
41
+ __exportStar(require("./context/ParsedCommandNode"), exports);
42
+ __exportStar(require("./context/CommandContext"), exports);
43
+ __exportStar(require("./context/CommandContextBuilder"), exports);
44
+ __exportStar(require("./context/SuggestionContext"), exports);
45
+ __exportStar(require("./ParseResults"), exports);
46
+ __exportStar(require("./CommandDispatcher"), exports);
@@ -0,0 +1,12 @@
1
+ import { StringRange } from "..";
2
+ export declare class Suggestion {
3
+ private range;
4
+ private text;
5
+ private tooltip;
6
+ constructor(range: StringRange, text: string, tooltip?: string);
7
+ getRange(): StringRange;
8
+ getText(): string;
9
+ getTooltip(): string;
10
+ apply(input: string): string;
11
+ expand(command: string, range: StringRange): Suggestion;
12
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Suggestion = void 0;
4
+ var Suggestion = /** @class */ (function () {
5
+ function Suggestion(range, text, tooltip) {
6
+ this.range = range;
7
+ this.text = text;
8
+ this.tooltip = tooltip;
9
+ }
10
+ Suggestion.prototype.getRange = function () {
11
+ return this.range;
12
+ };
13
+ Suggestion.prototype.getText = function () {
14
+ return this.text;
15
+ };
16
+ Suggestion.prototype.getTooltip = function () {
17
+ return this.tooltip;
18
+ };
19
+ Suggestion.prototype.apply = function (input) {
20
+ if (this.range.getStart() == 0 && this.range.getEnd() === input.length) {
21
+ return this.text;
22
+ }
23
+ var result = "";
24
+ if (this.range.getStart() > 0) {
25
+ result += input.substring(0, this.range.getStart());
26
+ }
27
+ result += this.text;
28
+ if (this.range.getEnd() < input.length) {
29
+ result += input.substring(this.range.getEnd());
30
+ }
31
+ return result;
32
+ };
33
+ Suggestion.prototype.expand = function (command, range) {
34
+ if (range === this.range) {
35
+ return this;
36
+ }
37
+ var result = "";
38
+ if (range.getStart() < this.range.getStart()) {
39
+ result += command.substring(range.getStart(), this.range.getStart());
40
+ }
41
+ result += this.text;
42
+ if (range.getEnd() > this.range.getEnd()) {
43
+ result += command.substring(this.range.getEnd(), range.getEnd());
44
+ }
45
+ return new Suggestion(range, result, this.tooltip);
46
+ };
47
+ return Suggestion;
48
+ }());
49
+ exports.Suggestion = Suggestion;
@@ -0,0 +1,13 @@
1
+ import { StringRange, Suggestion } from "..";
2
+ export declare class Suggestions {
3
+ static EMPTY: Suggestions;
4
+ private range;
5
+ private suggestions;
6
+ constructor(range: StringRange, suggestions: Suggestion[]);
7
+ getRange(): StringRange;
8
+ getList(): Suggestion[];
9
+ isEmpty(): boolean;
10
+ static empty(): Promise<Suggestions>;
11
+ static merge(command: string, input: Suggestions[]): Suggestions;
12
+ static create(command: string, suggestions: Suggestion[]): Suggestions;
13
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Suggestions = void 0;
4
+ var __1 = require("..");
5
+ var Suggestions = /** @class */ (function () {
6
+ function Suggestions(range, suggestions) {
7
+ this.range = range;
8
+ this.suggestions = suggestions;
9
+ }
10
+ Suggestions.prototype.getRange = function () {
11
+ return this.range;
12
+ };
13
+ Suggestions.prototype.getList = function () {
14
+ return this.suggestions;
15
+ };
16
+ Suggestions.prototype.isEmpty = function () {
17
+ return this.suggestions.length === 0;
18
+ };
19
+ Suggestions.empty = function () {
20
+ return Promise.resolve(Suggestions.EMPTY);
21
+ };
22
+ Suggestions.merge = function (command, input) {
23
+ if (input.length === 0) {
24
+ return Suggestions.EMPTY;
25
+ }
26
+ else if (input.length === 1) {
27
+ return input[0];
28
+ }
29
+ var texts = new Set();
30
+ for (var _i = 0, input_1 = input; _i < input_1.length; _i++) {
31
+ var suggestions = input_1[_i];
32
+ suggestions.getList().forEach(function (s) { return texts.add(s); });
33
+ }
34
+ return Suggestions.create(command, Array.from(texts));
35
+ };
36
+ Suggestions.create = function (command, suggestions) {
37
+ if (suggestions.length === 0) {
38
+ return Suggestions.EMPTY;
39
+ }
40
+ var start = Infinity;
41
+ var end = -Infinity;
42
+ for (var _i = 0, suggestions_1 = suggestions; _i < suggestions_1.length; _i++) {
43
+ var suggestion = suggestions_1[_i];
44
+ start = Math.min(suggestion.getRange().getStart(), start);
45
+ end = Math.max(suggestion.getRange().getEnd(), end);
46
+ }
47
+ var range = new __1.StringRange(start, end);
48
+ var texts = [];
49
+ for (var _a = 0, suggestions_2 = suggestions; _a < suggestions_2.length; _a++) {
50
+ var suggestion = suggestions_2[_a];
51
+ texts.push(suggestion.expand(command, range));
52
+ }
53
+ return new Suggestions(range, texts.sort());
54
+ };
55
+ Suggestions.EMPTY = new Suggestions(__1.StringRange.at(0), []);
56
+ return Suggestions;
57
+ }());
58
+ exports.Suggestions = Suggestions;
@@ -0,0 +1,17 @@
1
+ import { Suggestions } from "..";
2
+ export declare class SuggestionsBuilder {
3
+ private input;
4
+ private start;
5
+ private remaining;
6
+ private result;
7
+ constructor(input: string, start: number);
8
+ getInput(): string;
9
+ getStart(): number;
10
+ getRemaining(): string;
11
+ build(): Suggestions;
12
+ buildPromise(): Promise<Suggestions>;
13
+ suggest(text: string, tooltip?: string): SuggestionsBuilder;
14
+ add(other: SuggestionsBuilder): SuggestionsBuilder;
15
+ createOffset(start: number): SuggestionsBuilder;
16
+ restart(start: number): SuggestionsBuilder;
17
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SuggestionsBuilder = void 0;
4
+ var __1 = require("..");
5
+ var SuggestionsBuilder = /** @class */ (function () {
6
+ function SuggestionsBuilder(input, start) {
7
+ this.input = input;
8
+ this.start = start;
9
+ this.remaining = input.substring(start);
10
+ this.result = [];
11
+ }
12
+ SuggestionsBuilder.prototype.getInput = function () {
13
+ return this.input;
14
+ };
15
+ SuggestionsBuilder.prototype.getStart = function () {
16
+ return this.start;
17
+ };
18
+ SuggestionsBuilder.prototype.getRemaining = function () {
19
+ return this.remaining;
20
+ };
21
+ SuggestionsBuilder.prototype.build = function () {
22
+ return __1.Suggestions.create(this.input, this.result);
23
+ };
24
+ SuggestionsBuilder.prototype.buildPromise = function () {
25
+ return Promise.resolve(this.build());
26
+ };
27
+ SuggestionsBuilder.prototype.suggest = function (text, tooltip) {
28
+ if (text === this.remaining) {
29
+ return this;
30
+ }
31
+ this.result.push(new __1.Suggestion(new __1.StringRange(this.start, this.input.length), text, tooltip));
32
+ return this;
33
+ };
34
+ SuggestionsBuilder.prototype.add = function (other) {
35
+ this.result.concat(other.result);
36
+ return this;
37
+ };
38
+ SuggestionsBuilder.prototype.createOffset = function (start) {
39
+ return new SuggestionsBuilder(this.input, start);
40
+ };
41
+ SuggestionsBuilder.prototype.restart = function (start) {
42
+ return new SuggestionsBuilder(this.input, this.start);
43
+ };
44
+ return SuggestionsBuilder;
45
+ }());
46
+ exports.SuggestionsBuilder = SuggestionsBuilder;
@@ -0,0 +1,11 @@
1
+ import { ArgumentType, CommandNode, StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, Suggestions, SuggestionsBuilder } from '..';
2
+ export declare class ArgumentCommandNode<S, T> extends CommandNode<S> {
3
+ name: string;
4
+ type: ArgumentType<T>;
5
+ constructor(name: string, type: ArgumentType<T>, command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
6
+ getType(): ArgumentType<T>;
7
+ parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
8
+ getName(): string;
9
+ getUsageText(): string;
10
+ listSuggestions(context: CommandContext<S>, builder: SuggestionsBuilder): Promise<Suggestions>;
11
+ }
@@ -0,0 +1,49 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ArgumentCommandNode = void 0;
19
+ var __1 = require("..");
20
+ var ArgumentCommandNode = /** @class */ (function (_super) {
21
+ __extends(ArgumentCommandNode, _super);
22
+ function ArgumentCommandNode(name, type, command, requirement, redirect, modifier, forks) {
23
+ var _this = _super.call(this, command, requirement, redirect, modifier, forks) || this;
24
+ _this.name = name;
25
+ _this.type = type;
26
+ return _this;
27
+ }
28
+ ArgumentCommandNode.prototype.getType = function () {
29
+ return this.type;
30
+ };
31
+ ArgumentCommandNode.prototype.parse = function (reader, contextBuilder) {
32
+ var start = reader.getCursor();
33
+ var result = this.type.parse(reader);
34
+ var parsed = new __1.ParsedArgument(start, reader.getCursor(), result);
35
+ contextBuilder.withArgument(this.name, parsed);
36
+ contextBuilder.withNode(this, parsed.getRange());
37
+ };
38
+ ArgumentCommandNode.prototype.getName = function () {
39
+ return this.name;
40
+ };
41
+ ArgumentCommandNode.prototype.getUsageText = function () {
42
+ return "<" + this.name + ">";
43
+ };
44
+ ArgumentCommandNode.prototype.listSuggestions = function (context, builder) {
45
+ return __1.Suggestions.empty();
46
+ };
47
+ return ArgumentCommandNode;
48
+ }(__1.CommandNode));
49
+ exports.ArgumentCommandNode = ArgumentCommandNode;
@@ -0,0 +1,25 @@
1
+ import { StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, SuggestionsBuilder, Suggestions } from '..';
2
+ export declare abstract class CommandNode<S> {
3
+ private children;
4
+ private literals;
5
+ private arguments;
6
+ private command;
7
+ private requirement;
8
+ private redirect;
9
+ private modifier;
10
+ private forks;
11
+ constructor(command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
12
+ getCommand(): Command<S>;
13
+ getChildren(): CommandNode<S>[];
14
+ getChild(name: string): CommandNode<S>;
15
+ getRedirect(): CommandNode<S>;
16
+ getRedirectModifier(): RedirectModifier<S>;
17
+ isFork(): boolean;
18
+ canUse(source: S): Promise<boolean>;
19
+ addChild(node: CommandNode<S>): void;
20
+ abstract parse(reader: StringReader, context: CommandContextBuilder<S>): void;
21
+ abstract getName(): string;
22
+ abstract getUsageText(): string;
23
+ abstract listSuggestions(context: CommandContext<S>, builder: SuggestionsBuilder): Promise<Suggestions>;
24
+ getRelevantNodes(input: StringReader): CommandNode<S>[];
25
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandNode = void 0;
4
+ var __1 = require("..");
5
+ var CommandNode = /** @class */ (function () {
6
+ function CommandNode(command, requirement, redirect, modifier, forks) {
7
+ this.children = new Map();
8
+ this.literals = new Map();
9
+ this.arguments = new Map();
10
+ this.command = command;
11
+ this.requirement = requirement;
12
+ this.redirect = redirect;
13
+ this.modifier = modifier;
14
+ this.forks = forks;
15
+ }
16
+ CommandNode.prototype.getCommand = function () {
17
+ return this.command;
18
+ };
19
+ CommandNode.prototype.getChildren = function () {
20
+ return Array.from(this.children.values());
21
+ };
22
+ CommandNode.prototype.getChild = function (name) {
23
+ return this.children.get(name);
24
+ };
25
+ CommandNode.prototype.getRedirect = function () {
26
+ return this.redirect;
27
+ };
28
+ CommandNode.prototype.getRedirectModifier = function () {
29
+ return this.modifier;
30
+ };
31
+ CommandNode.prototype.isFork = function () {
32
+ return this.forks;
33
+ };
34
+ CommandNode.prototype.canUse = function (source) {
35
+ return this.requirement(source);
36
+ };
37
+ CommandNode.prototype.addChild = function (node) {
38
+ var child = this.children.get(node.getName());
39
+ if (child != null) {
40
+ if (node.getCommand() != null) {
41
+ child.command = node.getCommand();
42
+ }
43
+ node.getChildren().forEach(function (grandChild) {
44
+ child.addChild(grandChild);
45
+ });
46
+ }
47
+ else {
48
+ this.children.set(node.getName(), node);
49
+ if (node instanceof __1.LiteralCommandNode) {
50
+ this.literals.set(node.getName(), node);
51
+ }
52
+ else if (node instanceof __1.ArgumentCommandNode) {
53
+ this.arguments.set(node.getName(), node);
54
+ }
55
+ }
56
+ };
57
+ CommandNode.prototype.getRelevantNodes = function (input) {
58
+ if (this.literals.size > 0) {
59
+ var cursor = input.getCursor();
60
+ while (input.canRead() && input.peek() != " ") {
61
+ input.skip();
62
+ }
63
+ var text = input.getString().substring(cursor, input.getCursor());
64
+ input.setCursor(cursor);
65
+ var literal = this.literals.get(text);
66
+ if (literal != null) {
67
+ return [literal];
68
+ }
69
+ }
70
+ return Array.from(this.arguments.values());
71
+ };
72
+ return CommandNode;
73
+ }());
74
+ exports.CommandNode = CommandNode;
@@ -0,0 +1,10 @@
1
+ import { CommandNode, StringReader, Command, CommandContext, CommandContextBuilder, Predicate, RedirectModifier, Suggestions, SuggestionsBuilder } from '..';
2
+ export declare class LiteralCommandNode<S> extends CommandNode<S> {
3
+ private literal;
4
+ constructor(literal: string, command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
5
+ parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
6
+ private parseInternal;
7
+ getName(): string;
8
+ getUsageText(): string;
9
+ listSuggestions(context: CommandContext<S>, builder: SuggestionsBuilder): Promise<Suggestions>;
10
+ }
@@ -0,0 +1,68 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.LiteralCommandNode = void 0;
19
+ var __1 = require("..");
20
+ var LiteralCommandNode = /** @class */ (function (_super) {
21
+ __extends(LiteralCommandNode, _super);
22
+ function LiteralCommandNode(literal, command, requirement, redirect, modifier, forks) {
23
+ var _this = _super.call(this, command, requirement, redirect, modifier, forks) || this;
24
+ _this.literal = literal;
25
+ return _this;
26
+ }
27
+ LiteralCommandNode.prototype.parse = function (reader, contextBuilder) {
28
+ var start = reader.getCursor();
29
+ var end = this.parseInternal(reader);
30
+ if (end > -1) {
31
+ contextBuilder.withNode(this, new __1.StringRange(start, end));
32
+ return;
33
+ }
34
+ throw __1.CommandSyntaxError.LITERAL_INCORRECT.createWithContext(reader, this.literal);
35
+ };
36
+ LiteralCommandNode.prototype.parseInternal = function (reader) {
37
+ var start = reader.getCursor();
38
+ if (reader.canRead(this.literal.length)) {
39
+ var end = start + this.literal.length;
40
+ if (reader.getString().substr(start, this.literal.length) === this.literal) {
41
+ reader.setCursor(end);
42
+ if (!reader.canRead() || reader.peek() == " ") {
43
+ return end;
44
+ }
45
+ else {
46
+ reader.setCursor(start);
47
+ }
48
+ }
49
+ }
50
+ return -1;
51
+ };
52
+ LiteralCommandNode.prototype.getName = function () {
53
+ return this.literal;
54
+ };
55
+ LiteralCommandNode.prototype.getUsageText = function () {
56
+ return this.literal;
57
+ };
58
+ LiteralCommandNode.prototype.listSuggestions = function (context, builder) {
59
+ if (this.literal.toLowerCase().startsWith(builder.getRemaining().toLowerCase())) {
60
+ return builder.suggest(this.literal).buildPromise();
61
+ }
62
+ else {
63
+ return __1.Suggestions.empty();
64
+ }
65
+ };
66
+ return LiteralCommandNode;
67
+ }(__1.CommandNode));
68
+ exports.LiteralCommandNode = LiteralCommandNode;
@@ -0,0 +1,8 @@
1
+ import { CommandNode, StringReader, CommandContextBuilder, CommandContext, Suggestions, SuggestionsBuilder } from '..';
2
+ export declare class RootCommandNode<S> extends CommandNode<S> {
3
+ constructor();
4
+ parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
5
+ getName(): string;
6
+ getUsageText(): string;
7
+ listSuggestions(context: CommandContext<S>, builder: SuggestionsBuilder): Promise<Suggestions>;
8
+ }