@wq2/brigadier-ts 1.0.0 → 1.0.1

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