@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,95 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ArgumentBuilder = void 0;
40
+ var __1 = require("..");
41
+ var ArgumentBuilder = /** @class */ (function () {
42
+ function ArgumentBuilder() {
43
+ var _this = this;
44
+ 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
+ }); }); };
48
+ }
49
+ ArgumentBuilder.prototype.then = function (argument) {
50
+ var child = argument instanceof __1.CommandNode ? argument : argument.build();
51
+ this.arguments.addChild(child);
52
+ return this.getThis();
53
+ };
54
+ ArgumentBuilder.prototype.executes = function (command) {
55
+ this.command = command;
56
+ return this.getThis();
57
+ };
58
+ ArgumentBuilder.prototype.requires = function (requirement) {
59
+ this.requirement = requirement;
60
+ return this.getThis();
61
+ };
62
+ ArgumentBuilder.prototype.redirect = function (target, modifier) {
63
+ if (modifier === void 0) { modifier = null; }
64
+ return this.forward(target, modifier, false);
65
+ };
66
+ ArgumentBuilder.prototype.fork = function (target, modifier) {
67
+ return this.forward(target, modifier, true);
68
+ };
69
+ ArgumentBuilder.prototype.forward = function (target, modifier, forks) {
70
+ this.target = target;
71
+ this.modifier = modifier;
72
+ this.forks = forks;
73
+ return this.getThis();
74
+ };
75
+ ArgumentBuilder.prototype.getArguments = function () {
76
+ return this.arguments.getChildren();
77
+ };
78
+ ArgumentBuilder.prototype.getCommand = function () {
79
+ return this.command;
80
+ };
81
+ ArgumentBuilder.prototype.getRequirement = function () {
82
+ return this.requirement;
83
+ };
84
+ ArgumentBuilder.prototype.getRedirect = function () {
85
+ return this.target;
86
+ };
87
+ ArgumentBuilder.prototype.getRedirectModifier = function () {
88
+ return this.modifier;
89
+ };
90
+ ArgumentBuilder.prototype.isFork = function () {
91
+ return this.forks;
92
+ };
93
+ return ArgumentBuilder;
94
+ }());
95
+ exports.ArgumentBuilder = ArgumentBuilder;
@@ -0,0 +1,9 @@
1
+ import { ArgumentBuilder, LiteralCommandNode } from "..";
2
+ export declare class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumentBuilder<S>> {
3
+ private literal;
4
+ constructor(literal: string);
5
+ getThis(): LiteralArgumentBuilder<S>;
6
+ getLiteral(): string;
7
+ build(): LiteralCommandNode<S>;
8
+ }
9
+ export declare function literal<S = any>(name: string): LiteralArgumentBuilder<S>;
@@ -0,0 +1,47 @@
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.LiteralArgumentBuilder = void 0;
19
+ 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;
27
+ }
28
+ LiteralArgumentBuilder.prototype.getThis = function () {
29
+ return this;
30
+ };
31
+ LiteralArgumentBuilder.prototype.getLiteral = function () {
32
+ 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];
38
+ result.addChild(argument);
39
+ }
40
+ return result;
41
+ };
42
+ return LiteralArgumentBuilder;
43
+ }(__1.ArgumentBuilder));
44
+ exports.LiteralArgumentBuilder = LiteralArgumentBuilder;
45
+ function literal(name) {
46
+ return new LiteralArgumentBuilder(name);
47
+ }
@@ -0,0 +1,11 @@
1
+ import { ArgumentBuilder, ArgumentType, ArgumentCommandNode } from "..";
2
+ export declare class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
3
+ private name;
4
+ private type;
5
+ constructor(name: string, type: ArgumentType<T>);
6
+ getThis(): RequiredArgumentBuilder<S, T>;
7
+ getName(): string;
8
+ getType(): ArgumentType<T>;
9
+ build(): ArgumentCommandNode<S, T>;
10
+ }
11
+ export declare function argument<S = any, T = any>(name: string, type: ArgumentType<T>): RequiredArgumentBuilder<S, T>;
@@ -0,0 +1,51 @@
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.RequiredArgumentBuilder = void 0;
19
+ 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;
28
+ }
29
+ RequiredArgumentBuilder.prototype.getThis = function () {
30
+ return this;
31
+ };
32
+ RequiredArgumentBuilder.prototype.getName = function () {
33
+ return this.name;
34
+ };
35
+ RequiredArgumentBuilder.prototype.getType = function () {
36
+ 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);
43
+ }
44
+ return result;
45
+ };
46
+ return RequiredArgumentBuilder;
47
+ }(__1.ArgumentBuilder));
48
+ exports.RequiredArgumentBuilder = RequiredArgumentBuilder;
49
+ function argument(name, type) {
50
+ return new RequiredArgumentBuilder(name, type);
51
+ }
@@ -0,0 +1,27 @@
1
+ import { Command, CommandNode, StringRange, ParsedArgument, ParsedCommandNode, RedirectModifier } from "..";
2
+ export declare class CommandContext<S> {
3
+ private source;
4
+ private input;
5
+ private arguments;
6
+ private nodes;
7
+ private command;
8
+ private rootNode;
9
+ private child;
10
+ private range;
11
+ private modifier;
12
+ private forks;
13
+ constructor(source: S, input: string, parsedArguments: Map<string, ParsedArgument<any>>, command: Command<S>, rootNode: CommandNode<S>, nodes: ParsedCommandNode<S>[], range: StringRange, child: CommandContext<S>, modifier: RedirectModifier<S>, forks: boolean);
14
+ copyFor(source: S): CommandContext<S>;
15
+ getChild(): CommandContext<S>;
16
+ getLastChild(): CommandContext<S>;
17
+ getCommand(): Command<S>;
18
+ getSource(): S;
19
+ getRootNode(): CommandNode<S>;
20
+ get(name: string): any;
21
+ getRedirectModifier(): RedirectModifier<S>;
22
+ getRange(): StringRange;
23
+ getInput(): string;
24
+ getNodes(): ParsedCommandNode<S>[];
25
+ hasNodes(): boolean;
26
+ isForked(): boolean;
27
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandContext = void 0;
4
+ var CommandContext = /** @class */ (function () {
5
+ function CommandContext(source, input, parsedArguments, command, rootNode, nodes, range, child, modifier, forks) {
6
+ this.source = source;
7
+ this.input = input;
8
+ this.arguments = parsedArguments;
9
+ this.command = command;
10
+ this.rootNode = rootNode;
11
+ this.nodes = nodes;
12
+ this.range = range;
13
+ this.child = child;
14
+ this.modifier = modifier;
15
+ this.forks = forks;
16
+ }
17
+ CommandContext.prototype.copyFor = function (source) {
18
+ if (this.source === source) {
19
+ return this;
20
+ }
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 () {
24
+ return this.child;
25
+ };
26
+ CommandContext.prototype.getLastChild = function () {
27
+ var result = this;
28
+ while (result.getChild() != null) {
29
+ result = result.getChild();
30
+ }
31
+ return result;
32
+ };
33
+ CommandContext.prototype.getCommand = function () {
34
+ return this.command;
35
+ };
36
+ CommandContext.prototype.getSource = function () {
37
+ return this.source;
38
+ };
39
+ CommandContext.prototype.getRootNode = function () {
40
+ return this.rootNode;
41
+ };
42
+ CommandContext.prototype.get = function (name) {
43
+ var argument = this.arguments.get(name);
44
+ // TODO: Throw exception when argument is null
45
+ return argument.getResult();
46
+ };
47
+ CommandContext.prototype.getRedirectModifier = function () {
48
+ return this.modifier;
49
+ };
50
+ CommandContext.prototype.getRange = function () {
51
+ return this.range;
52
+ };
53
+ CommandContext.prototype.getInput = function () {
54
+ return this.input;
55
+ };
56
+ CommandContext.prototype.getNodes = function () {
57
+ return this.nodes;
58
+ };
59
+ CommandContext.prototype.hasNodes = function () {
60
+ return this.nodes.length !== 0;
61
+ };
62
+ CommandContext.prototype.isForked = function () {
63
+ return this.forks;
64
+ };
65
+ return CommandContext;
66
+ }());
67
+ exports.CommandContext = CommandContext;
@@ -0,0 +1,31 @@
1
+ import { CommandNode, CommandDispatcher, Command, CommandContext, StringRange, ParsedCommandNode, ParsedArgument, SuggestionContext } from "..";
2
+ export declare class CommandContextBuilder<S> {
3
+ private source;
4
+ private arguments;
5
+ private rootNode;
6
+ private dispatcher;
7
+ private command;
8
+ private child;
9
+ private range;
10
+ private nodes;
11
+ private modifier;
12
+ private forks;
13
+ constructor(dispatcher: CommandDispatcher<S>, source: S, rootNode: CommandNode<S>, start: number);
14
+ withSource(source: S): CommandContextBuilder<S>;
15
+ getSource(): S;
16
+ getRootNode(): CommandNode<S>;
17
+ withArgument(name: string, argument: ParsedArgument<any>): CommandContextBuilder<S>;
18
+ getArguments(): Map<string, ParsedArgument<any>>;
19
+ withChild(child: CommandContextBuilder<S>): CommandContextBuilder<S>;
20
+ getChild(): CommandContextBuilder<S>;
21
+ getLastChild(): CommandContextBuilder<S>;
22
+ withCommand(command: Command<S>): CommandContextBuilder<S>;
23
+ getCommand(): Command<S>;
24
+ withNode(node: CommandNode<S>, range: StringRange): CommandContextBuilder<S>;
25
+ getNodes(): ParsedCommandNode<S>[];
26
+ copy(): CommandContextBuilder<S>;
27
+ build(input: string): CommandContext<S>;
28
+ getDispatcher(): CommandDispatcher<S>;
29
+ getRange(): StringRange;
30
+ findSuggestionContext(cursor: number): SuggestionContext<S>;
31
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandContextBuilder = void 0;
4
+ var __1 = require("..");
5
+ var CommandContextBuilder = /** @class */ (function () {
6
+ function CommandContextBuilder(dispatcher, source, rootNode, start) {
7
+ this.dispatcher = dispatcher;
8
+ this.source = source;
9
+ this.rootNode = rootNode;
10
+ this.range = __1.StringRange.at(start);
11
+ this.nodes = [];
12
+ this.arguments = new Map();
13
+ }
14
+ CommandContextBuilder.prototype.withSource = function (source) {
15
+ this.source = source;
16
+ return this;
17
+ };
18
+ CommandContextBuilder.prototype.getSource = function () {
19
+ return this.source;
20
+ };
21
+ CommandContextBuilder.prototype.getRootNode = function () {
22
+ return this.rootNode;
23
+ };
24
+ CommandContextBuilder.prototype.withArgument = function (name, argument) {
25
+ this.arguments.set(name, argument);
26
+ return this;
27
+ };
28
+ CommandContextBuilder.prototype.getArguments = function () {
29
+ return this.arguments;
30
+ };
31
+ CommandContextBuilder.prototype.withChild = function (child) {
32
+ this.child = child;
33
+ return this;
34
+ };
35
+ CommandContextBuilder.prototype.getChild = function () {
36
+ return this.child;
37
+ };
38
+ CommandContextBuilder.prototype.getLastChild = function () {
39
+ var result = this;
40
+ while (result.getChild() != null) {
41
+ result = result.getChild();
42
+ }
43
+ return result;
44
+ };
45
+ CommandContextBuilder.prototype.withCommand = function (command) {
46
+ this.command = command;
47
+ return this;
48
+ };
49
+ CommandContextBuilder.prototype.getCommand = function () {
50
+ return this.command;
51
+ };
52
+ CommandContextBuilder.prototype.withNode = function (node, range) {
53
+ this.nodes.push(new __1.ParsedCommandNode(node, range));
54
+ this.range = __1.StringRange.encompassing(this.range, range);
55
+ this.modifier = node.getRedirectModifier();
56
+ this.forks = node.isFork();
57
+ return this;
58
+ };
59
+ CommandContextBuilder.prototype.getNodes = function () {
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());
65
+ copy.command = this.command;
66
+ copy.child = this.child;
67
+ copy.range = this.range;
68
+ (_a = copy.nodes).push.apply(_a, this.nodes);
69
+ this.arguments.forEach(function (v, k) {
70
+ copy.arguments.set(k, v);
71
+ });
72
+ return copy;
73
+ };
74
+ CommandContextBuilder.prototype.build = function (input) {
75
+ var child = this.child == null ? null : this.child.build(input);
76
+ 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 () {
79
+ return this.dispatcher;
80
+ };
81
+ CommandContextBuilder.prototype.getRange = function () {
82
+ return this.range;
83
+ };
84
+ CommandContextBuilder.prototype.findSuggestionContext = function (cursor) {
85
+ if (this.range.getStart() <= cursor) {
86
+ if (this.range.getEnd() < cursor) {
87
+ if (this.child != null) {
88
+ return this.child.findSuggestionContext(cursor);
89
+ }
90
+ else if (this.nodes.length > 0) {
91
+ var last = this.nodes[this.nodes.length - 1];
92
+ return new __1.SuggestionContext(last.getNode(), last.getRange().getEnd() + 1);
93
+ }
94
+ else {
95
+ return new __1.SuggestionContext(this.rootNode, this.range.getStart());
96
+ }
97
+ }
98
+ 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();
103
+ if (nodeRange.getStart() <= cursor && cursor <= nodeRange.getEnd()) {
104
+ return new __1.SuggestionContext(prev, nodeRange.getStart());
105
+ }
106
+ prev = node.getNode();
107
+ }
108
+ if (prev === null) {
109
+ throw new Error("Can't find node before cursor");
110
+ }
111
+ return new __1.SuggestionContext(prev, this.range.getStart());
112
+ }
113
+ }
114
+ throw new Error("Can't find node before cursor");
115
+ };
116
+ return CommandContextBuilder;
117
+ }());
118
+ exports.CommandContextBuilder = CommandContextBuilder;
@@ -0,0 +1,8 @@
1
+ import { StringRange } from "..";
2
+ export declare class ParsedArgument<T> {
3
+ private range;
4
+ private result;
5
+ constructor(start: number, end: number, result: T);
6
+ getRange(): StringRange;
7
+ getResult(): T;
8
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParsedArgument = void 0;
4
+ var __1 = require("..");
5
+ var ParsedArgument = /** @class */ (function () {
6
+ function ParsedArgument(start, end, result) {
7
+ this.range = new __1.StringRange(start, end);
8
+ this.result = result;
9
+ }
10
+ ParsedArgument.prototype.getRange = function () {
11
+ return this.range;
12
+ };
13
+ ParsedArgument.prototype.getResult = function () {
14
+ return this.result;
15
+ };
16
+ return ParsedArgument;
17
+ }());
18
+ exports.ParsedArgument = ParsedArgument;
@@ -0,0 +1,8 @@
1
+ import { CommandNode, StringRange } from "..";
2
+ export declare class ParsedCommandNode<S> {
3
+ private node;
4
+ private range;
5
+ constructor(node: CommandNode<S>, range: StringRange);
6
+ getNode(): CommandNode<S>;
7
+ getRange(): StringRange;
8
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParsedCommandNode = void 0;
4
+ var ParsedCommandNode = /** @class */ (function () {
5
+ function ParsedCommandNode(node, range) {
6
+ this.node = node;
7
+ this.range = range;
8
+ }
9
+ ParsedCommandNode.prototype.getNode = function () {
10
+ return this.node;
11
+ };
12
+ ParsedCommandNode.prototype.getRange = function () {
13
+ return this.range;
14
+ };
15
+ return ParsedCommandNode;
16
+ }());
17
+ exports.ParsedCommandNode = ParsedCommandNode;
@@ -0,0 +1,11 @@
1
+ export declare class StringRange {
2
+ private start;
3
+ private end;
4
+ constructor(start: number, end: number);
5
+ static at(pos: number): StringRange;
6
+ static encompassing(a: StringRange, b: StringRange): StringRange;
7
+ getStart(): number;
8
+ getEnd(): number;
9
+ isEmpty(): boolean;
10
+ getLength(): number;
11
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringRange = void 0;
4
+ var StringRange = /** @class */ (function () {
5
+ function StringRange(start, end) {
6
+ this.start = start;
7
+ this.end = end;
8
+ }
9
+ StringRange.at = function (pos) {
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());
15
+ return new StringRange(start, end);
16
+ };
17
+ StringRange.prototype.getStart = function () {
18
+ return this.start;
19
+ };
20
+ StringRange.prototype.getEnd = function () {
21
+ return this.end;
22
+ };
23
+ StringRange.prototype.isEmpty = function () {
24
+ return this.start === this.end;
25
+ };
26
+ StringRange.prototype.getLength = function () {
27
+ return this.end - this.start;
28
+ };
29
+ return StringRange;
30
+ }());
31
+ exports.StringRange = StringRange;
@@ -0,0 +1,6 @@
1
+ import { CommandNode } from "..";
2
+ export declare class SuggestionContext<S> {
3
+ parent: CommandNode<S>;
4
+ startPos: number;
5
+ constructor(parent: CommandNode<S>, startPos: number);
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SuggestionContext = void 0;
4
+ var SuggestionContext = /** @class */ (function () {
5
+ function SuggestionContext(parent, startPos) {
6
+ this.parent = parent;
7
+ this.startPos = startPos;
8
+ }
9
+ return SuggestionContext;
10
+ }());
11
+ exports.SuggestionContext = SuggestionContext;
@@ -0,0 +1,9 @@
1
+ import { CommandSyntaxError, StringReader } from "..";
2
+ type CommandErrorFunction = (...args: any[]) => string;
3
+ export declare class CommandErrorType {
4
+ private func;
5
+ constructor(func: CommandErrorFunction);
6
+ create(...args: any[]): CommandSyntaxError;
7
+ createWithContext(reader: StringReader, ...args: any[]): CommandSyntaxError;
8
+ }
9
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandErrorType = void 0;
4
+ var __1 = require("..");
5
+ var CommandErrorType = /** @class */ (function () {
6
+ function CommandErrorType(func) {
7
+ this.func = func;
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);
15
+ 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);
23
+ return new __1.CommandSyntaxError(message, reader.getString(), reader.getCursor());
24
+ };
25
+ return CommandErrorType;
26
+ }());
27
+ exports.CommandErrorType = CommandErrorType;
@@ -0,0 +1,28 @@
1
+ import { CommandErrorType } from "..";
2
+ export declare class CommandSyntaxError extends Error {
3
+ private input;
4
+ private cursor;
5
+ constructor(message: string, input?: string, cursor?: number);
6
+ static DOUBLE_TOO_SMALL: CommandErrorType;
7
+ static DOUBLE_TOO_BIG: CommandErrorType;
8
+ static FLOAT_TOO_SMALL: CommandErrorType;
9
+ static FLOAT_TOO_BIG: CommandErrorType;
10
+ static INTEGER_TOO_SMALL: CommandErrorType;
11
+ static INTEGER_TOO_BIG: CommandErrorType;
12
+ static LONG_TOO_SMALL: CommandErrorType;
13
+ static LONG_TOO_BIG: CommandErrorType;
14
+ static LITERAL_INCORRECT: CommandErrorType;
15
+ static READER_EXPECTED_START_OF_QUOTE: CommandErrorType;
16
+ static READER_EXPECTED_END_OF_QUOTE: CommandErrorType;
17
+ static READER_INVALID_ESCAPE: CommandErrorType;
18
+ static READER_INVALID_BOOL: CommandErrorType;
19
+ static READER_EXPECTED_BOOL: CommandErrorType;
20
+ static READER_INVALID_INT: CommandErrorType;
21
+ static READER_EXPECTED_INT: CommandErrorType;
22
+ static READER_INVALID_FLOAT: CommandErrorType;
23
+ static READER_EXPECTED_FLOAT: CommandErrorType;
24
+ static DISPATCHER_UNKNOWN_COMMAND: CommandErrorType;
25
+ static DISPATCHER_UNKNOWN_ARGUMENT: CommandErrorType;
26
+ static DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR: CommandErrorType;
27
+ static DISPATCHER_PARSE_ERROR: CommandErrorType;
28
+ }