@jsprismarine/brigadier 0.2.0-rc.1 → 0.2.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 (136) hide show
  1. package/README.md +57 -39
  2. package/dist/index.js +6 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/lib/CommandDispatcher.js +1 -3
  5. package/dist/lib/CommandDispatcher.js.map +1 -1
  6. package/dist/lib/builder/LiteralArgumentBuilder.js.map +1 -1
  7. package/dist/lib/builder/RequiredArgumentBuilder.js.map +1 -1
  8. package/dist/lib/context/CommandContext.js +4 -4
  9. package/dist/lib/context/CommandContext.js.map +1 -1
  10. package/dist/lib/suggestion/Suggestion.js +1 -1
  11. package/dist/lib/suggestion/Suggestion.js.map +1 -1
  12. package/dist/lib/suggestion/Suggestions.js +1 -1
  13. package/dist/lib/suggestion/Suggestions.js.map +1 -1
  14. package/dist/lib/tree/ArgumentCommandNode.js +1 -1
  15. package/dist/lib/tree/ArgumentCommandNode.js.map +1 -1
  16. package/dist/lib/tree/CommandNode.js +2 -2
  17. package/dist/lib/tree/CommandNode.js.map +1 -1
  18. package/package.json +55 -48
  19. package/.prettierrc +0 -10
  20. package/.renovaterc +0 -3
  21. package/CHANGELOG.md +0 -30
  22. package/dist/index.d.ts +0 -23
  23. package/dist/lib/AmbiguityConsumer.d.ts +0 -4
  24. package/dist/lib/Command.d.ts +0 -4
  25. package/dist/lib/CommandDispatcher.d.ts +0 -29
  26. package/dist/lib/ImmutableStringReader.d.ts +0 -12
  27. package/dist/lib/LiteralMessage.d.ts +0 -7
  28. package/dist/lib/Message.d.ts +0 -3
  29. package/dist/lib/ParseResults.d.ts +0 -13
  30. package/dist/lib/Predicate.d.ts +0 -3
  31. package/dist/lib/RedirectModifier.d.ts +0 -4
  32. package/dist/lib/ResultConsumer.d.ts +0 -4
  33. package/dist/lib/SingleRedirectModifier.d.ts +0 -4
  34. package/dist/lib/StringReader.d.ts +0 -27
  35. package/dist/lib/arguments/ArgumentType.d.ts +0 -21
  36. package/dist/lib/arguments/BoolArgumentType.d.ts +0 -13
  37. package/dist/lib/arguments/FloatArgumentType.d.ts +0 -16
  38. package/dist/lib/arguments/IntegerArgumentType.d.ts +0 -16
  39. package/dist/lib/arguments/StringArgumentType.d.ts +0 -21
  40. package/dist/lib/builder/ArgumentBuilder.d.ts +0 -28
  41. package/dist/lib/builder/LiteralArgumentBuilder.d.ts +0 -11
  42. package/dist/lib/builder/RequiredArgumentBuilder.d.ts +0 -18
  43. package/dist/lib/context/CommandContext.d.ts +0 -33
  44. package/dist/lib/context/CommandContextBuilder.d.ts +0 -38
  45. package/dist/lib/context/ParsedArgument.d.ts +0 -9
  46. package/dist/lib/context/ParsedCommandNode.d.ts +0 -11
  47. package/dist/lib/context/StringRange.d.ts +0 -16
  48. package/dist/lib/context/SuggestionContext.d.ts +0 -6
  49. package/dist/lib/exceptions/BuiltInExceptionProvider.d.ts +0 -23
  50. package/dist/lib/exceptions/BuiltInExceptions.d.ts +0 -43
  51. package/dist/lib/exceptions/CommandExceptionType.d.ts +0 -2
  52. package/dist/lib/exceptions/CommandSyntaxException.d.ts +0 -19
  53. package/dist/lib/exceptions/DynamicCommandExceptionType.d.ts +0 -10
  54. package/dist/lib/exceptions/SimpleCommandExceptionType.d.ts +0 -11
  55. package/dist/lib/suggestion/IntegerSuggestion.d.ts +0 -12
  56. package/dist/lib/suggestion/Suggestion.d.ts +0 -17
  57. package/dist/lib/suggestion/SuggestionProvider.d.ts +0 -6
  58. package/dist/lib/suggestion/Suggestions.d.ts +0 -16
  59. package/dist/lib/suggestion/SuggestionsBuilder.d.ts +0 -18
  60. package/dist/lib/tree/ArgumentCommandNode.d.ts +0 -31
  61. package/dist/lib/tree/CommandNode.d.ts +0 -45
  62. package/dist/lib/tree/LiteralCommandNode.d.ts +0 -27
  63. package/dist/lib/tree/RootCommandNode.d.ts +0 -21
  64. package/dist/lib/util/isEqual.d.ts +0 -1
  65. package/example/fill.js +0 -47
  66. package/example/fill.ts +0 -50
  67. package/src/index.ts +0 -50
  68. package/src/lib/AmbiguityConsumer.ts +0 -6
  69. package/src/lib/Command.ts +0 -5
  70. package/src/lib/CommandDispatcher.ts +0 -480
  71. package/src/lib/ImmutableStringReader.ts +0 -22
  72. package/src/lib/LiteralMessage.ts +0 -17
  73. package/src/lib/Message.ts +0 -3
  74. package/src/lib/ParseResults.ts +0 -32
  75. package/src/lib/Predicate.ts +0 -3
  76. package/src/lib/RedirectModifier.ts +0 -5
  77. package/src/lib/ResultConsumer.ts +0 -6
  78. package/src/lib/SingleRedirectModifier.ts +0 -6
  79. package/src/lib/StringReader.ts +0 -210
  80. package/src/lib/arguments/ArgumentType.ts +0 -28
  81. package/src/lib/arguments/BoolArgumentType.ts +0 -41
  82. package/src/lib/arguments/FloatArgumentType.ts +0 -75
  83. package/src/lib/arguments/IntegerArgumentType.ts +0 -75
  84. package/src/lib/arguments/StringArgumentType.ts +0 -83
  85. package/src/lib/builder/ArgumentBuilder.ts +0 -94
  86. package/src/lib/builder/LiteralArgumentBuilder.ts +0 -35
  87. package/src/lib/builder/RequiredArgumentBuilder.ts +0 -54
  88. package/src/lib/context/CommandContext.ts +0 -118
  89. package/src/lib/context/CommandContextBuilder.ts +0 -155
  90. package/src/lib/context/ParsedArgument.ts +0 -27
  91. package/src/lib/context/ParsedCommandNode.ts +0 -35
  92. package/src/lib/context/StringRange.ts +0 -57
  93. package/src/lib/context/SuggestionContext.ts +0 -12
  94. package/src/lib/exceptions/BuiltInExceptionProvider.ts +0 -43
  95. package/src/lib/exceptions/BuiltInExceptions.ts +0 -121
  96. package/src/lib/exceptions/CommandExceptionType.ts +0 -2
  97. package/src/lib/exceptions/CommandSyntaxException.ts +0 -77
  98. package/src/lib/exceptions/DynamicCommandExceptionType.ts +0 -22
  99. package/src/lib/exceptions/SimpleCommandExceptionType.ts +0 -26
  100. package/src/lib/suggestion/IntegerSuggestion.ts +0 -46
  101. package/src/lib/suggestion/Suggestion.ts +0 -87
  102. package/src/lib/suggestion/SuggestionProvider.ts +0 -7
  103. package/src/lib/suggestion/Suggestions.ts +0 -85
  104. package/src/lib/suggestion/SuggestionsBuilder.ts +0 -69
  105. package/src/lib/tree/ArgumentCommandNode.ts +0 -140
  106. package/src/lib/tree/CommandNode.ts +0 -208
  107. package/src/lib/tree/LiteralCommandNode.ts +0 -111
  108. package/src/lib/tree/RootCommandNode.ts +0 -62
  109. package/src/lib/util/isEqual.ts +0 -75
  110. package/test/CommandDispatcherTest.ts +0 -427
  111. package/test/CommandDispatcherUsagesTest.ts +0 -163
  112. package/test/CommandSuggestionsTest.ts +0 -283
  113. package/test/StringReaderTest.ts +0 -391
  114. package/test/arguments/BoolArgumentTypeTest.ts +0 -18
  115. package/test/arguments/FloatArgumentTypeTest.ts +0 -61
  116. package/test/arguments/IntegerArgumentTypeTest.ts +0 -63
  117. package/test/arguments/StringArgumentTypeTest.ts +0 -61
  118. package/test/benchmarks/ExecuteBenchmark.js +0 -33
  119. package/test/benchmarks/ParsingBenchmark.js +0 -96
  120. package/test/builder/ArgumentBuilderTest.ts +0 -61
  121. package/test/builder/LiteralArgumentBuilderTest.ts +0 -37
  122. package/test/builder/RequiredArgumentBuilderTest.ts +0 -40
  123. package/test/context/CommandContextTest.ts +0 -77
  124. package/test/context/ParsedArgumentTest.ts +0 -19
  125. package/test/exceptions/DynamicCommandSyntaxExceptionTypeTest.ts +0 -18
  126. package/test/exceptions/SimpleCommandSyntaxExceptionTypeTest.ts +0 -33
  127. package/test/suggestion/SuggestionBuilderTest.ts +0 -66
  128. package/test/suggestion/SuggestionTest.ts +0 -65
  129. package/test/suggestion/SuggestionsTest.ts +0 -24
  130. package/test/tree/AbstractCommandNodeTest.ts +0 -57
  131. package/test/tree/ArgumentCommandNodeTest.ts +0 -81
  132. package/test/tree/LiteralCommandNodeTest.ts +0 -112
  133. package/test/tree/RootCommandNodeTest.ts +0 -70
  134. package/test/utils/testEquality.ts +0 -10
  135. package/tsconfig.json +0 -41
  136. package/tsconfig.tsbuildinfo +0 -1585
