@wq2/brigadier-ts 1.0.0 → 1.0.2

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 (90) hide show
  1. package/README.md +1 -0
  2. package/dist/Command.d.ts +1 -1
  3. package/dist/CommandDispatcher.d.ts +1 -1
  4. package/dist/CommandDispatcher.js +231 -357
  5. package/dist/ParseResults.d.ts +1 -1
  6. package/dist/ParseResults.js +9 -10
  7. package/dist/StringReader.d.ts +1 -1
  8. package/dist/StringReader.js +75 -77
  9. package/dist/arguments/ArgumentType.d.ts +1 -1
  10. package/dist/arguments/ArgumentType.js +9 -8
  11. package/dist/arguments/BoolArgumentType.d.ts +5 -1
  12. package/dist/arguments/BoolArgumentType.js +9 -27
  13. package/dist/arguments/FloatArgumentType.d.ts +1 -1
  14. package/dist/arguments/FloatArgumentType.js +11 -30
  15. package/dist/arguments/IntegerArgumentType.d.ts +1 -1
  16. package/dist/arguments/IntegerArgumentType.js +11 -30
  17. package/dist/arguments/LongArgumentType.d.ts +3 -3
  18. package/dist/arguments/LongArgumentType.js +13 -32
  19. package/dist/arguments/NumberArgumentType.d.ts +2 -2
  20. package/dist/arguments/NumberArgumentType.js +15 -33
  21. package/dist/arguments/StringArgumentType.d.ts +1 -1
  22. package/dist/arguments/StringArgumentType.js +11 -29
  23. package/dist/builder/ArgumentBuilder.d.ts +1 -1
  24. package/dist/builder/ArgumentBuilder.js +31 -71
  25. package/dist/builder/LiteralArgumentBuilder.js +14 -33
  26. package/dist/builder/RequiredArgumentBuilder.d.ts +1 -1
  27. package/dist/builder/RequiredArgumentBuilder.js +18 -37
  28. package/dist/context/CommandContext.d.ts +1 -1
  29. package/dist/context/CommandContext.js +31 -32
  30. package/dist/context/CommandContextBuilder.d.ts +1 -1
  31. package/dist/context/CommandContextBuilder.js +47 -50
  32. package/dist/context/ParsedArgument.js +8 -9
  33. package/dist/context/ParsedCommandNode.d.ts +1 -1
  34. package/dist/context/ParsedCommandNode.js +7 -8
  35. package/dist/context/StringRange.js +17 -18
  36. package/dist/context/SuggestionContext.d.ts +1 -1
  37. package/dist/context/SuggestionContext.js +3 -4
  38. package/dist/exceptions/CommandErrorType.d.ts +3 -3
  39. package/dist/exceptions/CommandErrorType.js +10 -19
  40. package/dist/exceptions/CommandSyntaxError.js +36 -54
  41. package/dist/suggestion/Suggestion.d.ts +1 -1
  42. package/dist/suggestion/Suggestion.js +16 -17
  43. package/dist/suggestion/Suggestions.d.ts +1 -1
  44. package/dist/suggestion/Suggestions.js +28 -30
  45. package/dist/suggestion/SuggestionsBuilder.d.ts +1 -1
  46. package/dist/suggestion/SuggestionsBuilder.js +22 -23
  47. package/dist/tree/ArgumentCommandNode.d.ts +1 -1
  48. package/dist/tree/ArgumentCommandNode.js +22 -40
  49. package/dist/tree/CommandNode.d.ts +1 -1
  50. package/dist/tree/CommandNode.js +28 -29
  51. package/dist/tree/LiteralCommandNode.d.ts +1 -1
  52. package/dist/tree/LiteralCommandNode.js +28 -41
  53. package/dist/tree/RootCommandNode.d.ts +1 -1
  54. package/dist/tree/RootCommandNode.js +17 -69
  55. package/jest.config.js +5 -5
  56. package/package.json +32 -32
  57. package/src/Command.ts +2 -1
  58. package/src/CommandDispatcher.ts +397 -295
  59. package/src/ParseResults.ts +26 -22
  60. package/src/StringReader.ts +212 -193
  61. package/src/arguments/ArgumentType.ts +13 -8
  62. package/src/arguments/BoolArgumentType.ts +22 -21
  63. package/src/arguments/FloatArgumentType.ts +13 -14
  64. package/src/arguments/IntegerArgumentType.ts +13 -14
  65. package/src/arguments/LongArgumentType.ts +16 -17
  66. package/src/arguments/NumberArgumentType.ts +48 -38
  67. package/src/arguments/StringArgumentType.ts +26 -26
  68. package/src/builder/ArgumentBuilder.ts +80 -75
  69. package/src/builder/LiteralArgumentBuilder.ts +31 -21
  70. package/src/builder/RequiredArgumentBuilder.ts +42 -32
  71. package/src/context/CommandContext.ts +99 -76
  72. package/src/context/CommandContextBuilder.ts +169 -143
  73. package/src/context/ParsedArgument.ts +13 -13
  74. package/src/context/ParsedCommandNode.ts +14 -14
  75. package/src/context/StringRange.ts +26 -26
  76. package/src/context/SuggestionContext.ts +7 -7
  77. package/src/exceptions/CommandErrorType.ts +20 -13
  78. package/src/exceptions/CommandSyntaxError.ts +78 -37
  79. package/src/index.ts +30 -30
  80. package/src/suggestion/Suggestion.ts +46 -46
  81. package/src/suggestion/Suggestions.ts +59 -57
  82. package/src/suggestion/SuggestionsBuilder.ts +59 -57
  83. package/src/tree/ArgumentCommandNode.ts +51 -40
  84. package/src/tree/CommandNode.ts +96 -87
  85. package/src/tree/LiteralCommandNode.ts +78 -57
  86. package/src/tree/RootCommandNode.ts +33 -23
  87. package/test/Arguments.test.ts +47 -33
  88. package/test/CommandDispatcher.test.ts +18 -22
  89. package/test/StringReader.test.ts +47 -47
  90. 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
