@jsprismarine/brigadier 0.1.0 → 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 (210) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +57 -39
  3. package/dist/index.js +6 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/AmbiguityConsumer.js +0 -0
  6. package/dist/lib/AmbiguityConsumer.js.map +0 -0
  7. package/dist/lib/Command.js +0 -0
  8. package/dist/lib/Command.js.map +0 -0
  9. package/dist/lib/CommandDispatcher.js +45 -28
  10. package/dist/lib/CommandDispatcher.js.map +1 -1
  11. package/dist/lib/ImmutableStringReader.js +0 -0
  12. package/dist/lib/ImmutableStringReader.js.map +0 -0
  13. package/dist/lib/LiteralMessage.js +0 -0
  14. package/dist/lib/LiteralMessage.js.map +0 -0
  15. package/dist/lib/Message.js +0 -0
  16. package/dist/lib/Message.js.map +0 -0
  17. package/dist/lib/ParseResults.js +0 -0
  18. package/dist/lib/ParseResults.js.map +0 -0
  19. package/dist/lib/Predicate.js +0 -0
  20. package/dist/lib/Predicate.js.map +0 -0
  21. package/dist/lib/RedirectModifier.js +0 -0
  22. package/dist/lib/RedirectModifier.js.map +0 -0
  23. package/dist/lib/ResultConsumer.js +0 -0
  24. package/dist/lib/ResultConsumer.js.map +0 -0
  25. package/dist/lib/SingleRedirectModifier.js +0 -0
  26. package/dist/lib/SingleRedirectModifier.js.map +0 -0
  27. package/dist/lib/StringReader.js +0 -0
  28. package/dist/lib/StringReader.js.map +0 -0
  29. package/dist/lib/arguments/ArgumentType.js +1 -1
  30. package/dist/lib/arguments/ArgumentType.js.map +1 -1
  31. package/dist/lib/arguments/BoolArgumentType.js +0 -0
  32. package/dist/lib/arguments/BoolArgumentType.js.map +0 -0
  33. package/dist/lib/arguments/FloatArgumentType.js +0 -0
  34. package/dist/lib/arguments/FloatArgumentType.js.map +0 -0
  35. package/dist/lib/arguments/IntegerArgumentType.js +0 -0
  36. package/dist/lib/arguments/IntegerArgumentType.js.map +0 -0
  37. package/dist/lib/arguments/StringArgumentType.js +0 -0
  38. package/dist/lib/arguments/StringArgumentType.js.map +0 -0
  39. package/dist/lib/builder/ArgumentBuilder.js +0 -0
  40. package/dist/lib/builder/ArgumentBuilder.js.map +0 -0
  41. package/dist/lib/builder/LiteralArgumentBuilder.js +0 -0
  42. package/dist/lib/builder/LiteralArgumentBuilder.js.map +1 -1
  43. package/dist/lib/builder/RequiredArgumentBuilder.js +0 -0
  44. package/dist/lib/builder/RequiredArgumentBuilder.js.map +1 -1
  45. package/dist/lib/context/CommandContext.js +4 -4
  46. package/dist/lib/context/CommandContext.js.map +1 -1
  47. package/dist/lib/context/CommandContextBuilder.js +0 -0
  48. package/dist/lib/context/CommandContextBuilder.js.map +0 -0
  49. package/dist/lib/context/ParsedArgument.js +0 -0
  50. package/dist/lib/context/ParsedArgument.js.map +0 -0
  51. package/dist/lib/context/ParsedCommandNode.js +0 -0
  52. package/dist/lib/context/ParsedCommandNode.js.map +0 -0
  53. package/dist/lib/context/StringRange.js +0 -0
  54. package/dist/lib/context/StringRange.js.map +0 -0
  55. package/dist/lib/context/SuggestionContext.js +0 -0
  56. package/dist/lib/context/SuggestionContext.js.map +0 -0
  57. package/dist/lib/exceptions/BuiltInExceptionProvider.js +0 -0
  58. package/dist/lib/exceptions/BuiltInExceptionProvider.js.map +0 -0
  59. package/dist/lib/exceptions/BuiltInExceptions.js +0 -0
  60. package/dist/lib/exceptions/BuiltInExceptions.js.map +0 -0
  61. package/dist/lib/exceptions/CommandExceptionType.js +0 -0
  62. package/dist/lib/exceptions/CommandExceptionType.js.map +0 -0
  63. package/dist/lib/exceptions/CommandSyntaxException.js +0 -0
  64. package/dist/lib/exceptions/CommandSyntaxException.js.map +0 -0
  65. package/dist/lib/exceptions/DynamicCommandExceptionType.js +0 -0
  66. package/dist/lib/exceptions/DynamicCommandExceptionType.js.map +0 -0
  67. package/dist/lib/exceptions/SimpleCommandExceptionType.js +0 -0
  68. package/dist/lib/exceptions/SimpleCommandExceptionType.js.map +0 -0
  69. package/dist/lib/suggestion/IntegerSuggestion.js +0 -0
  70. package/dist/lib/suggestion/IntegerSuggestion.js.map +0 -0
  71. package/dist/lib/suggestion/Suggestion.js +1 -1
  72. package/dist/lib/suggestion/Suggestion.js.map +1 -1
  73. package/dist/lib/suggestion/SuggestionProvider.js +0 -0
  74. package/dist/lib/suggestion/SuggestionProvider.js.map +0 -0
  75. package/dist/lib/suggestion/Suggestions.js +1 -1
  76. package/dist/lib/suggestion/Suggestions.js.map +1 -1
  77. package/dist/lib/suggestion/SuggestionsBuilder.js +0 -0
  78. package/dist/lib/suggestion/SuggestionsBuilder.js.map +0 -0
  79. package/dist/lib/tree/ArgumentCommandNode.js +17 -16
  80. package/dist/lib/tree/ArgumentCommandNode.js.map +1 -1
  81. package/dist/lib/tree/CommandNode.js +14 -13
  82. package/dist/lib/tree/CommandNode.js.map +1 -1
  83. package/dist/lib/tree/LiteralCommandNode.js +0 -0
  84. package/dist/lib/tree/LiteralCommandNode.js.map +0 -0
  85. package/dist/lib/tree/RootCommandNode.js +0 -0
  86. package/dist/lib/tree/RootCommandNode.js.map +0 -0
  87. package/dist/lib/util/isEqual.js +0 -0
  88. package/dist/lib/util/isEqual.js.map +0 -0
  89. package/index.js +0 -0
  90. package/package.json +55 -48
  91. package/.prettierrc +0 -10
  92. package/.renovaterc +0 -3
  93. package/CHANGELOG.md +0 -30
  94. package/dist/index.d.ts +0 -23
  95. package/dist/lib/AmbiguityConsumer.d.ts +0 -4
  96. package/dist/lib/Command.d.ts +0 -4
  97. package/dist/lib/CommandDispatcher.d.ts +0 -29
  98. package/dist/lib/ImmutableStringReader.d.ts +0 -12
  99. package/dist/lib/LiteralMessage.d.ts +0 -7
  100. package/dist/lib/Message.d.ts +0 -3
  101. package/dist/lib/ParseResults.d.ts +0 -13
  102. package/dist/lib/Predicate.d.ts +0 -3
  103. package/dist/lib/Primitive.js +0 -2
  104. package/dist/lib/RedirectModifier.d.ts +0 -4
  105. package/dist/lib/ResultConsumer.d.ts +0 -4
  106. package/dist/lib/SingleRedirectModifier.d.ts +0 -4
  107. package/dist/lib/StringReader.d.ts +0 -27
  108. package/dist/lib/arguments/ArgumentType.d.ts +0 -21
  109. package/dist/lib/arguments/BoolArgumentType.d.ts +0 -13
  110. package/dist/lib/arguments/FloatArgumentType.d.ts +0 -16
  111. package/dist/lib/arguments/IntegerArgumentType.d.ts +0 -16
  112. package/dist/lib/arguments/StringArgumentType.d.ts +0 -21
  113. package/dist/lib/builder/ArgumentBuilder.d.ts +0 -28
  114. package/dist/lib/builder/LiteralArgumentBuilder.d.ts +0 -11
  115. package/dist/lib/builder/RequiredArgumentBuilder.d.ts +0 -18
  116. package/dist/lib/context/CommandContext.d.ts +0 -33
  117. package/dist/lib/context/CommandContextBuilder.d.ts +0 -38
  118. package/dist/lib/context/ParsedArgument.d.ts +0 -9
  119. package/dist/lib/context/ParsedCommandNode.d.ts +0 -11
  120. package/dist/lib/context/StringRange.d.ts +0 -16
  121. package/dist/lib/context/SuggestionContext.d.ts +0 -6
  122. package/dist/lib/exceptions/BuiltInExceptionProvider.d.ts +0 -23
  123. package/dist/lib/exceptions/BuiltInExceptions.d.ts +0 -43
  124. package/dist/lib/exceptions/CommandExceptionType.d.ts +0 -2
  125. package/dist/lib/exceptions/CommandSyntaxException.d.ts +0 -19
  126. package/dist/lib/exceptions/Dynamic2CommandExceptionType.js +0 -19
  127. package/dist/lib/exceptions/DynamicCommandExceptionType.d.ts +0 -10
  128. package/dist/lib/exceptions/SimpleCommandExceptionType.d.ts +0 -11
  129. package/dist/lib/suggestion/IntegerSuggestion.d.ts +0 -12
  130. package/dist/lib/suggestion/Suggestion.d.ts +0 -17
  131. package/dist/lib/suggestion/SuggestionProvider.d.ts +0 -6
  132. package/dist/lib/suggestion/Suggestions.d.ts +0 -16
  133. package/dist/lib/suggestion/SuggestionsBuilder.d.ts +0 -18
  134. package/dist/lib/tree/ArgumentCommandNode.d.ts +0 -31
  135. package/dist/lib/tree/CommandNode.d.ts +0 -45
  136. package/dist/lib/tree/LiteralCommandNode.d.ts +0 -27
  137. package/dist/lib/tree/RootCommandNode.d.ts +0 -21
  138. package/dist/lib/util/isEqual.d.ts +0 -1
  139. package/example/fill.js +0 -47
  140. package/example/fill.ts +0 -50
  141. package/src/index.ts +0 -50
  142. package/src/lib/AmbiguityConsumer.ts +0 -6
  143. package/src/lib/Command.ts +0 -5
  144. package/src/lib/CommandDispatcher.ts +0 -390
  145. package/src/lib/ImmutableStringReader.ts +0 -22
  146. package/src/lib/LiteralMessage.ts +0 -17
  147. package/src/lib/Message.ts +0 -3
  148. package/src/lib/ParseResults.ts +0 -32
  149. package/src/lib/Predicate.ts +0 -3
  150. package/src/lib/RedirectModifier.ts +0 -5
  151. package/src/lib/ResultConsumer.ts +0 -6
  152. package/src/lib/SingleRedirectModifier.ts +0 -6
  153. package/src/lib/StringReader.ts +0 -210
  154. package/src/lib/arguments/ArgumentType.ts +0 -27
  155. package/src/lib/arguments/BoolArgumentType.ts +0 -41
  156. package/src/lib/arguments/FloatArgumentType.ts +0 -75
  157. package/src/lib/arguments/IntegerArgumentType.ts +0 -75
  158. package/src/lib/arguments/StringArgumentType.ts +0 -83
  159. package/src/lib/builder/ArgumentBuilder.ts +0 -94
  160. package/src/lib/builder/LiteralArgumentBuilder.ts +0 -35
  161. package/src/lib/builder/RequiredArgumentBuilder.ts +0 -54
  162. package/src/lib/context/CommandContext.ts +0 -118
  163. package/src/lib/context/CommandContextBuilder.ts +0 -155
  164. package/src/lib/context/ParsedArgument.ts +0 -27
  165. package/src/lib/context/ParsedCommandNode.ts +0 -35
  166. package/src/lib/context/StringRange.ts +0 -57
  167. package/src/lib/context/SuggestionContext.ts +0 -12
  168. package/src/lib/exceptions/BuiltInExceptionProvider.ts +0 -43
  169. package/src/lib/exceptions/BuiltInExceptions.ts +0 -121
  170. package/src/lib/exceptions/CommandExceptionType.ts +0 -2
  171. package/src/lib/exceptions/CommandSyntaxException.ts +0 -77
  172. package/src/lib/exceptions/DynamicCommandExceptionType.ts +0 -22
  173. package/src/lib/exceptions/SimpleCommandExceptionType.ts +0 -26
  174. package/src/lib/suggestion/IntegerSuggestion.ts +0 -46
  175. package/src/lib/suggestion/Suggestion.ts +0 -87
  176. package/src/lib/suggestion/SuggestionProvider.ts +0 -7
  177. package/src/lib/suggestion/Suggestions.ts +0 -85
  178. package/src/lib/suggestion/SuggestionsBuilder.ts +0 -69
  179. package/src/lib/tree/ArgumentCommandNode.ts +0 -118
  180. package/src/lib/tree/CommandNode.ts +0 -200
  181. package/src/lib/tree/LiteralCommandNode.ts +0 -111
  182. package/src/lib/tree/RootCommandNode.ts +0 -62
  183. package/src/lib/util/isEqual.ts +0 -75
  184. package/test/CommandDispatcherTest.ts +0 -427
  185. package/test/CommandDispatcherUsagesTest.ts +0 -163
  186. package/test/CommandSuggestionsTest.ts +0 -283
  187. package/test/StringReaderTest.ts +0 -391
  188. package/test/arguments/BoolArgumentTypeTest.ts +0 -18
  189. package/test/arguments/FloatArgumentTypeTest.ts +0 -61
  190. package/test/arguments/IntegerArgumentTypeTest.ts +0 -63
  191. package/test/arguments/StringArgumentTypeTest.ts +0 -61
  192. package/test/benchmarks/ExecuteBenchmark.js +0 -33
  193. package/test/benchmarks/ParsingBenchmark.js +0 -96
  194. package/test/builder/ArgumentBuilderTest.ts +0 -61
  195. package/test/builder/LiteralArgumentBuilderTest.ts +0 -37
  196. package/test/builder/RequiredArgumentBuilderTest.ts +0 -40
  197. package/test/context/CommandContextTest.ts +0 -77
  198. package/test/context/ParsedArgumentTest.ts +0 -19
  199. package/test/exceptions/DynamicCommandSyntaxExceptionTypeTest.ts +0 -18
  200. package/test/exceptions/SimpleCommandSyntaxExceptionTypeTest.ts +0 -33
  201. package/test/suggestion/SuggestionBuilderTest.ts +0 -66
  202. package/test/suggestion/SuggestionTest.ts +0 -65
  203. package/test/suggestion/SuggestionsTest.ts +0 -24
  204. package/test/tree/AbstractCommandNodeTest.ts +0 -57
  205. package/test/tree/ArgumentCommandNodeTest.ts +0 -81
  206. package/test/tree/LiteralCommandNodeTest.ts +0 -112
  207. package/test/tree/RootCommandNodeTest.ts +0 -70
  208. package/test/utils/testEquality.ts +0 -10
  209. package/tsconfig.json +0 -40
  210. package/tsconfig.tsbuildinfo +0 -1578
