@wq2/brigadier-ts 1.0.4 → 1.0.6
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.
- package/dist/CommandDispatcher.d.ts +7 -1
- package/dist/CommandDispatcher.js +27 -20
- package/dist/StringReader.js +11 -11
- package/dist/arguments/FloatArgumentType.js +3 -3
- package/dist/arguments/IntegerArgumentType.js +3 -3
- package/dist/arguments/LongArgumentType.js +3 -3
- package/dist/exceptions/CommandSyntaxError.d.ts +0 -23
- package/dist/exceptions/CommandSyntaxError.js +0 -23
- package/dist/exceptions/StandardErrorTypes.d.ts +23 -0
- package/dist/exceptions/StandardErrorTypes.js +26 -0
- package/dist/tree/LiteralCommandNode.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/CommandDispatcher.ts +16 -26
- package/src/StringReader.ts +11 -28
- package/src/arguments/FloatArgumentType.ts +3 -3
- package/src/arguments/IntegerArgumentType.ts +3 -3
- package/src/arguments/LongArgumentType.ts +3 -3
- package/src/exceptions/CommandSyntaxError.ts +0 -65
- package/src/exceptions/StandardErrorTypes.ts +68 -0
- package/src/tree/LiteralCommandNode.ts +2 -2
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
|
|
2
|
+
import { ParseResults } from "./ParseResults";
|
|
3
|
+
import { StringReader } from "./StringReader";
|
|
4
|
+
import { Suggestions } from "./suggestion/Suggestions";
|
|
5
|
+
import type { CommandNode } from "./tree/CommandNode";
|
|
6
|
+
import type { LiteralCommandNode } from "./tree/LiteralCommandNode";
|
|
7
|
+
import { RootCommandNode } from "./tree/RootCommandNode";
|
|
2
8
|
export declare class CommandDispatcher<S> {
|
|
3
9
|
private root;
|
|
4
10
|
private static USAGE_OPTIONAL_OPEN;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandDispatcher = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandContextBuilder_1 = require("./context/CommandContextBuilder");
|
|
5
|
+
const CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
|
|
6
|
+
const StandardErrorTypes_1 = require("./exceptions/StandardErrorTypes");
|
|
7
|
+
const ParseResults_1 = require("./ParseResults");
|
|
8
|
+
const StringReader_1 = require("./StringReader");
|
|
9
|
+
const Suggestions_1 = require("./suggestion/Suggestions");
|
|
10
|
+
const SuggestionsBuilder_1 = require("./suggestion/SuggestionsBuilder");
|
|
11
|
+
const RootCommandNode_1 = require("./tree/RootCommandNode");
|
|
5
12
|
class CommandDispatcher {
|
|
6
13
|
constructor() {
|
|
7
|
-
this.root = new
|
|
14
|
+
this.root = new RootCommandNode_1.RootCommandNode();
|
|
8
15
|
}
|
|
9
16
|
register(command) {
|
|
10
17
|
const build = command.build();
|
|
@@ -13,17 +20,17 @@ class CommandDispatcher {
|
|
|
13
20
|
}
|
|
14
21
|
async execute(parse, source) {
|
|
15
22
|
if (typeof parse === "string") {
|
|
16
|
-
parse = await this.parse(new
|
|
23
|
+
parse = await this.parse(new StringReader_1.StringReader(parse), source);
|
|
17
24
|
}
|
|
18
25
|
if (parse.getReader().canRead()) {
|
|
19
26
|
if (parse.getErrors().size === 1) {
|
|
20
27
|
throw parse.getErrors().values().next();
|
|
21
28
|
}
|
|
22
29
|
else if (parse.getContext().getRange().isEmpty()) {
|
|
23
|
-
throw
|
|
30
|
+
throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
24
31
|
}
|
|
25
32
|
else {
|
|
26
|
-
throw
|
|
33
|
+
throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
let result = 0;
|
|
@@ -78,13 +85,13 @@ class CommandDispatcher {
|
|
|
78
85
|
next = [];
|
|
79
86
|
}
|
|
80
87
|
if (!foundCommand) {
|
|
81
|
-
throw
|
|
88
|
+
throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
82
89
|
}
|
|
83
90
|
return forked ? successfulForks : result;
|
|
84
91
|
}
|
|
85
92
|
async parse(reader, source) {
|
|
86
|
-
reader = new
|
|
87
|
-
const context = new
|
|
93
|
+
reader = new StringReader_1.StringReader(reader);
|
|
94
|
+
const context = new CommandContextBuilder_1.CommandContextBuilder(this, source, this.root, reader.getCursor());
|
|
88
95
|
return this.parseNodes(this.root, reader, context);
|
|
89
96
|
}
|
|
90
97
|
async parseNodes(node, originalReader, contextSoFar) {
|
|
@@ -97,25 +104,25 @@ class CommandDispatcher {
|
|
|
97
104
|
continue;
|
|
98
105
|
}
|
|
99
106
|
const context = contextSoFar.copy();
|
|
100
|
-
const reader = new
|
|
107
|
+
const reader = new StringReader_1.StringReader(originalReader);
|
|
101
108
|
try {
|
|
102
109
|
try {
|
|
103
110
|
child.parse(reader, context);
|
|
104
111
|
}
|
|
105
112
|
catch (e) {
|
|
106
|
-
if (e instanceof
|
|
113
|
+
if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
|
|
107
114
|
throw e;
|
|
108
115
|
}
|
|
109
116
|
else {
|
|
110
|
-
throw
|
|
117
|
+
throw StandardErrorTypes_1.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
120
|
if (reader.canRead() && reader.peek() !== " ") {
|
|
114
|
-
throw
|
|
121
|
+
throw StandardErrorTypes_1.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
catch (e) {
|
|
118
|
-
if (e instanceof
|
|
125
|
+
if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
|
|
119
126
|
errors.set(child, e);
|
|
120
127
|
reader.setCursor(cursor);
|
|
121
128
|
continue;
|
|
@@ -128,21 +135,21 @@ class CommandDispatcher {
|
|
|
128
135
|
if (reader.canRead(child.getRedirect() === null ? 2 : 1)) {
|
|
129
136
|
reader.skip();
|
|
130
137
|
if (child.getRedirect()) {
|
|
131
|
-
const childContext = new
|
|
138
|
+
const childContext = new CommandContextBuilder_1.CommandContextBuilder(this, source, child.getRedirect(), reader.getCursor());
|
|
132
139
|
const parse = await this.parseNodes(child.getRedirect(), reader, childContext);
|
|
133
140
|
context.withChild(parse.getContext());
|
|
134
|
-
return new
|
|
141
|
+
return new ParseResults_1.ParseResults(context, parse.getReader(), parse.getErrors());
|
|
135
142
|
}
|
|
136
143
|
else {
|
|
137
144
|
potentials.push(this.parseNodes(child, reader, context));
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
else {
|
|
141
|
-
potentials.push(new
|
|
148
|
+
potentials.push(new ParseResults_1.ParseResults(context, reader, new Map()));
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
if (potentials.length === 0) {
|
|
145
|
-
potentials.push(new
|
|
152
|
+
potentials.push(new ParseResults_1.ParseResults(contextSoFar, originalReader, errors));
|
|
146
153
|
}
|
|
147
154
|
return potentials[0];
|
|
148
155
|
}
|
|
@@ -187,9 +194,9 @@ class CommandDispatcher {
|
|
|
187
194
|
const truncatedInput = fullInput.substring(0, cursor);
|
|
188
195
|
const promises = [];
|
|
189
196
|
for (const node of parent.getChildren()) {
|
|
190
|
-
let promise =
|
|
197
|
+
let promise = Suggestions_1.Suggestions.empty();
|
|
191
198
|
try {
|
|
192
|
-
promise = node.listSuggestions(context.build(truncatedInput), new
|
|
199
|
+
promise = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder_1.SuggestionsBuilder(truncatedInput, start));
|
|
193
200
|
}
|
|
194
201
|
catch (ignored) {
|
|
195
202
|
console.log("???", ignored);
|
|
@@ -197,7 +204,7 @@ class CommandDispatcher {
|
|
|
197
204
|
promises.push(promise);
|
|
198
205
|
}
|
|
199
206
|
const suggestions = await Promise.all(promises);
|
|
200
|
-
return
|
|
207
|
+
return Suggestions_1.Suggestions.merge(fullInput, suggestions);
|
|
201
208
|
}
|
|
202
209
|
getSmartUsage(node, source, optional, deep) {
|
|
203
210
|
if (optional === undefined && deep === undefined) {
|
package/dist/StringReader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringReader = void 0;
|
|
4
|
-
const
|
|
4
|
+
const StandardErrorTypes_1 = require("./exceptions/StandardErrorTypes");
|
|
5
5
|
class StringReader {
|
|
6
6
|
constructor(string) {
|
|
7
7
|
if (string instanceof StringReader) {
|
|
@@ -58,7 +58,7 @@ class StringReader {
|
|
|
58
58
|
}
|
|
59
59
|
const number = this.string.substring(start, this.cursor);
|
|
60
60
|
if (number.length === 0) {
|
|
61
|
-
throw
|
|
61
|
+
throw StandardErrorTypes_1.READER_EXPECTED_INT.createWithContext(this);
|
|
62
62
|
}
|
|
63
63
|
try {
|
|
64
64
|
const value = Number(number);
|
|
@@ -69,7 +69,7 @@ class StringReader {
|
|
|
69
69
|
}
|
|
70
70
|
catch (_) {
|
|
71
71
|
this.cursor = start;
|
|
72
|
-
throw
|
|
72
|
+
throw StandardErrorTypes_1.READER_INVALID_INT.createWithContext(this, number);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
readLong() {
|
|
@@ -79,14 +79,14 @@ class StringReader {
|
|
|
79
79
|
}
|
|
80
80
|
const number = this.string.substring(start, this.cursor);
|
|
81
81
|
if (number.length === 0) {
|
|
82
|
-
throw
|
|
82
|
+
throw StandardErrorTypes_1.READER_EXPECTED_INT.createWithContext(this);
|
|
83
83
|
}
|
|
84
84
|
try {
|
|
85
85
|
return BigInt(number);
|
|
86
86
|
}
|
|
87
87
|
catch (_) {
|
|
88
88
|
this.cursor = start;
|
|
89
|
-
throw
|
|
89
|
+
throw StandardErrorTypes_1.READER_INVALID_INT.createWithContext(this, number);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
readFloat() {
|
|
@@ -96,7 +96,7 @@ class StringReader {
|
|
|
96
96
|
}
|
|
97
97
|
const number = this.string.substring(start, this.cursor);
|
|
98
98
|
if (number.length === 0) {
|
|
99
|
-
throw
|
|
99
|
+
throw StandardErrorTypes_1.READER_EXPECTED_FLOAT.createWithContext(this);
|
|
100
100
|
}
|
|
101
101
|
try {
|
|
102
102
|
const value = Number(number);
|
|
@@ -107,7 +107,7 @@ class StringReader {
|
|
|
107
107
|
}
|
|
108
108
|
catch (_e) {
|
|
109
109
|
this.cursor = start;
|
|
110
|
-
throw
|
|
110
|
+
throw StandardErrorTypes_1.READER_INVALID_FLOAT.createWithContext(this, number);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
isAllowedInUnquotedString(c) {
|
|
@@ -141,7 +141,7 @@ class StringReader {
|
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
143
|
this.setCursor(this.cursor - 1);
|
|
144
|
-
throw
|
|
144
|
+
throw StandardErrorTypes_1.READER_INVALID_ESCAPE.createWithContext(this, c);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
else if (c === "\\") {
|
|
@@ -154,7 +154,7 @@ class StringReader {
|
|
|
154
154
|
result.push(c);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
throw
|
|
157
|
+
throw StandardErrorTypes_1.READER_EXPECTED_END_OF_QUOTE.createWithContext(this);
|
|
158
158
|
}
|
|
159
159
|
readString() {
|
|
160
160
|
if (!this.canRead()) {
|
|
@@ -170,7 +170,7 @@ class StringReader {
|
|
|
170
170
|
readBoolean() {
|
|
171
171
|
const value = this.readUnquotedString();
|
|
172
172
|
if (value.length === 0) {
|
|
173
|
-
throw
|
|
173
|
+
throw StandardErrorTypes_1.READER_EXPECTED_BOOL.createWithContext(this);
|
|
174
174
|
}
|
|
175
175
|
if (value === "true") {
|
|
176
176
|
return true;
|
|
@@ -179,7 +179,7 @@ class StringReader {
|
|
|
179
179
|
return false;
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
|
-
throw
|
|
182
|
+
throw StandardErrorTypes_1.READER_INVALID_BOOL.createWithContext(this, value);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FloatArgumentType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const StandardErrorTypes_1 = require("../exceptions/StandardErrorTypes");
|
|
5
5
|
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
6
|
class FloatArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
7
7
|
constructor(minimum = -Infinity, maximum = Infinity) {
|
|
@@ -11,10 +11,10 @@ class FloatArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
|
11
11
|
return reader.readFloat();
|
|
12
12
|
}
|
|
13
13
|
getTooSmallError() {
|
|
14
|
-
return
|
|
14
|
+
return StandardErrorTypes_1.FLOAT_TOO_SMALL;
|
|
15
15
|
}
|
|
16
16
|
getTooBigError() {
|
|
17
|
-
return
|
|
17
|
+
return StandardErrorTypes_1.FLOAT_TOO_BIG;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.FloatArgumentType = FloatArgumentType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IntegerArgumentType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const StandardErrorTypes_1 = require("../exceptions/StandardErrorTypes");
|
|
5
5
|
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
6
|
class IntegerArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
7
7
|
constructor(minimum = -2147483648, maximum = 2147483647) {
|
|
@@ -11,10 +11,10 @@ class IntegerArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
|
11
11
|
return reader.readInt();
|
|
12
12
|
}
|
|
13
13
|
getTooSmallError() {
|
|
14
|
-
return
|
|
14
|
+
return StandardErrorTypes_1.INTEGER_TOO_SMALL;
|
|
15
15
|
}
|
|
16
16
|
getTooBigError() {
|
|
17
|
-
return
|
|
17
|
+
return StandardErrorTypes_1.INTEGER_TOO_BIG;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.IntegerArgumentType = IntegerArgumentType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LongArgumentType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const StandardErrorTypes_1 = require("../exceptions/StandardErrorTypes");
|
|
5
5
|
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
6
|
class LongArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
7
7
|
constructor(minimum = LongArgumentType.MIN, maximum = LongArgumentType.MAX) {
|
|
@@ -11,10 +11,10 @@ class LongArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
|
11
11
|
return reader.readLong();
|
|
12
12
|
}
|
|
13
13
|
getTooSmallError() {
|
|
14
|
-
return
|
|
14
|
+
return StandardErrorTypes_1.LONG_TOO_SMALL;
|
|
15
15
|
}
|
|
16
16
|
getTooBigError() {
|
|
17
|
-
return
|
|
17
|
+
return StandardErrorTypes_1.LONG_TOO_BIG;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.LongArgumentType = LongArgumentType;
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import { CommandErrorType } from "./CommandErrorType";
|
|
2
1
|
export declare class CommandSyntaxError extends Error {
|
|
3
2
|
private input;
|
|
4
3
|
private cursor;
|
|
5
4
|
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
5
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandSyntaxError = void 0;
|
|
4
|
-
const CommandErrorType_1 = require("./CommandErrorType");
|
|
5
4
|
const CONTEXT_AMOUNT = 10;
|
|
6
5
|
class CommandSyntaxError extends Error {
|
|
7
6
|
constructor(message, input, cursor) {
|
|
@@ -19,25 +18,3 @@ class CommandSyntaxError extends Error {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
exports.CommandSyntaxError = CommandSyntaxError;
|
|
22
|
-
CommandSyntaxError.DOUBLE_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Double must not be less than ${min}, found ${found}`);
|
|
23
|
-
CommandSyntaxError.DOUBLE_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Double must not be more than ${max}, found ${found}`);
|
|
24
|
-
CommandSyntaxError.FLOAT_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Float must not be less than ${min}, found ${found}`);
|
|
25
|
-
CommandSyntaxError.FLOAT_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Float must not be more than ${max}, found ${found}`);
|
|
26
|
-
CommandSyntaxError.INTEGER_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Integer must not be less than ${min}, found ${found}`);
|
|
27
|
-
CommandSyntaxError.INTEGER_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Integer must not be more than ${max}, found ${found}`);
|
|
28
|
-
CommandSyntaxError.LONG_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Long must not be less than ${min}, found ${found}`);
|
|
29
|
-
CommandSyntaxError.LONG_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Long must not be more than ${max}, found ${found}`);
|
|
30
|
-
CommandSyntaxError.LITERAL_INCORRECT = new CommandErrorType_1.CommandErrorType((expected) => `Expected literal ${expected}`);
|
|
31
|
-
CommandSyntaxError.READER_EXPECTED_START_OF_QUOTE = new CommandErrorType_1.CommandErrorType(() => `Expected quote to start a string`);
|
|
32
|
-
CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE = new CommandErrorType_1.CommandErrorType(() => `Unclosed quoted string`);
|
|
33
|
-
CommandSyntaxError.READER_INVALID_ESCAPE = new CommandErrorType_1.CommandErrorType((character) => `Invalid escape sequence '${character}' in quoted string`);
|
|
34
|
-
CommandSyntaxError.READER_INVALID_BOOL = new CommandErrorType_1.CommandErrorType((value) => `Invalid bool, expected true or false but found '${value}'`);
|
|
35
|
-
CommandSyntaxError.READER_EXPECTED_BOOL = new CommandErrorType_1.CommandErrorType(() => `Expected bool`);
|
|
36
|
-
CommandSyntaxError.READER_INVALID_INT = new CommandErrorType_1.CommandErrorType((value) => `Invalid integer '${value}'`);
|
|
37
|
-
CommandSyntaxError.READER_EXPECTED_INT = new CommandErrorType_1.CommandErrorType(() => `Expected integer`);
|
|
38
|
-
CommandSyntaxError.READER_INVALID_FLOAT = new CommandErrorType_1.CommandErrorType((value) => `Invalid float '${value}'`);
|
|
39
|
-
CommandSyntaxError.READER_EXPECTED_FLOAT = new CommandErrorType_1.CommandErrorType(() => `Expected float`);
|
|
40
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND = new CommandErrorType_1.CommandErrorType(() => `Unknown Command`);
|
|
41
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT = new CommandErrorType_1.CommandErrorType(() => `Incorrect argument for command`);
|
|
42
|
-
CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new CommandErrorType_1.CommandErrorType(() => `Expected whitespace to end one argument, but found trailing data`);
|
|
43
|
-
CommandSyntaxError.DISPATCHER_PARSE_ERROR = new CommandErrorType_1.CommandErrorType((message) => `Could not parse command: ${message}`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommandErrorType } from "./CommandErrorType";
|
|
2
|
+
export declare const DOUBLE_TOO_SMALL: CommandErrorType;
|
|
3
|
+
export declare const DOUBLE_TOO_BIG: CommandErrorType;
|
|
4
|
+
export declare const FLOAT_TOO_SMALL: CommandErrorType;
|
|
5
|
+
export declare const FLOAT_TOO_BIG: CommandErrorType;
|
|
6
|
+
export declare const INTEGER_TOO_SMALL: CommandErrorType;
|
|
7
|
+
export declare const INTEGER_TOO_BIG: CommandErrorType;
|
|
8
|
+
export declare const LONG_TOO_SMALL: CommandErrorType;
|
|
9
|
+
export declare const LONG_TOO_BIG: CommandErrorType;
|
|
10
|
+
export declare const LITERAL_INCORRECT: CommandErrorType;
|
|
11
|
+
export declare const READER_EXPECTED_START_OF_QUOTE: CommandErrorType;
|
|
12
|
+
export declare const READER_EXPECTED_END_OF_QUOTE: CommandErrorType;
|
|
13
|
+
export declare const READER_INVALID_ESCAPE: CommandErrorType;
|
|
14
|
+
export declare const READER_INVALID_BOOL: CommandErrorType;
|
|
15
|
+
export declare const READER_EXPECTED_BOOL: CommandErrorType;
|
|
16
|
+
export declare const READER_INVALID_INT: CommandErrorType;
|
|
17
|
+
export declare const READER_EXPECTED_INT: CommandErrorType;
|
|
18
|
+
export declare const READER_INVALID_FLOAT: CommandErrorType;
|
|
19
|
+
export declare const READER_EXPECTED_FLOAT: CommandErrorType;
|
|
20
|
+
export declare const DISPATCHER_UNKNOWN_COMMAND: CommandErrorType;
|
|
21
|
+
export declare const DISPATCHER_UNKNOWN_ARGUMENT: CommandErrorType;
|
|
22
|
+
export declare const DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR: CommandErrorType;
|
|
23
|
+
export declare const DISPATCHER_PARSE_ERROR: CommandErrorType;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DISPATCHER_PARSE_ERROR = exports.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = exports.DISPATCHER_UNKNOWN_ARGUMENT = exports.DISPATCHER_UNKNOWN_COMMAND = exports.READER_EXPECTED_FLOAT = exports.READER_INVALID_FLOAT = exports.READER_EXPECTED_INT = exports.READER_INVALID_INT = exports.READER_EXPECTED_BOOL = exports.READER_INVALID_BOOL = exports.READER_INVALID_ESCAPE = exports.READER_EXPECTED_END_OF_QUOTE = exports.READER_EXPECTED_START_OF_QUOTE = exports.LITERAL_INCORRECT = exports.LONG_TOO_BIG = exports.LONG_TOO_SMALL = exports.INTEGER_TOO_BIG = exports.INTEGER_TOO_SMALL = exports.FLOAT_TOO_BIG = exports.FLOAT_TOO_SMALL = exports.DOUBLE_TOO_BIG = exports.DOUBLE_TOO_SMALL = void 0;
|
|
4
|
+
const CommandErrorType_1 = require("./CommandErrorType");
|
|
5
|
+
exports.DOUBLE_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Double must not be less than ${min}, found ${found}`);
|
|
6
|
+
exports.DOUBLE_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Double must not be more than ${max}, found ${found}`);
|
|
7
|
+
exports.FLOAT_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Float must not be less than ${min}, found ${found}`);
|
|
8
|
+
exports.FLOAT_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Float must not be more than ${max}, found ${found}`);
|
|
9
|
+
exports.INTEGER_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Integer must not be less than ${min}, found ${found}`);
|
|
10
|
+
exports.INTEGER_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Integer must not be more than ${max}, found ${found}`);
|
|
11
|
+
exports.LONG_TOO_SMALL = new CommandErrorType_1.CommandErrorType((found, min) => `Long must not be less than ${min}, found ${found}`);
|
|
12
|
+
exports.LONG_TOO_BIG = new CommandErrorType_1.CommandErrorType((found, max) => `Long must not be more than ${max}, found ${found}`);
|
|
13
|
+
exports.LITERAL_INCORRECT = new CommandErrorType_1.CommandErrorType((expected) => `Expected literal ${expected}`);
|
|
14
|
+
exports.READER_EXPECTED_START_OF_QUOTE = new CommandErrorType_1.CommandErrorType(() => `Expected quote to start a string`);
|
|
15
|
+
exports.READER_EXPECTED_END_OF_QUOTE = new CommandErrorType_1.CommandErrorType(() => `Unclosed quoted string`);
|
|
16
|
+
exports.READER_INVALID_ESCAPE = new CommandErrorType_1.CommandErrorType((character) => `Invalid escape sequence '${character}' in quoted string`);
|
|
17
|
+
exports.READER_INVALID_BOOL = new CommandErrorType_1.CommandErrorType((value) => `Invalid bool, expected true or false but found '${value}'`);
|
|
18
|
+
exports.READER_EXPECTED_BOOL = new CommandErrorType_1.CommandErrorType(() => `Expected bool`);
|
|
19
|
+
exports.READER_INVALID_INT = new CommandErrorType_1.CommandErrorType((value) => `Invalid integer '${value}'`);
|
|
20
|
+
exports.READER_EXPECTED_INT = new CommandErrorType_1.CommandErrorType(() => `Expected integer`);
|
|
21
|
+
exports.READER_INVALID_FLOAT = new CommandErrorType_1.CommandErrorType((value) => `Invalid float '${value}'`);
|
|
22
|
+
exports.READER_EXPECTED_FLOAT = new CommandErrorType_1.CommandErrorType(() => `Expected float`);
|
|
23
|
+
exports.DISPATCHER_UNKNOWN_COMMAND = new CommandErrorType_1.CommandErrorType(() => `Unknown Command`);
|
|
24
|
+
exports.DISPATCHER_UNKNOWN_ARGUMENT = new CommandErrorType_1.CommandErrorType(() => `Incorrect argument for command`);
|
|
25
|
+
exports.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new CommandErrorType_1.CommandErrorType(() => `Expected whitespace to end one argument, but found trailing data`);
|
|
26
|
+
exports.DISPATCHER_PARSE_ERROR = new CommandErrorType_1.CommandErrorType((message) => `Could not parse command: ${message}`);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiteralCommandNode = void 0;
|
|
4
4
|
const StringRange_1 = require("../context/StringRange");
|
|
5
|
-
const
|
|
5
|
+
const StandardErrorTypes_1 = require("../exceptions/StandardErrorTypes");
|
|
6
6
|
const Suggestions_1 = require("../suggestion/Suggestions");
|
|
7
7
|
const CommandNode_1 = require("./CommandNode");
|
|
8
8
|
const internal2_1 = require("./internal2");
|
|
@@ -19,7 +19,7 @@ class LiteralCommandNode extends CommandNode_1.CommandNode {
|
|
|
19
19
|
contextBuilder.withNode(this, new StringRange_1.StringRange(start, end));
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
throw
|
|
22
|
+
throw StandardErrorTypes_1.LITERAL_INCORRECT.createWithContext(reader, this.literal);
|
|
23
23
|
}
|
|
24
24
|
parseInternal(reader) {
|
|
25
25
|
const start = reader.getCursor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/Command.ts","../src/CommandDispatcher.ts","../src/ParseResults.ts","../src/Predicate.ts","../src/StringReader.ts","../src/index.ts","../src/arguments/ArgumentType.ts","../src/arguments/BoolArgumentType.ts","../src/arguments/FloatArgumentType.ts","../src/arguments/IntegerArgumentType.ts","../src/arguments/LongArgumentType.ts","../src/arguments/NumberArgumentType.ts","../src/arguments/StringArgumentType.ts","../src/builder/ArgumentBuilder.ts","../src/builder/LiteralArgumentBuilder.ts","../src/builder/RequiredArgumentBuilder.ts","../src/context/CommandContext.ts","../src/context/CommandContextBuilder.ts","../src/context/ParsedArgument.ts","../src/context/ParsedCommandNode.ts","../src/context/StringRange.ts","../src/context/SuggestionContext.ts","../src/exceptions/CommandErrorType.ts","../src/exceptions/CommandSyntaxError.ts","../src/suggestion/Suggestion.ts","../src/suggestion/Suggestions.ts","../src/suggestion/SuggestionsBuilder.ts","../src/tree/ArgumentCommandNode.ts","../src/tree/CommandNode.ts","../src/tree/LiteralCommandNode.ts","../src/tree/RootCommandNode.ts","../src/tree/internal.ts","../src/tree/internal2.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/Command.ts","../src/CommandDispatcher.ts","../src/ParseResults.ts","../src/Predicate.ts","../src/StringReader.ts","../src/index.ts","../src/arguments/ArgumentType.ts","../src/arguments/BoolArgumentType.ts","../src/arguments/FloatArgumentType.ts","../src/arguments/IntegerArgumentType.ts","../src/arguments/LongArgumentType.ts","../src/arguments/NumberArgumentType.ts","../src/arguments/StringArgumentType.ts","../src/builder/ArgumentBuilder.ts","../src/builder/LiteralArgumentBuilder.ts","../src/builder/RequiredArgumentBuilder.ts","../src/context/CommandContext.ts","../src/context/CommandContextBuilder.ts","../src/context/ParsedArgument.ts","../src/context/ParsedCommandNode.ts","../src/context/StringRange.ts","../src/context/SuggestionContext.ts","../src/exceptions/CommandErrorType.ts","../src/exceptions/CommandSyntaxError.ts","../src/exceptions/StandardErrorTypes.ts","../src/suggestion/Suggestion.ts","../src/suggestion/Suggestions.ts","../src/suggestion/SuggestionsBuilder.ts","../src/tree/ArgumentCommandNode.ts","../src/tree/CommandNode.ts","../src/tree/LiteralCommandNode.ts","../src/tree/RootCommandNode.ts","../src/tree/internal.ts","../src/tree/internal2.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
package/src/CommandDispatcher.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from ".";
|
|
1
|
+
import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
|
|
2
|
+
import { CommandContextBuilder } from "./context/CommandContextBuilder";
|
|
3
|
+
import { CommandSyntaxError } from "./exceptions/CommandSyntaxError";
|
|
4
|
+
import { DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR, DISPATCHER_PARSE_ERROR, DISPATCHER_UNKNOWN_ARGUMENT, DISPATCHER_UNKNOWN_COMMAND } from "./exceptions/StandardErrorTypes";
|
|
5
|
+
import { ParseResults } from "./ParseResults";
|
|
6
|
+
import { StringReader } from "./StringReader";
|
|
7
|
+
import { Suggestions } from "./suggestion/Suggestions";
|
|
8
|
+
import { SuggestionsBuilder } from "./suggestion/SuggestionsBuilder";
|
|
9
|
+
import type { CommandNode } from "./tree/CommandNode";
|
|
10
|
+
import type { LiteralCommandNode } from "./tree/LiteralCommandNode";
|
|
11
|
+
import { RootCommandNode } from "./tree/RootCommandNode";
|
|
13
12
|
|
|
14
13
|
export class CommandDispatcher<S> {
|
|
15
14
|
private root: RootCommandNode<S>;
|
|
@@ -39,13 +38,9 @@ export class CommandDispatcher<S> {
|
|
|
39
38
|
if (parse.getErrors().size === 1) {
|
|
40
39
|
throw parse.getErrors().values().next();
|
|
41
40
|
} else if (parse.getContext().getRange().isEmpty()) {
|
|
42
|
-
throw
|
|
43
|
-
parse.getReader(),
|
|
44
|
-
);
|
|
41
|
+
throw DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
45
42
|
} else {
|
|
46
|
-
throw
|
|
47
|
-
parse.getReader(),
|
|
48
|
-
);
|
|
43
|
+
throw DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
|
|
@@ -97,9 +92,7 @@ export class CommandDispatcher<S> {
|
|
|
97
92
|
}
|
|
98
93
|
|
|
99
94
|
if (!foundCommand) {
|
|
100
|
-
throw
|
|
101
|
-
parse.getReader(),
|
|
102
|
-
);
|
|
95
|
+
throw DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
103
96
|
}
|
|
104
97
|
return forked ? successfulForks : result;
|
|
105
98
|
}
|
|
@@ -142,14 +135,11 @@ export class CommandDispatcher<S> {
|
|
|
142
135
|
if (e instanceof CommandSyntaxError) {
|
|
143
136
|
throw e;
|
|
144
137
|
} else {
|
|
145
|
-
throw
|
|
146
|
-
reader,
|
|
147
|
-
e.message,
|
|
148
|
-
);
|
|
138
|
+
throw DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
|
|
149
139
|
}
|
|
150
140
|
}
|
|
151
141
|
if (reader.canRead() && reader.peek() !== " ") {
|
|
152
|
-
throw
|
|
142
|
+
throw DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(
|
|
153
143
|
reader,
|
|
154
144
|
);
|
|
155
145
|
}
|
package/src/StringReader.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { READER_EXPECTED_BOOL, READER_EXPECTED_END_OF_QUOTE, READER_EXPECTED_FLOAT, READER_EXPECTED_INT, READER_INVALID_BOOL, READER_INVALID_ESCAPE, READER_INVALID_FLOAT, READER_INVALID_INT } from "./exceptions/StandardErrorTypes";
|
|
2
2
|
|
|
3
3
|
export class StringReader {
|
|
4
4
|
private string: string;
|
|
@@ -71,7 +71,7 @@ export class StringReader {
|
|
|
71
71
|
}
|
|
72
72
|
const number = this.string.substring(start, this.cursor);
|
|
73
73
|
if (number.length === 0) {
|
|
74
|
-
throw
|
|
74
|
+
throw READER_EXPECTED_INT.createWithContext(this);
|
|
75
75
|
}
|
|
76
76
|
try {
|
|
77
77
|
const value = Number(number);
|
|
@@ -81,10 +81,7 @@ export class StringReader {
|
|
|
81
81
|
return value;
|
|
82
82
|
} catch (_) {
|
|
83
83
|
this.cursor = start;
|
|
84
|
-
throw
|
|
85
|
-
this,
|
|
86
|
-
number,
|
|
87
|
-
);
|
|
84
|
+
throw READER_INVALID_INT.createWithContext(this, number);
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
|
|
@@ -95,16 +92,13 @@ export class StringReader {
|
|
|
95
92
|
}
|
|
96
93
|
const number = this.string.substring(start, this.cursor);
|
|
97
94
|
if (number.length === 0) {
|
|
98
|
-
throw
|
|
95
|
+
throw READER_EXPECTED_INT.createWithContext(this);
|
|
99
96
|
}
|
|
100
97
|
try {
|
|
101
98
|
return BigInt(number);
|
|
102
99
|
} catch (_) {
|
|
103
100
|
this.cursor = start;
|
|
104
|
-
throw
|
|
105
|
-
this,
|
|
106
|
-
number,
|
|
107
|
-
);
|
|
101
|
+
throw READER_INVALID_INT.createWithContext(this, number);
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
104
|
|
|
@@ -115,7 +109,7 @@ export class StringReader {
|
|
|
115
109
|
}
|
|
116
110
|
const number = this.string.substring(start, this.cursor);
|
|
117
111
|
if (number.length === 0) {
|
|
118
|
-
throw
|
|
112
|
+
throw READER_EXPECTED_FLOAT.createWithContext(this);
|
|
119
113
|
}
|
|
120
114
|
try {
|
|
121
115
|
const value = Number(number);
|
|
@@ -125,10 +119,7 @@ export class StringReader {
|
|
|
125
119
|
return value;
|
|
126
120
|
} catch (_e) {
|
|
127
121
|
this.cursor = start;
|
|
128
|
-
throw
|
|
129
|
-
this,
|
|
130
|
-
number,
|
|
131
|
-
);
|
|
122
|
+
throw READER_INVALID_FLOAT.createWithContext(this, number);
|
|
132
123
|
}
|
|
133
124
|
}
|
|
134
125
|
|
|
@@ -167,10 +158,7 @@ export class StringReader {
|
|
|
167
158
|
escaped = false;
|
|
168
159
|
} else {
|
|
169
160
|
this.setCursor(this.cursor - 1);
|
|
170
|
-
throw
|
|
171
|
-
this,
|
|
172
|
-
c,
|
|
173
|
-
);
|
|
161
|
+
throw READER_INVALID_ESCAPE.createWithContext(this, c);
|
|
174
162
|
}
|
|
175
163
|
} else if (c === "\\") {
|
|
176
164
|
escaped = true;
|
|
@@ -180,9 +168,7 @@ export class StringReader {
|
|
|
180
168
|
result.push(c);
|
|
181
169
|
}
|
|
182
170
|
}
|
|
183
|
-
throw
|
|
184
|
-
this,
|
|
185
|
-
);
|
|
171
|
+
throw READER_EXPECTED_END_OF_QUOTE.createWithContext(this);
|
|
186
172
|
}
|
|
187
173
|
|
|
188
174
|
readString(): string {
|
|
@@ -200,17 +186,14 @@ export class StringReader {
|
|
|
200
186
|
readBoolean(): boolean {
|
|
201
187
|
const value = this.readUnquotedString();
|
|
202
188
|
if (value.length === 0) {
|
|
203
|
-
throw
|
|
189
|
+
throw READER_EXPECTED_BOOL.createWithContext(this);
|
|
204
190
|
}
|
|
205
191
|
if (value === "true") {
|
|
206
192
|
return true;
|
|
207
193
|
} else if (value === "false") {
|
|
208
194
|
return false;
|
|
209
195
|
} else {
|
|
210
|
-
throw
|
|
211
|
-
this,
|
|
212
|
-
value,
|
|
213
|
-
);
|
|
196
|
+
throw READER_INVALID_BOOL.createWithContext(this, value);
|
|
214
197
|
}
|
|
215
198
|
}
|
|
216
199
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FLOAT_TOO_BIG, FLOAT_TOO_SMALL } from "../exceptions/StandardErrorTypes";
|
|
2
2
|
import type { StringReader } from "../StringReader";
|
|
3
3
|
import { NumberArgumentType } from "./NumberArgumentType";
|
|
4
4
|
|
|
@@ -12,10 +12,10 @@ export class FloatArgumentType extends NumberArgumentType {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
getTooSmallError() {
|
|
15
|
-
return
|
|
15
|
+
return FLOAT_TOO_SMALL;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
getTooBigError() {
|
|
19
|
-
return
|
|
19
|
+
return FLOAT_TOO_BIG;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INTEGER_TOO_BIG, INTEGER_TOO_SMALL } from "../exceptions/StandardErrorTypes";
|
|
2
2
|
import type { StringReader } from "../StringReader";
|
|
3
3
|
import { NumberArgumentType } from "./NumberArgumentType";
|
|
4
4
|
|
|
@@ -12,10 +12,10 @@ export class IntegerArgumentType extends NumberArgumentType {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
getTooSmallError() {
|
|
15
|
-
return
|
|
15
|
+
return INTEGER_TOO_SMALL;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
getTooBigError() {
|
|
19
|
-
return
|
|
19
|
+
return INTEGER_TOO_BIG;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LONG_TOO_BIG, LONG_TOO_SMALL } from "../exceptions/StandardErrorTypes";
|
|
2
2
|
import type { StringReader } from "../StringReader";
|
|
3
3
|
import { NumberArgumentType } from "./NumberArgumentType";
|
|
4
4
|
|
|
@@ -15,10 +15,10 @@ export class LongArgumentType extends NumberArgumentType<bigint> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
getTooSmallError() {
|
|
18
|
-
return
|
|
18
|
+
return LONG_TOO_SMALL;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
getTooBigError() {
|
|
22
|
-
return
|
|
22
|
+
return LONG_TOO_BIG;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CommandErrorType } from "./CommandErrorType";
|
|
2
|
-
|
|
3
1
|
const CONTEXT_AMOUNT = 10;
|
|
4
2
|
|
|
5
3
|
export class CommandSyntaxError extends Error {
|
|
@@ -23,67 +21,4 @@ export class CommandSyntaxError extends Error {
|
|
|
23
21
|
this.message += "<--[HERE]";
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
static DOUBLE_TOO_SMALL = new CommandErrorType(
|
|
28
|
-
(found, min) => `Double must not be less than ${min}, found ${found}`,
|
|
29
|
-
);
|
|
30
|
-
static DOUBLE_TOO_BIG = new CommandErrorType(
|
|
31
|
-
(found, max) => `Double must not be more than ${max}, found ${found}`,
|
|
32
|
-
);
|
|
33
|
-
static FLOAT_TOO_SMALL = new CommandErrorType(
|
|
34
|
-
(found, min) => `Float must not be less than ${min}, found ${found}`,
|
|
35
|
-
);
|
|
36
|
-
static FLOAT_TOO_BIG = new CommandErrorType(
|
|
37
|
-
(found, max) => `Float must not be more than ${max}, found ${found}`,
|
|
38
|
-
);
|
|
39
|
-
static INTEGER_TOO_SMALL = new CommandErrorType(
|
|
40
|
-
(found, min) => `Integer must not be less than ${min}, found ${found}`,
|
|
41
|
-
);
|
|
42
|
-
static INTEGER_TOO_BIG = new CommandErrorType(
|
|
43
|
-
(found, max) => `Integer must not be more than ${max}, found ${found}`,
|
|
44
|
-
);
|
|
45
|
-
static LONG_TOO_SMALL = new CommandErrorType(
|
|
46
|
-
(found, min) => `Long must not be less than ${min}, found ${found}`,
|
|
47
|
-
);
|
|
48
|
-
static LONG_TOO_BIG = new CommandErrorType(
|
|
49
|
-
(found, max) => `Long must not be more than ${max}, found ${found}`,
|
|
50
|
-
);
|
|
51
|
-
static LITERAL_INCORRECT = new CommandErrorType(
|
|
52
|
-
(expected) => `Expected literal ${expected}`,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
static READER_EXPECTED_START_OF_QUOTE = new CommandErrorType(
|
|
56
|
-
() => `Expected quote to start a string`,
|
|
57
|
-
);
|
|
58
|
-
static READER_EXPECTED_END_OF_QUOTE = new CommandErrorType(
|
|
59
|
-
() => `Unclosed quoted string`,
|
|
60
|
-
);
|
|
61
|
-
static READER_INVALID_ESCAPE = new CommandErrorType(
|
|
62
|
-
(character) => `Invalid escape sequence '${character}' in quoted string`,
|
|
63
|
-
);
|
|
64
|
-
static READER_INVALID_BOOL = new CommandErrorType(
|
|
65
|
-
(value) => `Invalid bool, expected true or false but found '${value}'`,
|
|
66
|
-
);
|
|
67
|
-
static READER_EXPECTED_BOOL = new CommandErrorType(() => `Expected bool`);
|
|
68
|
-
static READER_INVALID_INT = new CommandErrorType(
|
|
69
|
-
(value) => `Invalid integer '${value}'`,
|
|
70
|
-
);
|
|
71
|
-
static READER_EXPECTED_INT = new CommandErrorType(() => `Expected integer`);
|
|
72
|
-
static READER_INVALID_FLOAT = new CommandErrorType(
|
|
73
|
-
(value) => `Invalid float '${value}'`,
|
|
74
|
-
);
|
|
75
|
-
static READER_EXPECTED_FLOAT = new CommandErrorType(() => `Expected float`);
|
|
76
|
-
|
|
77
|
-
static DISPATCHER_UNKNOWN_COMMAND = new CommandErrorType(
|
|
78
|
-
() => `Unknown Command`,
|
|
79
|
-
);
|
|
80
|
-
static DISPATCHER_UNKNOWN_ARGUMENT = new CommandErrorType(
|
|
81
|
-
() => `Incorrect argument for command`,
|
|
82
|
-
);
|
|
83
|
-
static DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new CommandErrorType(
|
|
84
|
-
() => `Expected whitespace to end one argument, but found trailing data`,
|
|
85
|
-
);
|
|
86
|
-
static DISPATCHER_PARSE_ERROR = new CommandErrorType(
|
|
87
|
-
(message) => `Could not parse command: ${message}`,
|
|
88
|
-
);
|
|
89
24
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CommandErrorType } from "./CommandErrorType";
|
|
2
|
+
|
|
3
|
+
export const DOUBLE_TOO_SMALL = new CommandErrorType(
|
|
4
|
+
(found, min) => `Double must not be less than ${min}, found ${found}`,
|
|
5
|
+
);
|
|
6
|
+
export const DOUBLE_TOO_BIG = new CommandErrorType(
|
|
7
|
+
(found, max) => `Double must not be more than ${max}, found ${found}`,
|
|
8
|
+
);
|
|
9
|
+
export const FLOAT_TOO_SMALL = new CommandErrorType(
|
|
10
|
+
(found, min) => `Float must not be less than ${min}, found ${found}`,
|
|
11
|
+
);
|
|
12
|
+
export const FLOAT_TOO_BIG = new CommandErrorType(
|
|
13
|
+
(found, max) => `Float must not be more than ${max}, found ${found}`,
|
|
14
|
+
);
|
|
15
|
+
export const INTEGER_TOO_SMALL = new CommandErrorType(
|
|
16
|
+
(found, min) => `Integer must not be less than ${min}, found ${found}`,
|
|
17
|
+
);
|
|
18
|
+
export const INTEGER_TOO_BIG = new CommandErrorType(
|
|
19
|
+
(found, max) => `Integer must not be more than ${max}, found ${found}`,
|
|
20
|
+
);
|
|
21
|
+
export const LONG_TOO_SMALL = new CommandErrorType(
|
|
22
|
+
(found, min) => `Long must not be less than ${min}, found ${found}`,
|
|
23
|
+
);
|
|
24
|
+
export const LONG_TOO_BIG = new CommandErrorType(
|
|
25
|
+
(found, max) => `Long must not be more than ${max}, found ${found}`,
|
|
26
|
+
);
|
|
27
|
+
export const LITERAL_INCORRECT = new CommandErrorType(
|
|
28
|
+
(expected) => `Expected literal ${expected}`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const READER_EXPECTED_START_OF_QUOTE = new CommandErrorType(
|
|
32
|
+
() => `Expected quote to start a string`,
|
|
33
|
+
);
|
|
34
|
+
export const READER_EXPECTED_END_OF_QUOTE = new CommandErrorType(
|
|
35
|
+
() => `Unclosed quoted string`,
|
|
36
|
+
);
|
|
37
|
+
export const READER_INVALID_ESCAPE = new CommandErrorType(
|
|
38
|
+
(character) => `Invalid escape sequence '${character}' in quoted string`,
|
|
39
|
+
);
|
|
40
|
+
export const READER_INVALID_BOOL = new CommandErrorType(
|
|
41
|
+
(value) => `Invalid bool, expected true or false but found '${value}'`,
|
|
42
|
+
);
|
|
43
|
+
export const READER_EXPECTED_BOOL = new CommandErrorType(() => `Expected bool`);
|
|
44
|
+
export const READER_INVALID_INT = new CommandErrorType(
|
|
45
|
+
(value) => `Invalid integer '${value}'`,
|
|
46
|
+
);
|
|
47
|
+
export const READER_EXPECTED_INT = new CommandErrorType(
|
|
48
|
+
() => `Expected integer`,
|
|
49
|
+
);
|
|
50
|
+
export const READER_INVALID_FLOAT = new CommandErrorType(
|
|
51
|
+
(value) => `Invalid float '${value}'`,
|
|
52
|
+
);
|
|
53
|
+
export const READER_EXPECTED_FLOAT = new CommandErrorType(
|
|
54
|
+
() => `Expected float`,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const DISPATCHER_UNKNOWN_COMMAND = new CommandErrorType(
|
|
58
|
+
() => `Unknown Command`,
|
|
59
|
+
);
|
|
60
|
+
export const DISPATCHER_UNKNOWN_ARGUMENT = new CommandErrorType(
|
|
61
|
+
() => `Incorrect argument for command`,
|
|
62
|
+
);
|
|
63
|
+
export const DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new CommandErrorType(
|
|
64
|
+
() => `Expected whitespace to end one argument, but found trailing data`,
|
|
65
|
+
);
|
|
66
|
+
export const DISPATCHER_PARSE_ERROR = new CommandErrorType(
|
|
67
|
+
(message) => `Could not parse command: ${message}`,
|
|
68
|
+
);
|
|
@@ -3,7 +3,7 @@ import type { Command } from "../Command";
|
|
|
3
3
|
import type { CommandContext } from "../context/CommandContext";
|
|
4
4
|
import type { CommandContextBuilder } from "../context/CommandContextBuilder";
|
|
5
5
|
import { StringRange } from "../context/StringRange";
|
|
6
|
-
import {
|
|
6
|
+
import { LITERAL_INCORRECT } from "../exceptions/StandardErrorTypes";
|
|
7
7
|
import type { Predicate } from "../Predicate";
|
|
8
8
|
import type { StringReader } from "../StringReader";
|
|
9
9
|
import { Suggestions } from "../suggestion/Suggestions";
|
|
@@ -34,7 +34,7 @@ export class LiteralCommandNode<S> extends CommandNode<S> {
|
|
|
34
34
|
contextBuilder.withNode(this, new StringRange(start, end));
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
throw
|
|
37
|
+
throw LITERAL_INCORRECT.createWithContext(
|
|
38
38
|
reader,
|
|
39
39
|
this.literal,
|
|
40
40
|
);
|