@@ -1,480 +0,0 @@
1
- import AmbiguityConsumer from './AmbiguityConsumer';
2
- import CommandContext from './context/CommandContext';
3
- import CommandContextBuilder from './context/CommandContextBuilder';
4
- import CommandNode from './tree/CommandNode';
5
- import CommandSyntaxException from './exceptions/CommandSyntaxException';
6
- import LiteralArgumentBuilder from './builder/LiteralArgumentBuilder';
7
- import LiteralCommandNode from './tree/LiteralCommandNode';
8
- import ParseResults from './ParseResults';
9
- import RedirectModifier from './RedirectModifier';
10
- import ResultConsumer from './ResultConsumer';
11
- import RootCommandNode from './tree/RootCommandNode';
12
- import StringReader from './StringReader';
13
- import SuggestionContext from './context/SuggestionContext';
14
- import Suggestions from './suggestion/Suggestions';
15
- import SuggestionsBuilder from './suggestion/SuggestionsBuilder';
16
-
17
- const ARGUMENT_SEPARATOR = ' ';
18
- const USAGE_OPTIONAL_OPEN = '[';
19
- const USAGE_OPTIONAL_CLOSE = ']';
20
- const USAGE_REQUIRED_OPEN = '(';
21
- const USAGE_REQUIRED_CLOSE = ')';
22
- const USAGE_OR = '|';
23
-
24
- export default class CommandDispatcher<S> {
25
- private root: RootCommandNode<S>;
26
-
27
- private consumer: ResultConsumer<S> = {
28
- onCommandComplete() {}
29
- };
30
-
31
- public constructor(root: RootCommandNode<S> = null) {
32
- this.root = root || new RootCommandNode<S>();
33
- }
34
-
35
- public register(command: LiteralArgumentBuilder<S>): LiteralCommandNode<S> {
36
- let build = command.build();
37
- this.root.addChild(build);
38
- return build;
39
- }
40
-
41
- public setConsumer(consumer: ResultConsumer<S>) {
42
- this.consumer = consumer;
43
- }
44
-
45
- public execute(
46
- input: string | StringReader | ParseResults<S>,
47
- source: S = null
48
- ): Promise<any>[] {
49
- if (typeof input === 'string') input = new StringReader(input);
50
-
51
- let parse: ParseResults<S>;
52
- if (input instanceof StringReader) {
53
- if (!(source == null)) parse = this.parse(input, source);
54
- } else parse = input;
55
-
56
- if (parse.getReader().canRead()) {
57
- if (parse.getExceptions().size === 1) {
58
- throw parse.getExceptions().values().next().value;
59
- } else if (parse.getContext().getRange().isEmpty()) {
60
- throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(
61
- parse.getReader()
62
- );
63
- } else {
64
- throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(
65
- parse.getReader()
66
- );
67
- }
68
- }
69
-
70
- let result = [];
71
- let successfulForks = 0;
72
- let forked = false;
73
- let foundCommand = false;
74
- let command = parse.getReader().getString();
75
- let original = parse.getContext().build(command);
76
- let contexts: Array<CommandContext<S>> = [];
77
- contexts.push(original);
78
- let next: CommandContext<S>[] = null;
79
- while (!(contexts == null)) {
80
- for (let i = 0; i < contexts.length; i++) {
81
- let context: CommandContext<S> = contexts[i];
82
- let child: CommandContext<S> = context.getChild();
83
- if (!(child == null)) {
84
- forked = forked || context.isForked();
85
- if (child.hasNodes()) {
86
- foundCommand = true;
87
- let modifier: RedirectModifier<S> = context.getRedirectModifier();
88
- if (modifier == null) {
89
- if (next == null) next = [];
90
- next.push(child.copyFor(context.getSource()));
91
- } else {
92
- try {
93
- let results: Array<S> = modifier.apply(context);
94
- if (results.length !== 0) {
95
- if (next == null) next = [];
96
-
97
- for (let source of results) {
98
- next.push(child.copyFor(source));
99
- }
100
- }
101
- } catch (ex) {
102
- this.consumer.onCommandComplete(
103
- context,
104
- false,
105
- 0
106
- );
107
- if (!forked) throw ex;
108
- }
109
- }
110
- }
111
- } else if (context.getCommand() != null) {
112
- foundCommand = true;
113
- try {
114
- let value = context.getCommand()(context);
115
- result.push(value);
116
- this.consumer.onCommandComplete(context, true, value);
117
- successfulForks++;
118
- } catch (ex) {
119
- this.consumer.onCommandComplete(context, false, ex);
120
- if (!forked) throw ex;
121
- }
122
- }
123
- }
124
-
125
- contexts = next;
126
- next = null;
127
- }
128
-
129
- if (!foundCommand) {
130
- this.consumer.onCommandComplete(original, false, 0);
131
- throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(
132
- parse.getReader()
133
- );
134
- }
135
-
136
- return result;
137
- }
138
-
139
- public parse(command: string | StringReader, source: S): ParseResults<S> {
140
- if (typeof command === 'string') command = new StringReader(command);
141
-
142
- let context: CommandContextBuilder<S> = new CommandContextBuilder(
143
- this,
144
- source,
145
- this.root,
146
- command.getCursor()
147
- );
148
- return this.parseNodes(this.root, command, context);
149
- }
150
-
151
- private parseNodes(
152
- node: CommandNode<S>,
153
- originalReader: StringReader,
154
- contextSoFar: CommandContextBuilder<S>
155
- ): ParseResults<S> {
156
- let source: S = contextSoFar.getSource();
157
- let errors: Map<CommandNode<S>, CommandSyntaxException> = null;
158
- let potentials: ParseResults<S>[] = null;
159
- let cursor = originalReader.getCursor();
160
- for (let child of node.getRelevantNodes(originalReader)) {
161
- if (!child.canUse(source)) continue;
162
-
163
- let context: CommandContextBuilder<S> = contextSoFar.copy();
164
- let reader: StringReader = new StringReader(originalReader);
165
- try {
166
- child.parse(reader, context);
167
-
168
- if (reader.canRead())
169
- if (reader.peek() != ARGUMENT_SEPARATOR)
170
- throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherExpectedArgumentSeparator().createWithContext(
171
- reader
172
- );
173
- } catch (ex) {
174
- if (errors == null) {
175
- errors = new Map();
176
- }
177
- errors.set(child, ex);
178
- reader.setCursor(cursor);
179
- continue;
180
- }
181
-
182
- context.withCommand(child.getCommand());
183
- if (reader.canRead(child.getRedirect() == null ? 2 : 1)) {
184
- reader.skip();
185
- if (!(child.getRedirect() == null)) {
186
- let childContext: CommandContextBuilder<S> = new CommandContextBuilder(
187
- this,
188
- source,
189
- child.getRedirect(),
190
- reader.getCursor()
191
- );
192
- let parse: ParseResults<S> = this.parseNodes(
193
- child.getRedirect(),
194
- reader,
195
- childContext
196
- );
197
- context.withChild(parse.getContext());
198
- return new ParseResults(
199
- context,
200
- parse.getReader(),
201
- parse.getExceptions()
202
- );
203
- } else {
204
- let parse: ParseResults<S> = this.parseNodes(
205
- child,
206
- reader,
207
- context
208
- );
209
- if (potentials == null) {
210
- potentials = [];
211
- }
212
-
213
- potentials.push(parse);
214
- }
215
- } else {
216
- if (potentials == null) {
217
- potentials = [];
218
- }
219
- potentials.push(new ParseResults(context, reader, new Map()));
220
- }
221
- }
222
-
223
- if (!(potentials == null)) {
224
- if (potentials.length > 1) {
225
- potentials.sort((a, b) => {
226
- if (!a.getReader().canRead() && b.getReader().canRead()) {
227
- return -1;
228
- }
229
- if (a.getReader().canRead() && !b.getReader().canRead()) {
230
- return 1;
231
- }
232
- if (
233
- a.getExceptions().size === 0 &&
234
- b.getExceptions().size !== 0
235
- ) {
236
- return -1;
237
- }
238
- if (
239
- a.getExceptions().size !== 0 &&
240
- b.getExceptions().size === 0
241
- ) {
242
- return 1;
243
- }
244
- return 0;
245
- });
246
- }
247
- return potentials[0];
248
- }
249
-
250
- return new ParseResults<S>(
251
- contextSoFar,
252
- originalReader,
253
- errors == null ? new Map() : errors
254
- );
255
- }
256
-
257
- public getAllUsage(
258
- node: CommandNode<S>,
259
- source: S,
260
- restricted: boolean
261
- ): string[] {
262
- const result: Array<string> = [];
263
- this.__getAllUsage(node, source, result, '', restricted);
264
- return result;
265
- }
266
-
267
- private __getAllUsage(
268
- node: CommandNode<S>,
269
- source: S,
270
- result: string[],
271
- prefix = '',
272
- restricted: boolean
273
- ) {
274
- if (restricted && !node.canUse(source)) {
275
- return;
276
- }
277
-
278
- if (node.getCommand() != null) {
279
- result.push(prefix);
280
- }
281
-
282
- if (node.getRedirect() != null) {
283
- const redirect =
284
- node.getRedirect() === this.root
285
- ? '...'
286
- : '-> ' + node.getRedirect().getUsageText();
287
- result.push(
288
- prefix.length === 0
289
- ? node.getUsageText() + ARGUMENT_SEPARATOR + redirect
290
- : prefix + ARGUMENT_SEPARATOR + redirect
291
- );
292
- } else if (node.getChildrenCount() > 0) {
293
- for (let child of node.getChildren()) {
294
- this.__getAllUsage(
295
- child,
296
- source,
297
- result,
298
- prefix.length === 0
299
- ? child.getUsageText()
300
- : prefix + ARGUMENT_SEPARATOR + child.getUsageText(),
301
- restricted
302
- );
303
- }
304
- }
305
- }
306
-
307
- public getSmartUsage(
308
- node: CommandNode<S>,
309
- source: S
310
- ): Map<CommandNode<S>, string> {
311
- let result = new Map<CommandNode<S>, string>();
312
-
313
- let optional = node.getCommand() !== null;
314
- for (let child of node.getChildren()) {
315
- let usage = this.__getSmartUsage(child, source, optional, false);
316
- if (!(usage == null)) {
317
- result.set(child, usage);
318
- }
319
- }
320
-
321
- return result;
322
- }
323
-
324
- private __getSmartUsage(
325
- node: CommandNode<S>,
326
- source: S,
327
- optional: boolean,
328
- deep: boolean
329
- ): string {
330
- if (!node.canUse(source)) {
331
- return null;
332
- }
333
-
334
- let self = optional
335
- ? USAGE_OPTIONAL_OPEN + node.getUsageText() + USAGE_OPTIONAL_CLOSE
336
- : node.getUsageText();
337
- let childOptional = node.getCommand() != null;
338
- let open = childOptional ? USAGE_OPTIONAL_OPEN : USAGE_REQUIRED_OPEN;
339
- let close = childOptional ? USAGE_OPTIONAL_CLOSE : USAGE_REQUIRED_CLOSE;
340
-
341
- if (!deep) {
342
- if (node.getRedirect() != null) {
343
- let redirect =
344
- node.getRedirect() == this.root
345
- ? '...'
346
- : '-> ' + node.getRedirect().getUsageText();
347
- return self + ARGUMENT_SEPARATOR + redirect;
348
- } else {
349
- let children: CommandNode<S>[] = [
350
- ...node.getChildren()
351
- ].filter((c) => c.canUse(source));
352
- if (children.length == 1) {
353
- let usage = this.__getSmartUsage(
354
- children[0],
355
- source,
356
- childOptional,
357
- childOptional
358
- );
359
- if (!(usage == null)) {
360
- return self + ARGUMENT_SEPARATOR + usage;
361
- }
362
- } else if (children.length > 1) {
363
- let childUsage = new Set<string>();
364
- for (let child of children) {
365
- let usage = this.__getSmartUsage(
366
- child,
367
- source,
368
- childOptional,
369
- true
370
- );
371
- if (!(usage == null)) {
372
- childUsage.add(usage);
373
- }
374
- }
375
- if (childUsage.size === 1) {
376
- let usage = childUsage.values().next().value;
377
- return (
378
- self +
379
- ARGUMENT_SEPARATOR +
380
- (childOptional
381
- ? USAGE_OPTIONAL_OPEN +
382
- usage +
383
- USAGE_OPTIONAL_CLOSE
384
- : usage)
385
- );
386
- } else if (childUsage.size > 1) {
387
- let builder = open;
388
- let count = 0;
389
- for (let child of children) {
390
- if (count > 0) {
391
- builder += USAGE_OR;
392
- }
393
- builder += child.getUsageText();
394
- count++;
395
- }
396
- if (count > 0) {
397
- builder += close;
398
- return self + ARGUMENT_SEPARATOR + builder;
399
- }
400
- }
401
- }
402
- }
403
- }
404
- return self;
405
- }
406
-
407
- public async getCompletionSuggestions(
408
- parse: ParseResults<S>,
409
- cursor = parse.getReader().getTotalLength()
410
- ): Promise<Suggestions> {
411
- let context: CommandContextBuilder<S> = parse.getContext();
412
- let nodeBeforeCursor: SuggestionContext<S> = context.findSuggestionContext(
413
- cursor
414
- );
415
- let parent: CommandNode<S> = nodeBeforeCursor.parent;
416
- let start = Math.min(nodeBeforeCursor.startPos, cursor);
417
- let fullInput = parse.getReader().getString();
418
- let truncatedInput = fullInput.substring(0, cursor);
419
- let futures = [];
420
- for (let node of parent.getChildren()) {
421
- let future = await Suggestions.empty();
422
- try {
423
- future = await node.listSuggestions(
424
- context.build(truncatedInput),
425
- new SuggestionsBuilder(truncatedInput, start)
426
- );
427
- } catch (ignored) {}
428
- futures.push(future);
429
- }
430
-
431
- return Promise.resolve(Suggestions.merge(fullInput, futures));
432
- }
433
-
434
- public getRoot(): RootCommandNode<S> {
435
- return this.root;
436
- }
437
-
438
- public getPath(target: CommandNode<S>): string[] {
439
- let nodes: Array<Array<CommandNode<S>>> = [];
440
- this.addPaths(this.root, nodes, []);
441
- for (let list of nodes) {
442
- if (list[list.length - 1] === target) {
443
- let result = [];
444
- for (let node of list) {
445
- if (node !== this.root) {
446
- result.push(node.getName());
447
- }
448
- }
449
- return result;
450
- }
451
- }
452
- return [];
453
- }
454
-
455
- public findNode(path: string[]): CommandNode<S> {
456
- let node: CommandNode<S> = this.root;
457
- for (let name of path) {
458
- node = node.getChild(name);
459
- if (node == null) return null;
460
- }
461
- return node;
462
- }
463
-
464
- public findAmbiguities(consumer: AmbiguityConsumer<S>, context: any) {
465
- this.root.findAmbiguities(consumer, context);
466
- }
467
-
468
- private addPaths(
469
- node: CommandNode<S>,
470
- result: Array<Array<CommandNode<S>>>,
471
- parents: Array<CommandNode<S>>
472
- ): void {
473
- let current: Array<CommandNode<S>> = [];
474
- current.push(...parents);
475
- current.push(node);
476
- result.push(current);
477
- for (let child of node.getChildren())
478
- this.addPaths(child, result, current);
479
- }
480
- }
@@ -1,22 +0,0 @@
1
- export default interface ImmutableStringReader {
2
-
3
- getString(): string;
4
-
5
- getRemainingLength(): number;
6
-
7
- getTotalLength(): number;
8
-
9
- getCursor(): number;
10
-
11
- getRead(): string;
12
-
13
- getRemaining(): string;
14
-
15
- canRead(length: number): boolean;
16
-
17
- canRead(): boolean;
18
-
19
- peek(): string;
20
-
21
- peek(offset: number): string;
22
- }
@@ -1,17 +0,0 @@
1
- import Message from "./Message"
2
-
3
- export default class LiteralMessage implements Message {
4
-
5
- str: string;
6
- public constructor (str: string) {
7
- this.str = str;
8
- }
9
-
10
- public getString(): string {
11
- return this.str;
12
- }
13
-
14
- public toString(): string {
15
- return this.str;
16
- }
17
- }
@@ -1,3 +0,0 @@
1
- export default interface Message {
2
- getString(): string;
3
- }
@@ -1,32 +0,0 @@
1
- import CommandContextBuilder from "./context/CommandContextBuilder"
2
- import CommandSyntaxException from "./exceptions/CommandSyntaxException"
3
- import CommandNode from "./tree/CommandNode"
4
- import ImmutableStringReader from "./ImmutableStringReader"
5
- import StringReader from "./StringReader"
6
-
7
- export default class ParseResults<S> {
8
-
9
- private context: CommandContextBuilder<S>;
10
-
11
- private exceptions: Map<CommandNode<S>, CommandSyntaxException>;
12
-
13
- private reader: ImmutableStringReader;
14
-
15
- public constructor (context: CommandContextBuilder<S>, reader: ImmutableStringReader, exceptions: Map<CommandNode<S>, CommandSyntaxException>) {
16
- this.context = context;
17
- this.reader = reader || new StringReader("");
18
- this.exceptions = exceptions || new Map<CommandNode<S>, CommandSyntaxException>();
19
- }
20
-
21
- public getContext(): CommandContextBuilder<S> {
22
- return this.context;
23
- }
24
-
25
- public getReader(): ImmutableStringReader {
26
- return this.reader;
27
- }
28
-
29
- public getExceptions(): Map<CommandNode<S>, CommandSyntaxException> {
30
- return this.exceptions;
31
- }
32
- }
@@ -1,3 +0,0 @@
1
- export default interface Predicate<T> {
2
- (t: T): boolean;
3
- }
@@ -1,5 +0,0 @@
1
- import CommandContext from "./context/CommandContext"
2
-
3
- export default interface RedirectModifier<S> {
4
- apply(context: CommandContext<S>): S[];
5
- }
@@ -1,6 +0,0 @@
1
- import CommandContext from "./context/CommandContext"
2
-
3
- export default interface ResultConsumer<S> {
4
-
5
- onCommandComplete(context: CommandContext<S>, success: boolean, result: any): void;
6
- }
@@ -1,6 +0,0 @@
1
- import CommandContext from "./context/CommandContext"
2
-
3
- export default interface SingleRedirectModifier<S> {
4
-
5
- apply(context: CommandContext<S>): S;
6
- }