@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,10 @@
1
+ import { CommandContextBuilder, StringReader, CommandNode, CommandSyntaxError } from ".";
2
+ export declare class ParseResults<S> {
3
+ private context;
4
+ private reader;
5
+ private errors;
6
+ constructor(context: CommandContextBuilder<S>, reader: StringReader, errors: Map<CommandNode<S>, CommandSyntaxError>);
7
+ getContext(): CommandContextBuilder<S>;
8
+ getReader(): StringReader;
9
+ getErrors(): Map<CommandNode<S>, CommandSyntaxError>;
10
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParseResults = void 0;
4
+ var ParseResults = /** @class */ (function () {
5
+ function ParseResults(context, reader, errors) {
6
+ this.context = context;
7
+ this.reader = reader;
8
+ this.errors = errors;
9
+ }
10
+ ParseResults.prototype.getContext = function () {
11
+ return this.context;
12
+ };
13
+ ParseResults.prototype.getReader = function () {
14
+ return this.reader;
15
+ };
16
+ ParseResults.prototype.getErrors = function () {
17
+ return this.errors;
18
+ };
19
+ return ParseResults;
20
+ }());
21
+ exports.ParseResults = ParseResults;
@@ -0,0 +1 @@
1
+ export type Predicate<S> = (c: S) => Promise<boolean>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ export declare class StringReader {
2
+ private string;
3
+ private cursor;
4
+ constructor(string: string | StringReader);
5
+ getString(): string;
6
+ getCursor(): number;
7
+ setCursor(cursor: number): void;
8
+ getRemainingLength(): number;
9
+ getTotalLength(): number;
10
+ getRead(): string;
11
+ getRemaining(): string;
12
+ canRead(length?: number): boolean;
13
+ peek(offset?: number): string;
14
+ read(): string;
15
+ skip(): void;
16
+ isAllowedNumber(c: string): boolean;
17
+ readInt(): number;
18
+ readLong(): BigInt;
19
+ readFloat(): number;
20
+ isAllowedInUnquotedString(c: string): boolean;
21
+ isQuotedStringStart(c: string): boolean;
22
+ readUnquotedString(): string;
23
+ readStringUntil(terminator: string): string;
24
+ readString(): string;
25
+ readBoolean(): boolean;
26
+ }
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringReader = void 0;
4
+ var CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
5
+ var StringReader = /** @class */ (function () {
6
+ function StringReader(string) {
7
+ if (string instanceof StringReader) {
8
+ this.string = string.getString();
9
+ this.cursor = string.getCursor();
10
+ }
11
+ else {
12
+ this.string = string;
13
+ this.cursor = 0;
14
+ }
15
+ }
16
+ StringReader.prototype.getString = function () {
17
+ return this.string;
18
+ };
19
+ StringReader.prototype.getCursor = function () {
20
+ return this.cursor;
21
+ };
22
+ StringReader.prototype.setCursor = function (cursor) {
23
+ this.cursor = cursor;
24
+ };
25
+ StringReader.prototype.getRemainingLength = function () {
26
+ return this.string.length - this.cursor;
27
+ };
28
+ StringReader.prototype.getTotalLength = function () {
29
+ return this.string.length;
30
+ };
31
+ StringReader.prototype.getRead = function () {
32
+ return this.string.substring(0, this.cursor);
33
+ };
34
+ StringReader.prototype.getRemaining = function () {
35
+ return this.string.substring(this.cursor);
36
+ };
37
+ StringReader.prototype.canRead = function (length) {
38
+ if (length === void 0) { length = 1; }
39
+ return this.cursor + length <= this.string.length;
40
+ };
41
+ StringReader.prototype.peek = function (offset) {
42
+ if (offset === void 0) { offset = 0; }
43
+ return this.string.charAt(this.cursor + offset);
44
+ };
45
+ StringReader.prototype.read = function () {
46
+ var char = this.string.charAt(this.cursor);
47
+ this.cursor += 1;
48
+ return char;
49
+ };
50
+ StringReader.prototype.skip = function () {
51
+ this.cursor += 1;
52
+ };
53
+ StringReader.prototype.isAllowedNumber = function (c) {
54
+ return c >= "0" && c <= "9" || c === "." || c === "-";
55
+ };
56
+ StringReader.prototype.readInt = function () {
57
+ var start = this.cursor;
58
+ while (this.canRead() && this.isAllowedNumber(this.peek())) {
59
+ this.skip();
60
+ }
61
+ var number = this.string.substring(start, this.cursor);
62
+ if (number.length === 0) {
63
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
64
+ }
65
+ try {
66
+ var value = Number(number);
67
+ if (isNaN(value) || !Number.isInteger(value)) {
68
+ throw new Error();
69
+ }
70
+ return value;
71
+ }
72
+ catch (e) {
73
+ this.cursor = start;
74
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_INT.createWithContext(this, number);
75
+ }
76
+ };
77
+ StringReader.prototype.readLong = function () {
78
+ var start = this.cursor;
79
+ while (this.canRead() && this.isAllowedNumber(this.peek())) {
80
+ this.skip();
81
+ }
82
+ var number = this.string.substring(start, this.cursor);
83
+ if (number.length === 0) {
84
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
85
+ }
86
+ try {
87
+ return BigInt(number);
88
+ }
89
+ catch (e) {
90
+ this.cursor = start;
91
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_INT.createWithContext(this, number);
92
+ }
93
+ };
94
+ StringReader.prototype.readFloat = function () {
95
+ var start = this.cursor;
96
+ while (this.canRead() && this.isAllowedNumber(this.peek())) {
97
+ this.skip();
98
+ }
99
+ var number = this.string.substring(start, this.cursor);
100
+ if (number.length === 0) {
101
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_FLOAT.createWithContext(this);
102
+ }
103
+ try {
104
+ var value = Number(number);
105
+ if (isNaN(value)) {
106
+ throw new Error();
107
+ }
108
+ return value;
109
+ }
110
+ catch (e) {
111
+ this.cursor = start;
112
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_FLOAT.createWithContext(this, number);
113
+ }
114
+ };
115
+ StringReader.prototype.isAllowedInUnquotedString = function (c) {
116
+ return c >= "0" && c <= "9"
117
+ || c >= "A" && c <= "Z"
118
+ || c >= "a" && c <= "z"
119
+ || c == "_" || c == "-"
120
+ || c == "." || c == "+";
121
+ };
122
+ StringReader.prototype.isQuotedStringStart = function (c) {
123
+ return c === "'" || c === "\"";
124
+ };
125
+ StringReader.prototype.readUnquotedString = function () {
126
+ var start = this.cursor;
127
+ while (this.canRead() && this.isAllowedInUnquotedString(this.peek())) {
128
+ this.skip();
129
+ }
130
+ return this.string.substring(start, this.cursor);
131
+ };
132
+ StringReader.prototype.readStringUntil = function (terminator) {
133
+ var result = [];
134
+ var escaped = false;
135
+ while (this.canRead()) {
136
+ var c = this.read();
137
+ if (escaped) {
138
+ if (c === terminator || c === "\\") {
139
+ result.push(c);
140
+ escaped = false;
141
+ }
142
+ else {
143
+ this.setCursor(this.cursor - 1);
144
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_ESCAPE.createWithContext(this, c);
145
+ }
146
+ }
147
+ else if (c === "\\") {
148
+ escaped = true;
149
+ }
150
+ else if (c === terminator) {
151
+ return result.join("");
152
+ }
153
+ else {
154
+ result.push(c);
155
+ }
156
+ }
157
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE.createWithContext(this);
158
+ };
159
+ StringReader.prototype.readString = function () {
160
+ if (!this.canRead()) {
161
+ return "";
162
+ }
163
+ var next = this.peek();
164
+ if (this.isQuotedStringStart(next)) {
165
+ this.skip();
166
+ return this.readStringUntil(next);
167
+ }
168
+ return this.readUnquotedString();
169
+ };
170
+ StringReader.prototype.readBoolean = function () {
171
+ var start = this.cursor;
172
+ var value = this.readUnquotedString();
173
+ if (value.length === 0) {
174
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_BOOL.createWithContext(this);
175
+ }
176
+ if (value === "true") {
177
+ return true;
178
+ }
179
+ else if (value === "false") {
180
+ return false;
181
+ }
182
+ else {
183
+ throw CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_BOOL.createWithContext(this, value);
184
+ }
185
+ };
186
+ return StringReader;
187
+ }());
188
+ exports.StringReader = StringReader;
@@ -0,0 +1,5 @@
1
+ import { StringReader, CommandContext, Suggestions, SuggestionsBuilder } from "..";
2
+ export declare abstract class ArgumentType<T> {
3
+ abstract parse(reader: StringReader): T;
4
+ listSuggestions(context: CommandContext<any>, builder: SuggestionsBuilder): Promise<Suggestions>;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgumentType = void 0;
4
+ var __1 = require("..");
5
+ var ArgumentType = /** @class */ (function () {
6
+ function ArgumentType() {
7
+ }
8
+ ArgumentType.prototype.listSuggestions = function (context, builder) {
9
+ return __1.Suggestions.empty();
10
+ };
11
+ return ArgumentType;
12
+ }());
13
+ exports.ArgumentType = ArgumentType;
@@ -0,0 +1,6 @@
1
+ import { ArgumentType, StringReader, CommandContext, SuggestionsBuilder, Suggestions } from "..";
2
+ export declare class BoolArgumentType extends ArgumentType<boolean> {
3
+ parse(reader: StringReader): boolean;
4
+ listSuggestions(context: CommandContext<any>, builder: SuggestionsBuilder): Promise<Suggestions>;
5
+ }
6
+ export declare function bool(): BoolArgumentType;
@@ -0,0 +1,43 @@
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.BoolArgumentType = void 0;
19
+ exports.bool = bool;
20
+ var __1 = require("..");
21
+ var BoolArgumentType = /** @class */ (function (_super) {
22
+ __extends(BoolArgumentType, _super);
23
+ function BoolArgumentType() {
24
+ return _super !== null && _super.apply(this, arguments) || this;
25
+ }
26
+ BoolArgumentType.prototype.parse = function (reader) {
27
+ return reader.readBoolean();
28
+ };
29
+ BoolArgumentType.prototype.listSuggestions = function (context, builder) {
30
+ if ("true".startsWith(builder.getRemaining().toLowerCase())) {
31
+ builder.suggest("true");
32
+ }
33
+ if ("false".startsWith(builder.getRemaining().toLowerCase())) {
34
+ builder.suggest("false");
35
+ }
36
+ return builder.buildPromise();
37
+ };
38
+ return BoolArgumentType;
39
+ }(__1.ArgumentType));
40
+ exports.BoolArgumentType = BoolArgumentType;
41
+ function bool() {
42
+ return new BoolArgumentType();
43
+ }
@@ -0,0 +1,7 @@
1
+ import { StringReader, NumberArgumentType } from "..";
2
+ export declare class FloatArgumentType extends NumberArgumentType {
3
+ constructor(minimum?: number, maximum?: number);
4
+ readNumber(reader: StringReader): number;
5
+ getTooSmallError(): import("..").CommandErrorType;
6
+ getTooBigError(): import("..").CommandErrorType;
7
+ }
@@ -0,0 +1,38 @@
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.FloatArgumentType = void 0;
19
+ var __1 = require("..");
20
+ var FloatArgumentType = /** @class */ (function (_super) {
21
+ __extends(FloatArgumentType, _super);
22
+ function FloatArgumentType(minimum, maximum) {
23
+ if (minimum === void 0) { minimum = -Infinity; }
24
+ if (maximum === void 0) { maximum = Infinity; }
25
+ return _super.call(this, minimum, maximum) || this;
26
+ }
27
+ FloatArgumentType.prototype.readNumber = function (reader) {
28
+ return reader.readFloat();
29
+ };
30
+ FloatArgumentType.prototype.getTooSmallError = function () {
31
+ return __1.CommandSyntaxError.FLOAT_TOO_SMALL;
32
+ };
33
+ FloatArgumentType.prototype.getTooBigError = function () {
34
+ return __1.CommandSyntaxError.FLOAT_TOO_BIG;
35
+ };
36
+ return FloatArgumentType;
37
+ }(__1.NumberArgumentType));
38
+ exports.FloatArgumentType = FloatArgumentType;
@@ -0,0 +1,7 @@
1
+ import { StringReader, NumberArgumentType } from "..";
2
+ export declare class IntegerArgumentType extends NumberArgumentType {
3
+ constructor(minimum?: number, maximum?: number);
4
+ readNumber(reader: StringReader): number;
5
+ getTooSmallError(): import("..").CommandErrorType;
6
+ getTooBigError(): import("..").CommandErrorType;
7
+ }
@@ -0,0 +1,38 @@
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.IntegerArgumentType = void 0;
19
+ var __1 = require("..");
20
+ var IntegerArgumentType = /** @class */ (function (_super) {
21
+ __extends(IntegerArgumentType, _super);
22
+ function IntegerArgumentType(minimum, maximum) {
23
+ if (minimum === void 0) { minimum = -2147483648; }
24
+ if (maximum === void 0) { maximum = 2147483647; }
25
+ return _super.call(this, minimum, maximum) || this;
26
+ }
27
+ IntegerArgumentType.prototype.readNumber = function (reader) {
28
+ return reader.readInt();
29
+ };
30
+ IntegerArgumentType.prototype.getTooSmallError = function () {
31
+ return __1.CommandSyntaxError.INTEGER_TOO_SMALL;
32
+ };
33
+ IntegerArgumentType.prototype.getTooBigError = function () {
34
+ return __1.CommandSyntaxError.INTEGER_TOO_BIG;
35
+ };
36
+ return IntegerArgumentType;
37
+ }(__1.NumberArgumentType));
38
+ exports.IntegerArgumentType = IntegerArgumentType;
@@ -0,0 +1,9 @@
1
+ import { StringReader, NumberArgumentType } from "..";
2
+ export declare class LongArgumentType extends NumberArgumentType<BigInt> {
3
+ private static readonly MIN;
4
+ private static readonly MAX;
5
+ constructor(minimum?: bigint, maximum?: bigint);
6
+ readNumber(reader: StringReader): BigInt;
7
+ getTooSmallError(): import("..").CommandErrorType;
8
+ getTooBigError(): import("..").CommandErrorType;
9
+ }
@@ -0,0 +1,40 @@
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.LongArgumentType = void 0;
19
+ var __1 = require("..");
20
+ var LongArgumentType = /** @class */ (function (_super) {
21
+ __extends(LongArgumentType, _super);
22
+ function LongArgumentType(minimum, maximum) {
23
+ if (minimum === void 0) { minimum = LongArgumentType.MIN; }
24
+ if (maximum === void 0) { maximum = LongArgumentType.MAX; }
25
+ return _super.call(this, minimum, maximum) || this;
26
+ }
27
+ LongArgumentType.prototype.readNumber = function (reader) {
28
+ return reader.readLong();
29
+ };
30
+ LongArgumentType.prototype.getTooSmallError = function () {
31
+ return __1.CommandSyntaxError.LONG_TOO_SMALL;
32
+ };
33
+ LongArgumentType.prototype.getTooBigError = function () {
34
+ return __1.CommandSyntaxError.LONG_TOO_BIG;
35
+ };
36
+ LongArgumentType.MIN = BigInt("-9223372036854775808");
37
+ LongArgumentType.MAX = BigInt("9223372036854775807");
38
+ return LongArgumentType;
39
+ }(__1.NumberArgumentType));
40
+ exports.LongArgumentType = LongArgumentType;
@@ -0,0 +1,12 @@
1
+ import { ArgumentType, StringReader, CommandErrorType } from "..";
2
+ export declare abstract class NumberArgumentType<N extends number | BigInt = number> extends ArgumentType<N> {
3
+ private minimum;
4
+ private maximum;
5
+ constructor(minimum: N, maximum: N);
6
+ getMinimum(): N;
7
+ getMaximum(): N;
8
+ parse(reader: StringReader): N;
9
+ abstract readNumber(reader: StringReader): N;
10
+ abstract getTooSmallError(): CommandErrorType;
11
+ abstract getTooBigError(): CommandErrorType;
12
+ }
@@ -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.NumberArgumentType = void 0;
19
+ var __1 = require("..");
20
+ var NumberArgumentType = /** @class */ (function (_super) {
21
+ __extends(NumberArgumentType, _super);
22
+ function NumberArgumentType(minimum, maximum) {
23
+ var _this = _super.call(this) || this;
24
+ _this.minimum = minimum;
25
+ _this.maximum = maximum;
26
+ return _this;
27
+ }
28
+ NumberArgumentType.prototype.getMinimum = function () {
29
+ return this.minimum;
30
+ };
31
+ NumberArgumentType.prototype.getMaximum = function () {
32
+ return this.maximum;
33
+ };
34
+ NumberArgumentType.prototype.parse = function (reader) {
35
+ var start = reader.getCursor();
36
+ var result = this.readNumber(reader);
37
+ if (result < this.minimum) {
38
+ reader.setCursor(start);
39
+ throw this.getTooSmallError().createWithContext(reader, result, this.minimum);
40
+ }
41
+ else if (result > this.maximum) {
42
+ reader.setCursor(start);
43
+ throw this.getTooBigError().createWithContext(reader, result, this.maximum);
44
+ }
45
+ return result;
46
+ };
47
+ return NumberArgumentType;
48
+ }(__1.ArgumentType));
49
+ exports.NumberArgumentType = NumberArgumentType;
@@ -0,0 +1,12 @@
1
+ import { ArgumentType, StringReader } from "..";
2
+ type StringType = "single_word" | "quotable_phrase" | "greedy_phrase";
3
+ export declare class StringArgumentType extends ArgumentType<string> {
4
+ private type;
5
+ constructor(type: StringType);
6
+ getType(): StringType;
7
+ parse(reader: StringReader): string;
8
+ }
9
+ export declare function word(): StringArgumentType;
10
+ export declare function string(): StringArgumentType;
11
+ export declare function greedyString(): StringArgumentType;
12
+ export {};
@@ -0,0 +1,57 @@
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.StringArgumentType = void 0;
19
+ exports.word = word;
20
+ exports.string = string;
21
+ exports.greedyString = greedyString;
22
+ var __1 = require("..");
23
+ var StringArgumentType = /** @class */ (function (_super) {
24
+ __extends(StringArgumentType, _super);
25
+ function StringArgumentType(type) {
26
+ var _this = _super.call(this) || this;
27
+ _this.type = type;
28
+ return _this;
29
+ }
30
+ StringArgumentType.prototype.getType = function () {
31
+ return this.type;
32
+ };
33
+ StringArgumentType.prototype.parse = function (reader) {
34
+ if (this.type === "greedy_phrase") {
35
+ var text = reader.getRemaining();
36
+ reader.setCursor(reader.getTotalLength());
37
+ return text;
38
+ }
39
+ else if (this.type === "single_word") {
40
+ return reader.readUnquotedString();
41
+ }
42
+ else {
43
+ return reader.readString();
44
+ }
45
+ };
46
+ return StringArgumentType;
47
+ }(__1.ArgumentType));
48
+ exports.StringArgumentType = StringArgumentType;
49
+ function word() {
50
+ return new StringArgumentType("single_word");
51
+ }
52
+ function string() {
53
+ return new StringArgumentType("quotable_phrase");
54
+ }
55
+ function greedyString() {
56
+ return new StringArgumentType("greedy_phrase");
57
+ }
@@ -0,0 +1,25 @@
1
+ import { CommandNode, Command, Predicate, CommandContext } from "..";
2
+ export type RedirectModifier<S> = (context: CommandContext<S>) => S | S[];
3
+ export declare abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
4
+ private arguments;
5
+ private command;
6
+ private requirement;
7
+ private target;
8
+ private modifier;
9
+ private forks;
10
+ constructor();
11
+ abstract getThis(): T;
12
+ then(argument: ArgumentBuilder<S, any> | CommandNode<S>): T;
13
+ executes(command: Command<S>): T;
14
+ requires(requirement: Predicate<S>): T;
15
+ redirect(target: CommandNode<S>, modifier?: RedirectModifier<S>): T;
16
+ fork(target: CommandNode<S>, modifier: RedirectModifier<S>): T;
17
+ forward(target: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean): T;
18
+ getArguments(): CommandNode<S>[];
19
+ getCommand(): Command<S>;
20
+ getRequirement(): Predicate<S>;
21
+ getRedirect(): CommandNode<S>;
22
+ getRedirectModifier(): RedirectModifier<S>;
23
+ isFork(): boolean;
24
+ abstract build(): CommandNode<S>;
25
+ }