- var StringRange = /** @class */ (function () {
5
- function StringRange(start, end) {
4
+ class StringRange {
5
+ constructor(start, end) {
6
6
  this.start = start;
7
7
  this.end = end;
8
8
  }
9
- StringRange.at = function (pos) {
9
+ static at(pos) {
10
10
  return new StringRange(pos, pos);
11
- };
12
- StringRange.encompassing = function (a, b) {
13
- var start = Math.min(a.getStart(), b.getStart());
14
- var end = Math.max(a.getEnd(), b.getEnd());
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
- StringRange.prototype.getStart = function () {
16
+ }
17
+ getStart() {
18
18
  return this.start;
19
- };
20
- StringRange.prototype.getEnd = function () {
19
+ }
20
+ getEnd() {
21
21
  return this.end;
22
- };
23
- StringRange.prototype.isEmpty = function () {
22
+ }
23
+ isEmpty() {
24
24
  return this.start === this.end;
25
- };
26
- StringRange.prototype.getLength = function () {
25
+ }
26
+ getLength() {
27
27
  return this.end - this.start;
28
- };
29
- return StringRange;
30
- }());
28
+ }
29
+ }
31
30
  exports.StringRange = StringRange;
@@ -1,4 +1,4 @@
1
- import { CommandNode } from "..";
1
+ import type { CommandNode } from "..";
2
2
  export declare class SuggestionContext<S> {
3
3
  parent: CommandNode<S>;
4
4
  startPos: number;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SuggestionContext = void 0;
4
- var SuggestionContext = /** @class */ (function () {
5
- function SuggestionContext(parent, startPos) {
4
+ class SuggestionContext {
5
+ constructor(parent, startPos) {
6
6
  this.parent = parent;
7
7
  this.startPos = startPos;
8
8
  }
9
- return SuggestionContext;
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: any[]): CommandSyntaxError;
7
- createWithContext(reader: StringReader, ...args: any[]): CommandSyntaxError;
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
- var __1 = require("..");
5
- var CommandErrorType = /** @class */ (function () {
6
- function CommandErrorType(func) {
4
+ const __1 = require("..");
5
+ class CommandErrorType {
6
+ constructor(func) {
7
7
  this.func = func;
8
8
  }
9
- CommandErrorType.prototype.create = function () {
10
- var args = [];
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
- CommandErrorType.prototype.createWithContext = function (reader) {
18
- var args = [];
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
- return CommandErrorType;
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
- 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;
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
- _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]";
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
- 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));
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,4 +1,4 @@
1
- import { StringRange } from "..";
1
+ import type { StringRange } from "..";
2
2
  export declare class Suggestion {
3
3
  private range;
4
4
  private text;
@@ -1,26 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Suggestion = void 0;
4
- var Suggestion = /** @class */ (function () {
5
- function Suggestion(range, text, tooltip) {
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
- Suggestion.prototype.getRange = function () {
10
+ getRange() {
11
11
  return this.range;
12
- };
13
- Suggestion.prototype.getText = function () {
12
+ }
13
+ getText() {
14
14
  return this.text;
15
- };
16
- Suggestion.prototype.getTooltip = function () {
15
+ }
16
+ getTooltip() {
17
17
  return this.tooltip;
18
- };
19
- Suggestion.prototype.apply = function (input) {
20
- if (this.range.getStart() == 0 && this.range.getEnd() === input.length) {
18
+ }
19
+ apply(input) {
20
+ if (this.range.getStart() === 0 && this.range.getEnd() === input.length) {
21
21
  return this.text;
22
22
  }
23
- var result = "";
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
- Suggestion.prototype.expand = function (command, range) {
32
+ }
33
+ expand(command, range) {
34
34
  if (range === this.range) {
35
35
  return this;
36
36
  }
37
- var result = "";
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
- return Suggestion;
48
- }());
46
+ }
47
+ }
49
48
  exports.Suggestion = Suggestion;
@@ -1,4 +1,4 @@
1
- import { StringRange, Suggestion } from "..";
1
+ import { StringRange, type Suggestion } from "..";
2
2
  export declare class Suggestions {
3
3
  static EMPTY: Suggestions;
4
4
  private range;
@@ -1,58 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Suggestions = void 0;
4
- var __1 = require("..");
5
- var Suggestions = /** @class */ (function () {
6
- function Suggestions(range, suggestions) {
4
+ const __1 = require("..");
5
+ class Suggestions {
6
+ constructor(range, suggestions) {
7
7
  this.range = range;
8
8
  this.suggestions = suggestions;
9
9
  }
10
- Suggestions.prototype.getRange = function () {
10
+ getRange() {
11
11
  return this.range;
12
- };
13
- Suggestions.prototype.getList = function () {
12
+ }
13
+ getList() {
14
14
  return this.suggestions;
15
- };
16
- Suggestions.prototype.isEmpty = function () {
15
+ }
16
+ isEmpty() {
17
17
  return this.suggestions.length === 0;
18
- };
19
- Suggestions.empty = function () {
18
+ }
19
+ static empty() {
20
20
  return Promise.resolve(Suggestions.EMPTY);
21
- };
22
- Suggestions.merge = function (command, input) {
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
- 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); });
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
- Suggestions.create = function (command, suggestions) {
36
+ }
37
+ static create(command, suggestions) {
37
38
  if (suggestions.length === 0) {
38
39
  return Suggestions.EMPTY;
39
40
  }
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];
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
- 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];
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
- Suggestions.EMPTY = new Suggestions(__1.StringRange.at(0), []);
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(start: number): SuggestionsBuilder;
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
- var __1 = require("..");
5
- var SuggestionsBuilder = /** @class */ (function () {
6
- function SuggestionsBuilder(input, start) {
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
- SuggestionsBuilder.prototype.getInput = function () {
12
+ getInput() {
13
13
  return this.input;
14
- };
15
- SuggestionsBuilder.prototype.getStart = function () {
14
+ }
15
+ getStart() {
16
16
  return this.start;
17
- };
18
- SuggestionsBuilder.prototype.getRemaining = function () {
17
+ }
18
+ getRemaining() {
19
19
  return this.remaining;
20
- };
21
- SuggestionsBuilder.prototype.build = function () {
20
+ }
21
+ build() {
22
22
  return __1.Suggestions.create(this.input, this.result);
23
- };
24
- SuggestionsBuilder.prototype.buildPromise = function () {
23
+ }
24
+ buildPromise() {
25
25
  return Promise.resolve(this.build());
26
- };
27
- SuggestionsBuilder.prototype.suggest = function (text, tooltip) {
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
- SuggestionsBuilder.prototype.add = function (other) {
33
+ }
34
+ add(other) {
35
35
  this.result.concat(other.result);
36
36
  return this;
37
- };
38
- SuggestionsBuilder.prototype.createOffset = function (start) {
37
+ }
38
+ createOffset(start) {
39
39
  return new SuggestionsBuilder(this.input, start);
40
- };
41
- SuggestionsBuilder.prototype.restart = function (start) {
40
+ }
41
+ restart() {
42
42
  return new SuggestionsBuilder(this.input, this.start);
43
- };
44
- return SuggestionsBuilder;
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
- 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;
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
- ArgumentCommandNode.prototype.getType = function () {
11
+ getType() {
29
12
  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);
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
- ArgumentCommandNode.prototype.getName = function () {
20
+ }
21
+ getName() {
39
22
  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));
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;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandNode = void 0;
4
- var __1 = require("..");
5
- var CommandNode = /** @class */ (function () {
6
- function CommandNode(command, requirement, redirect, modifier, forks) {
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
- CommandNode.prototype.getCommand = function () {
16
+ getCommand() {
17
17
  return this.command;
18
- };
19
- CommandNode.prototype.getChildren = function () {
18
+ }
19
+ getChildren() {
20
20
  return Array.from(this.children.values());
21
- };
22
- CommandNode.prototype.getChild = function (name) {
21
+ }
22
+ getChild(name) {
23
23
  return this.children.get(name);
24
- };
25
- CommandNode.prototype.getRedirect = function () {
24
+ }
25
+ getRedirect() {
26
26
  return this.redirect;
27
- };
28
- CommandNode.prototype.getRedirectModifier = function () {
27
+ }
28
+ getRedirectModifier() {
29
29
  return this.modifier;
30
- };
31
- CommandNode.prototype.isFork = function () {
30
+ }
31
+ isFork() {
32
32
  return this.forks;
33
- };
34
- CommandNode.prototype.canUse = function (source) {
33
+ }
34
+ canUse(source) {
35
35
  return this.requirement(source);
36
- };
37
- CommandNode.prototype.addChild = function (node) {
38
- var child = this.children.get(node.getName());
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(function (grandChild) {
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
- CommandNode.prototype.getRelevantNodes = function (input) {
56
+ }
57
+ getRelevantNodes(input) {
58
58
  if (this.literals.size > 0) {
59
- var cursor = input.getCursor();
60
- while (input.canRead() && input.peek() != " ") {
59
+ const cursor = input.getCursor();
60
+ while (input.canRead() && input.peek() !== " ") {
61
61
  input.skip();
62
62
  }
63
- var text = input.getString().substring(cursor, input.getCursor());
63
+ const text = input.getString().substring(cursor, input.getCursor());
64
64
  input.setCursor(cursor);
65
- var literal = this.literals.get(text);
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
- return CommandNode;
73
- }());
71
+ }
72
+ }
74
73
  exports.CommandNode = CommandNode;