@@ -1,118 +0,0 @@
1
- import isEqual from "../util/isEqual"
2
- import Command from "../Command"
3
- import RedirectModifier from "../RedirectModifier"
4
- import CommandNode from "../tree/CommandNode"
5
- import StringRange from "./StringRange"
6
- import ParsedArgument from "./ParsedArgument"
7
- import ParsedCommandNode from "./ParsedCommandNode"
8
-
9
- export default class CommandContext<S> {
10
-
11
- private source: S;
12
- private input: string;
13
- private command: Command<S>;
14
- private args: Map<String, ParsedArgument<S, any>>;
15
- private rootNode: CommandNode<S>;
16
- private nodes: Array<ParsedCommandNode<S>>;
17
- private range: StringRange;
18
- private child: CommandContext<S>;
19
- private modifier: RedirectModifier<S>;
20
- private forks: boolean;
21
-
22
- public constructor (source: S, input: string, args: Map<String, ParsedArgument<S, any>>, command: Command<S>, rootNode: CommandNode<S>, nodes: Array<ParsedCommandNode<S>>, range: StringRange, child: CommandContext<S>, modifier: RedirectModifier<S>, forks: boolean) {
23
- this.source = source;
24
- this.input = input;
25
- this.args = args;
26
- this.command = command;
27
- this.rootNode = rootNode;
28
- this.nodes = nodes;
29
- this.range = range;
30
- this.child = child;
31
- this.modifier = modifier;
32
- this.forks = forks;
33
- }
34
-
35
- public copyFor(source: S): CommandContext<S> {
36
- if (this.source === source)
37
- return this;
38
-
39
- return new CommandContext<S>(source, this.input, this.args, this.command, this.rootNode, this.nodes, this.range, this.child, this.modifier, this.forks);
40
- }
41
-
42
- public getChild(): CommandContext<S> {
43
- return this.child;
44
- }
45
-
46
- public getLastChild(): CommandContext<S> {
47
- let result: CommandContext<S> = this;
48
- while (!(result.getChild() == null)) {
49
- result = result.getChild();
50
- }
51
- return result;
52
- }
53
-
54
- public getCommand(): Command<S> {
55
- return this.command;
56
- }
57
-
58
- public getSource(): S {
59
- return this.source;
60
- }
61
-
62
- public getArgument(name: string, clazz?: Function): any {
63
- const arg: ParsedArgument<S, any> = this.args.get(name);
64
-
65
- if (arg == null) {
66
- throw new Error("No such argument '" + name + "' exists on this command");
67
- }
68
-
69
- let result = arg.getResult();
70
- if (clazz == null) {
71
- return result;
72
- } else {
73
- return clazz(result);
74
- }
75
- }
76
-
77
- public equals(o: object): boolean {
78
- if (this === o) return true;
79
- if (!(o instanceof CommandContext)) return false;
80
-
81
- if (!isEqual(this.args, o.args)) return false;
82
- if (!this.rootNode.equals(o.rootNode)) return false;
83
- if (this.nodes.length != o.nodes.length || !isEqual(this.nodes, o.nodes)) return false;
84
- if (!(this.command == null) ? !isEqual(this.command, o.command) : o.command != null) return false;
85
- if (!isEqual(this.source, o.source)) return false;
86
- if (!(this.child == null) ? !this.child.equals(o.child) : o.child != null) return false;
87
-
88
- return true;
89
- }
90
-
91
- public getRedirectModifier(): RedirectModifier<S> {
92
- return this.modifier;
93
- }
94
-
95
- public getRange(): StringRange {
96
- return this.range;
97
- }
98
-
99
- public getInput(): string {
100
- return this.input;
101
- }
102
-
103
- public getRootNode(): CommandNode<S> {
104
- return this.rootNode;
105
- }
106
-
107
- public getNodes(): Array<ParsedCommandNode<S>> {
108
- return this.nodes;
109
- }
110
-
111
- public hasNodes(): boolean {
112
- return this.nodes.length >= 0
113
- }
114
-
115
- public isForked(): boolean {
116
- return this.forks;
117
- }
118
- }
@@ -1,155 +0,0 @@
1
- import Command from "../Command"
2
- import StringRange from "./StringRange"
3
- import CommandNode from "../tree/CommandNode"
4
- import CommandContext from "./CommandContext"
5
- import ParsedArgument from "./ParsedArgument"
6
- import SuggestionContext from "./SuggestionContext"
7
- import ParsedCommandNode from "./ParsedCommandNode"
8
- import CommandDispatcher from "../CommandDispatcher"
9
- import RedirectModifier from "../RedirectModifier"
10
-
11
- export default class CommandContextBuilder<S> {
12
-
13
- private args: Map<String, ParsedArgument<S, any>> = new Map();
14
-
15
- private rootNode: CommandNode<S>;
16
-
17
- private nodes: Array<ParsedCommandNode<S>> = [];
18
-
19
- private dispatcher: CommandDispatcher<S>;
20
-
21
- private source: S;
22
-
23
- private command: Command<S>;
24
-
25
- private child: CommandContextBuilder<S>;
26
-
27
- private range: StringRange;
28
-
29
- private modifier: RedirectModifier<S> = null;
30
-
31
- private forks: boolean;
32
-
33
- public constructor (dispatcher: CommandDispatcher<S>, source: S, rootNode: CommandNode<S>, start: number) {
34
- this.rootNode = rootNode;
35
- this.dispatcher = dispatcher;
36
- this.source = source;
37
- this.range = StringRange.at(start);
38
- }
39
-
40
- public withSource(source: S): CommandContextBuilder<S> {
41
- this.source = source;
42
- return this;
43
- }
44
-
45
- public getSource(): S {
46
- return this.source;
47
- }
48
-
49
- public getRootNode(): CommandNode<S> {
50
- return this.rootNode;
51
- }
52
-
53
- public withArgument(name: String, argument: ParsedArgument<S, any>): CommandContextBuilder<S> {
54
- this.args.set(name, argument);
55
- return this;
56
- }
57
-
58
- public getArguments(): Map<String, ParsedArgument<S, any>> {
59
- return this.args;
60
- }
61
-
62
- public withCommand(command: Command<S>): CommandContextBuilder<S> {
63
- this.command = command;
64
- return this;
65
- }
66
-
67
- public withNode(node: CommandNode<S>, range: StringRange): CommandContextBuilder<S> {
68
- this.nodes.push(new ParsedCommandNode(node, range));
69
- this.range = StringRange.encompassing(this.range, range);
70
- this.modifier = node.getRedirectModifier();
71
- this.forks = node.isFork();
72
- return this;
73
- }
74
-
75
- public copy(): CommandContextBuilder<S> {
76
- const copy: CommandContextBuilder<S> = new CommandContextBuilder(this.dispatcher, this.source, this.rootNode, this.range.getStart());
77
- copy.command = this.command;
78
- copy.args = new Map([...copy.args, ...this.args])
79
- copy.nodes.push(...this.nodes);
80
- copy.child = this.child;
81
- copy.range = this.range;
82
- copy.forks = this.forks;
83
- return copy;
84
- }
85
-
86
- public withChild(child: CommandContextBuilder<S>): CommandContextBuilder<S> {
87
- this.child = child;
88
- return this;
89
- }
90
-
91
- public getChild(): CommandContextBuilder<S> {
92
- return this.child;
93
- }
94
-
95
- public getLastChild(): CommandContextBuilder<S> {
96
- let result: CommandContextBuilder<S> = this;
97
- while (result.getChild() != null) {
98
- result = result.getChild();
99
- }
100
-
101
- return result;
102
- }
103
-
104
- public getCommand(): Command<S> {
105
- return this.command;
106
- }
107
-
108
- public getNodes(): Array<ParsedCommandNode<S>> {
109
- return this.nodes;
110
- }
111
-
112
- public build(input: string): CommandContext<S> {
113
- return new CommandContext<S>(this.source, input, this.args, this.command, this.rootNode, this.nodes, this.range, this.child == null ? null : this.child.build(input), this.modifier, this.forks);
114
- }
115
-
116
- public getDispatcher(): CommandDispatcher<S> {
117
- return this.dispatcher;
118
- }
119
-
120
- public getRange(): StringRange {
121
- return this.range;
122
- }
123
-
124
- public findSuggestionContext(cursor: number): SuggestionContext<S> {
125
- if ((this.range.getStart() <= cursor)) {
126
- if ((this.range.getEnd() < cursor)) {
127
- if ((this.child != null)) {
128
- return this.child.findSuggestionContext(cursor);
129
- }
130
- else if (this.nodes.length > 0) {
131
- let last: ParsedCommandNode<S> = this.nodes[this.nodes.length - 1];
132
- return new SuggestionContext(last.getNode(), last.getRange().getEnd() + 1);
133
- }
134
- else {
135
- return new SuggestionContext(this.rootNode, this.range.getStart());
136
- }
137
- }
138
- else {
139
- let prev: CommandNode<S> = this.rootNode;
140
- for (let node of this.nodes) {
141
- let nodeRange: StringRange = node.getRange();
142
- if (nodeRange.getStart() <= cursor && cursor <= nodeRange.getEnd()) {
143
- return new SuggestionContext(prev, nodeRange.getStart());
144
- }
145
- prev = node.getNode();
146
- }
147
- if ((prev == null)) {
148
- throw new Error("Can't find node before cursor");
149
- }
150
- return new SuggestionContext(prev, this.range.getStart());
151
- }
152
- }
153
- throw new Error("Can't find node before cursor");
154
- }
155
- }
@@ -1,27 +0,0 @@
1
- import StringRange from "./StringRange"
2
-
3
- export default class ParsedArgument<S, T> {
4
-
5
- private range: StringRange;
6
- private result: T;
7
-
8
- public constructor (start: number, end: number, result: T) {
9
- this.range = StringRange.between(start, end);
10
- this.result = result;
11
- }
12
-
13
- public getRange(): StringRange {
14
- return this.range;
15
- }
16
-
17
- public getResult(): T {
18
- return this.result;
19
- }
20
-
21
- public equals(o: object): boolean {
22
- if (this === o) return true;
23
- if (!(o instanceof ParsedArgument)) return false;
24
-
25
- return this.range.equals(o.range) && this.result === o.result;
26
- }
27
- }
@@ -1,35 +0,0 @@
1
- import CommandNode from "../tree/CommandNode"
2
- import StringRange from "./StringRange"
3
-
4
- export default class ParsedCommandNode<S> {
5
-
6
- private node: CommandNode<S>;
7
- private range: StringRange;
8
-
9
- public constructor (node: CommandNode<S>, range: StringRange) {
10
- this.node = node;
11
- this.range = range;
12
- }
13
-
14
- public getNode(): CommandNode<S> {
15
- return this.node;
16
- }
17
-
18
- public getRange(): StringRange {
19
- return this.range;
20
- }
21
-
22
- public toString(): String {
23
- return this.node + "@" + this.range;
24
- }
25
-
26
- public equals(o: object): boolean {
27
- if (this === o) return true;
28
-
29
- if (o == null || !(o instanceof ParsedCommandNode)) {
30
- return false;
31
- }
32
-
33
- return this.node.equals(o.node) && this.range.equals(o.range);
34
- }
35
- }
@@ -1,57 +0,0 @@
1
- import ImmutableStringReader from "../ImmutableStringReader"
2
-
3
- export default class StringRange {
4
-
5
- private start: number;
6
- private end: number;
7
-
8
- public constructor (start: number, end: number) {
9
- this.start = start;
10
- this.end = end;
11
- }
12
-
13
- public static at(pos: number): StringRange {
14
- return new StringRange(pos, pos);
15
- }
16
-
17
- public static between(start: number, end: number): StringRange {
18
- return new StringRange(start, end);
19
- }
20
-
21
- public static encompassing(a: StringRange, b: StringRange): StringRange {
22
- return new StringRange(Math.min(a.getStart(), b.getStart()), Math.max(a.getEnd(), b.getEnd()));
23
- }
24
-
25
- public getStart(): number {
26
- return this.start;
27
- }
28
-
29
- public getEnd(): number {
30
- return this.end;
31
- }
32
-
33
- public get(str: ImmutableStringReader | string): string {
34
- if (typeof str === "string")
35
- return str.substring(this.start, this.end);
36
- else
37
- return str.getString().substring(this.start, this.end);
38
- }
39
-
40
- public isEmpty(): boolean {
41
- return this.start === this.end;
42
- }
43
-
44
- public getLength(): number {
45
- return this.end - this.start;
46
- }
47
-
48
- public equals(o: object): boolean {
49
- if (this === o) return true;
50
- if (!(o instanceof StringRange)) return false;
51
- return this.start === o.start && this.end == o.end;
52
- }
53
-
54
- public toString(): string {
55
- return "StringRange{" + "start=" + this.start + ", end=" + this.end + '}';
56
- }
57
- }
@@ -1,12 +0,0 @@
1
- import CommandNode from "../tree/CommandNode"
2
-
3
- export default class SuggestionContext<S> {
4
-
5
- public parent: CommandNode<S>;
6
- public startPos: number;
7
-
8
- public constructor (parent: CommandNode<S>, startPos: number) {
9
- this.parent = parent;
10
- this.startPos = startPos;
11
- }
12
- }
@@ -1,43 +0,0 @@
1
- import DynamicCommandExceptionType from "./DynamicCommandExceptionType"
2
- import SimpleCommandExceptionType from "./SimpleCommandExceptionType"
3
-
4
- export default interface BuiltInExceptionProvider {
5
-
6
- floatTooLow(): DynamicCommandExceptionType;
7
-
8
- floatTooHigh(): DynamicCommandExceptionType;
9
-
10
- integerTooLow(): DynamicCommandExceptionType;
11
-
12
- integerTooHigh(): DynamicCommandExceptionType;
13
-
14
- literalIncorrect(): DynamicCommandExceptionType;
15
-
16
- readerExpectedStartOfQuote(): SimpleCommandExceptionType;
17
-
18
- readerExpectedEndOfQuote(): SimpleCommandExceptionType;
19
-
20
- readerInvalidEscape(): DynamicCommandExceptionType;
21
-
22
- readerInvalidBool(): DynamicCommandExceptionType;
23
-
24
- readerInvalidInt(): DynamicCommandExceptionType;
25
-
26
- readerExpectedInt(): SimpleCommandExceptionType;
27
-
28
- readerInvalidFloat(): DynamicCommandExceptionType;
29
-
30
- readerExpectedFloat(): SimpleCommandExceptionType;
31
-
32
- readerExpectedBool(): SimpleCommandExceptionType;
33
-
34
- readerExpectedSymbol(): DynamicCommandExceptionType;
35
-
36
- dispatcherUnknownCommand(): SimpleCommandExceptionType;
37
-
38
- dispatcherUnknownArgument(): SimpleCommandExceptionType;
39
-
40
- dispatcherExpectedArgumentSeparator(): SimpleCommandExceptionType;
41
-
42
- dispatcherParseException(): DynamicCommandExceptionType;
43
- }
@@ -1,121 +0,0 @@
1
- import LiteralMessage from "../LiteralMessage"
2
- import BuiltInExceptionProvider from "./BuiltInExceptionProvider"
3
- import SimpleCommandExceptionType from "./SimpleCommandExceptionType"
4
- import DynamicCommandExceptionType from "./DynamicCommandExceptionType"
5
-
6
- export default class BuiltInExceptions implements BuiltInExceptionProvider {
7
-
8
- private static FLOAT_TOO_SMALL = new DynamicCommandExceptionType((found, min) => new LiteralMessage("Float must not be less than " + min + ", found " + found));
9
-
10
- private static FLOAT_TOO_BIG = new DynamicCommandExceptionType((found, max) => new LiteralMessage("Float must not be more than " + max + ", found " + found));
11
-
12
- private static INTEGER_TOO_SMALL = new DynamicCommandExceptionType((found, min) => new LiteralMessage("Integer must not be less than " + min + ", found " + found));
13
-
14
- private static INTEGER_TOO_BIG = new DynamicCommandExceptionType((found, max) => new LiteralMessage("Integer must not be more than " + max + ", found " + found));
15
-
16
- private static LITERAL_INCORRECT: DynamicCommandExceptionType = new DynamicCommandExceptionType(expected => new LiteralMessage("Expected literal " + expected));
17
-
18
- private static READER_EXPECTED_START_OF_QUOTE: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Expected quote to start a string"));
19
-
20
- private static READER_EXPECTED_END_OF_QUOTE: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Unclosed quoted string"));
21
-
22
- private static READER_INVALID_ESCAPE: DynamicCommandExceptionType = new DynamicCommandExceptionType(character => new LiteralMessage("Invalid escape sequence '" + character + "' in quoted string"));
23
-
24
- private static READER_INVALID_BOOL: DynamicCommandExceptionType = new DynamicCommandExceptionType(value => new LiteralMessage("Invalid bool, expected true or false but found '" + value + "'"));
25
-
26
- private static READER_INVALID_INT: DynamicCommandExceptionType = new DynamicCommandExceptionType(value => new LiteralMessage("Invalid integer '" + value + "'"));
27
-
28
- private static READER_EXPECTED_INT: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Expected integer"));
29
-
30
- private static READER_INVALID_FLOAT: DynamicCommandExceptionType = new DynamicCommandExceptionType(value => new LiteralMessage("Invalid float '" + value + "'"));
31
-
32
- private static READER_EXPECTED_FLOAT: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Expected float"));
33
-
34
- private static READER_EXPECTED_BOOL: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Expected bool"));
35
-
36
- private static READER_EXPECTED_SYMBOL: DynamicCommandExceptionType = new DynamicCommandExceptionType(symbol => new LiteralMessage("Expected '" + symbol + "'"));
37
-
38
- private static DISPATCHER_UNKNOWN_COMMAND: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Unknown command"));
39
-
40
- private static DISPATCHER_UNKNOWN_ARGUMENT: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Incorrect argument for command"));
41
-
42
- private static DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR: SimpleCommandExceptionType = new SimpleCommandExceptionType(new LiteralMessage("Expected whitespace to end one argument, but found trailing data"));
43
-
44
- private static DISPATCHER_PARSE_EXCEPTION: DynamicCommandExceptionType = new DynamicCommandExceptionType(message => new LiteralMessage(("Could not parse command: " + message)));
45
-
46
- public floatTooLow(): DynamicCommandExceptionType {
47
- return BuiltInExceptions.FLOAT_TOO_SMALL;
48
- }
49
-
50
- public floatTooHigh(): DynamicCommandExceptionType {
51
- return BuiltInExceptions.FLOAT_TOO_BIG;
52
- }
53
-
54
- public integerTooLow(): DynamicCommandExceptionType {
55
- return BuiltInExceptions.INTEGER_TOO_SMALL;
56
- }
57
-
58
- public integerTooHigh(): DynamicCommandExceptionType {
59
- return BuiltInExceptions.INTEGER_TOO_BIG;
60
- }
61
-
62
- public literalIncorrect(): DynamicCommandExceptionType {
63
- return BuiltInExceptions.LITERAL_INCORRECT;
64
- }
65
-
66
- public readerExpectedStartOfQuote(): SimpleCommandExceptionType {
67
- return BuiltInExceptions.READER_EXPECTED_START_OF_QUOTE;
68
- }
69
-
70
- public readerExpectedEndOfQuote(): SimpleCommandExceptionType {
71
- return BuiltInExceptions.READER_EXPECTED_END_OF_QUOTE;
72
- }
73
-
74
- public readerInvalidEscape(): DynamicCommandExceptionType {
75
- return BuiltInExceptions.READER_INVALID_ESCAPE;
76
- }
77
-
78
- public readerInvalidBool(): DynamicCommandExceptionType {
79
- return BuiltInExceptions.READER_INVALID_BOOL;
80
- }
81
-
82
- public readerInvalidInt(): DynamicCommandExceptionType {
83
- return BuiltInExceptions.READER_INVALID_INT;
84
- }
85
-
86
- public readerExpectedInt(): SimpleCommandExceptionType {
87
- return BuiltInExceptions.READER_EXPECTED_INT;
88
- }
89
-
90
- public readerInvalidFloat(): DynamicCommandExceptionType {
91
- return BuiltInExceptions.READER_INVALID_FLOAT;
92
- }
93
-
94
- public readerExpectedFloat(): SimpleCommandExceptionType {
95
- return BuiltInExceptions.READER_EXPECTED_FLOAT;
96
- }
97
-
98
- public readerExpectedBool(): SimpleCommandExceptionType {
99
- return BuiltInExceptions.READER_EXPECTED_BOOL;
100
- }
101
-
102
- public readerExpectedSymbol(): DynamicCommandExceptionType {
103
- return BuiltInExceptions.READER_EXPECTED_SYMBOL;
104
- }
105
-
106
- public dispatcherUnknownCommand(): SimpleCommandExceptionType {
107
- return BuiltInExceptions.DISPATCHER_UNKNOWN_COMMAND;
108
- }
109
-
110
- public dispatcherUnknownArgument(): SimpleCommandExceptionType {
111
- return BuiltInExceptions.DISPATCHER_UNKNOWN_ARGUMENT;
112
- }
113
-
114
- public dispatcherExpectedArgumentSeparator(): SimpleCommandExceptionType {
115
- return BuiltInExceptions.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR;
116
- }
117
-
118
- public dispatcherParseException(): DynamicCommandExceptionType {
119
- return BuiltInExceptions.DISPATCHER_PARSE_EXCEPTION;
120
- }
121
- }
@@ -1,2 +0,0 @@
1
- export default interface CommandExceptionType {
2
- }
@@ -1,77 +0,0 @@
1
- import Message from "../Message"
2
- import BuiltInExceptions from "./BuiltInExceptions"
3
- import BuiltInExceptionProvider from "./BuiltInExceptionProvider"
4
- import CommandExceptionType from "./CommandExceptionType"
5
-
6
- export default class CommandSyntaxException extends Error {
7
-
8
- public static CONTEXT_AMOUNT = 10;
9
- public static BUILT_IN_EXCEPTIONS: BuiltInExceptionProvider = new BuiltInExceptions();
10
-
11
- private type: CommandExceptionType;
12
- private __message: Message;
13
- private input: string;
14
- private cursor: number;
15
-
16
- public constructor (type: CommandExceptionType, message: Message, input: string = null, cursor = -1) {
17
- super(message.getString());
18
- Error.captureStackTrace(this, CommandSyntaxException)
19
- this.type = type;
20
- this.__message = message;
21
- this.input = input;
22
- this.cursor = cursor;
23
-
24
- this.message = this.getMessage();
25
- }
26
-
27
- public getMessage(): string {
28
- let message = this.__message.getString();
29
- let context = this.getContext();
30
- if (context != null) {
31
- message += " at position " + this.cursor + ": " + context;
32
- }
33
- return message;
34
- }
35
-
36
- public getRawMessage(): Message {
37
- return this.__message;
38
- }
39
-
40
- public getContext(): string {
41
- if (this.input == null || this.cursor < 0) {
42
- return null;
43
- }
44
-
45
- let builder = ""
46
- let cursor = Math.min(this.input.length, this.cursor);
47
- if (cursor > CommandSyntaxException.CONTEXT_AMOUNT) {
48
- builder += "...";
49
- }
50
-
51
- builder += this.input.substring(
52
- Math.max(
53
- 0,
54
- cursor - CommandSyntaxException.CONTEXT_AMOUNT
55
- ),
56
- cursor
57
- );
58
- builder += "<--[HERE]";
59
- return builder;
60
- }
61
-
62
- public getType(): CommandExceptionType {
63
- return this.type;
64
- }
65
-
66
- public getInput(): string {
67
- return this.input;
68
- }
69
-
70
- public getCursor(): number {
71
- return this.cursor;
72
- }
73
-
74
- public toString(): string {
75
- return this.message;
76
- }
77
- }
@@ -1,22 +0,0 @@
1
- import Message from "../Message"
2
- import CommandExceptionType from "./CommandExceptionType"
3
- import CommandSyntaxException from "./CommandSyntaxException"
4
- import ImmutableStringReader from "../ImmutableStringReader"
5
-
6
- export default class DynamicCommandExceptionType implements CommandExceptionType {
7
-
8
- private fn: Function;
9
-
10
- public constructor(fn: (...args: any[]) => Message) {
11
- this.fn = fn;
12
- Error.captureStackTrace(this, DynamicCommandExceptionType)
13
- }
14
-
15
- public create(...args: any[]): CommandSyntaxException {
16
- return new CommandSyntaxException(this, this.fn(...args));
17
- }
18
-
19
- public createWithContext(reader: ImmutableStringReader, ...args: any[]): CommandSyntaxException {
20
- return new CommandSyntaxException(this, this.fn(...args), reader.getString(), reader.getCursor());
21
- }
22
- }