@wq2/brigadier-ts 1.0.5 → 1.0.7

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandDispatcher = void 0;
4
4
  const CommandContextBuilder_1 = require("./context/CommandContextBuilder");
5
5
  const CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
6
+ const StandardErrorTypes_1 = require("./exceptions/StandardErrorTypes");
6
7
  const ParseResults_1 = require("./ParseResults");
7
8
  const StringReader_1 = require("./StringReader");
8
9
  const Suggestions_1 = require("./suggestion/Suggestions");
@@ -26,10 +27,10 @@ class CommandDispatcher {
26
27
  throw parse.getErrors().values().next();
27
28
  }
28
29
  else if (parse.getContext().getRange().isEmpty()) {
29
- throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
30
+ throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
30
31
  }
31
32
  else {
32
- throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
33
+ throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
33
34
  }
34
35
  }
35
36
  let result = 0;
@@ -84,7 +85,7 @@ class CommandDispatcher {
84
85
  next = [];
85
86
  }
86
87
  if (!foundCommand) {
87
- throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
88
+ throw StandardErrorTypes_1.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
88
89
  }
89
90
  return forked ? successfulForks : result;
90
91
  }
@@ -113,11 +114,11 @@ class CommandDispatcher {
113
114
  throw e;
114
115
  }
115
116
  else {
116
- throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
117
+ throw StandardErrorTypes_1.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
117
118
  }
118
119
  }
119
120
  if (reader.canRead() && reader.peek() !== " ") {
120
- throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
121
+ throw StandardErrorTypes_1.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
121
122
  }
122
123
  }
123
124
  catch (e) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringReader = void 0;
4
- const CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
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 CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
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 CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_INT.createWithContext(this, number);
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 CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
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 CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_INT.createWithContext(this, number);
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 CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_FLOAT.createWithContext(this);
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 CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_FLOAT.createWithContext(this, number);
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 CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_ESCAPE.createWithContext(this, c);
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 CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE.createWithContext(this);
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 CommandSyntaxError_1.CommandSyntaxError.READER_EXPECTED_BOOL.createWithContext(this);
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 CommandSyntaxError_1.CommandSyntaxError.READER_INVALID_BOOL.createWithContext(this, value);
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 CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
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 CommandSyntaxError_1.CommandSyntaxError.FLOAT_TOO_SMALL;
14
+ return StandardErrorTypes_1.FLOAT_TOO_SMALL;
15
15
  }
16
16
  getTooBigError() {
17
- return CommandSyntaxError_1.CommandSyntaxError.FLOAT_TOO_BIG;
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 CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
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 CommandSyntaxError_1.CommandSyntaxError.INTEGER_TOO_SMALL;
14
+ return StandardErrorTypes_1.INTEGER_TOO_SMALL;
15
15
  }
16
16
  getTooBigError() {
17
- return CommandSyntaxError_1.CommandSyntaxError.INTEGER_TOO_BIG;
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 CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
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 CommandSyntaxError_1.CommandSyntaxError.LONG_TOO_SMALL;
14
+ return StandardErrorTypes_1.LONG_TOO_SMALL;
15
15
  }
16
16
  getTooBigError() {
17
- return CommandSyntaxError_1.CommandSyntaxError.LONG_TOO_BIG;
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}`);
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./context/StringRange";
18
18
  export * from "./context/SuggestionContext";
19
19
  export * from "./exceptions/CommandErrorType";
20
20
  export * from "./exceptions/CommandSyntaxError";
21
+ export * from "./exceptions/StandardErrorTypes";
21
22
  export * from "./ParseResults";
22
23
  export * from "./Predicate";
23
24
  export * from "./StringReader";
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __exportStar(require("./context/StringRange"), exports);
34
34
  __exportStar(require("./context/SuggestionContext"), exports);
35
35
  __exportStar(require("./exceptions/CommandErrorType"), exports);
36
36
  __exportStar(require("./exceptions/CommandSyntaxError"), exports);
37
+ __exportStar(require("./exceptions/StandardErrorTypes"), exports);
37
38
  __exportStar(require("./ParseResults"), exports);
38
39
  __exportStar(require("./Predicate"), exports);
39
40
  __exportStar(require("./StringReader"), exports);
@@ -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 CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
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 CommandSyntaxError_1.CommandSyntaxError.LITERAL_INCORRECT.createWithContext(reader, this.literal);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wq2/brigadier-ts",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Fork of brigadier-ts with some extra changes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,12 @@
1
1
  import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
2
2
  import { CommandContextBuilder } from "./context/CommandContextBuilder";
3
3
  import { CommandSyntaxError } from "./exceptions/CommandSyntaxError";
4
+ import {
5
+ DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR,
6
+ DISPATCHER_PARSE_ERROR,
7
+ DISPATCHER_UNKNOWN_ARGUMENT,
8
+ DISPATCHER_UNKNOWN_COMMAND,
9
+ } from "./exceptions/StandardErrorTypes";
4
10
  import { ParseResults } from "./ParseResults";
5
11
  import { StringReader } from "./StringReader";
6
12
  import { Suggestions } from "./suggestion/Suggestions";
@@ -37,13 +43,9 @@ export class CommandDispatcher<S> {
37
43
  if (parse.getErrors().size === 1) {
38
44
  throw parse.getErrors().values().next();
39
45
  } else if (parse.getContext().getRange().isEmpty()) {
40
- throw CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(
41
- parse.getReader(),
42
- );
46
+ throw DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
43
47
  } else {
44
- throw CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(
45
- parse.getReader(),
46
- );
48
+ throw DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
47
49
  }
48
50
  }
49
51
 
@@ -95,9 +97,7 @@ export class CommandDispatcher<S> {
95
97
  }
96
98
 
97
99
  if (!foundCommand) {
98
- throw CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(
99
- parse.getReader(),
100
- );
100
+ throw DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
101
101
  }
102
102
  return forked ? successfulForks : result;
103
103
  }
@@ -140,14 +140,11 @@ export class CommandDispatcher<S> {
140
140
  if (e instanceof CommandSyntaxError) {
141
141
  throw e;
142
142
  } else {
143
- throw CommandSyntaxError.DISPATCHER_PARSE_ERROR.createWithContext(
144
- reader,
145
- e.message,
146
- );
143
+ throw DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
147
144
  }
148
145
  }
149
146
  if (reader.canRead() && reader.peek() !== " ") {
150
- throw CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(
147
+ throw DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(
151
148
  reader,
152
149
  );
153
150
  }
@@ -1,4 +1,13 @@
1
- import { CommandSyntaxError } from "./exceptions/CommandSyntaxError";
1
+ import {
2
+ READER_EXPECTED_BOOL,
3
+ READER_EXPECTED_END_OF_QUOTE,
4
+ READER_EXPECTED_FLOAT,
5
+ READER_EXPECTED_INT,
6
+ READER_INVALID_BOOL,
7
+ READER_INVALID_ESCAPE,
8
+ READER_INVALID_FLOAT,
9
+ READER_INVALID_INT,
10
+ } from "./exceptions/StandardErrorTypes";
2
11
 
3
12
  export class StringReader {
4
13
  private string: string;
@@ -71,7 +80,7 @@ export class StringReader {
71
80
  }
72
81
  const number = this.string.substring(start, this.cursor);
73
82
  if (number.length === 0) {
74
- throw CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
83
+ throw READER_EXPECTED_INT.createWithContext(this);
75
84
  }
76
85
  try {
77
86
  const value = Number(number);
@@ -81,10 +90,7 @@ export class StringReader {
81
90
  return value;
82
91
  } catch (_) {
83
92
  this.cursor = start;
84
- throw CommandSyntaxError.READER_INVALID_INT.createWithContext(
85
- this,
86
- number,
87
- );
93
+ throw READER_INVALID_INT.createWithContext(this, number);
88
94
  }
89
95
  }
90
96
 
@@ -95,16 +101,13 @@ export class StringReader {
95
101
  }
96
102
  const number = this.string.substring(start, this.cursor);
97
103
  if (number.length === 0) {
98
- throw CommandSyntaxError.READER_EXPECTED_INT.createWithContext(this);
104
+ throw READER_EXPECTED_INT.createWithContext(this);
99
105
  }
100
106
  try {
101
107
  return BigInt(number);
102
108
  } catch (_) {
103
109
  this.cursor = start;
104
- throw CommandSyntaxError.READER_INVALID_INT.createWithContext(
105
- this,
106
- number,
107
- );
110
+ throw READER_INVALID_INT.createWithContext(this, number);
108
111
  }
109
112
  }
110
113
 
@@ -115,7 +118,7 @@ export class StringReader {
115
118
  }
116
119
  const number = this.string.substring(start, this.cursor);
117
120
  if (number.length === 0) {
118
- throw CommandSyntaxError.READER_EXPECTED_FLOAT.createWithContext(this);
121
+ throw READER_EXPECTED_FLOAT.createWithContext(this);
119
122
  }
120
123
  try {
121
124
  const value = Number(number);
@@ -125,10 +128,7 @@ export class StringReader {
125
128
  return value;
126
129
  } catch (_e) {
127
130
  this.cursor = start;
128
- throw CommandSyntaxError.READER_INVALID_FLOAT.createWithContext(
129
- this,
130
- number,
131
- );
131
+ throw READER_INVALID_FLOAT.createWithContext(this, number);
132
132
  }
133
133
  }
134
134
 
@@ -167,10 +167,7 @@ export class StringReader {
167
167
  escaped = false;
168
168
  } else {
169
169
  this.setCursor(this.cursor - 1);
170
- throw CommandSyntaxError.READER_INVALID_ESCAPE.createWithContext(
171
- this,
172
- c,
173
- );
170
+ throw READER_INVALID_ESCAPE.createWithContext(this, c);
174
171
  }
175
172
  } else if (c === "\\") {
176
173
  escaped = true;
@@ -180,9 +177,7 @@ export class StringReader {
180
177
  result.push(c);
181
178
  }
182
179
  }
183
- throw CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE.createWithContext(
184
- this,
185
- );
180
+ throw READER_EXPECTED_END_OF_QUOTE.createWithContext(this);
186
181
  }
187
182
 
188
183
  readString(): string {
@@ -200,17 +195,14 @@ export class StringReader {
200
195
  readBoolean(): boolean {
201
196
  const value = this.readUnquotedString();
202
197
  if (value.length === 0) {
203
- throw CommandSyntaxError.READER_EXPECTED_BOOL.createWithContext(this);
198
+ throw READER_EXPECTED_BOOL.createWithContext(this);
204
199
  }
205
200
  if (value === "true") {
206
201
  return true;
207
202
  } else if (value === "false") {
208
203
  return false;
209
204
  } else {
210
- throw CommandSyntaxError.READER_INVALID_BOOL.createWithContext(
211
- this,
212
- value,
213
- );
205
+ throw READER_INVALID_BOOL.createWithContext(this, value);
214
206
  }
215
207
  }
216
208
  }
@@ -1,4 +1,7 @@
1
- import { CommandSyntaxError } from "../exceptions/CommandSyntaxError";
1
+ import {
2
+ FLOAT_TOO_BIG,
3
+ FLOAT_TOO_SMALL,
4
+ } from "../exceptions/StandardErrorTypes";
2
5
  import type { StringReader } from "../StringReader";
3
6
  import { NumberArgumentType } from "./NumberArgumentType";
4
7
 
@@ -12,10 +15,10 @@ export class FloatArgumentType extends NumberArgumentType {
12
15
  }
13
16
 
14
17
  getTooSmallError() {
15
- return CommandSyntaxError.FLOAT_TOO_SMALL;
18
+ return FLOAT_TOO_SMALL;
16
19
  }
17
20
 
18
21
  getTooBigError() {
19
- return CommandSyntaxError.FLOAT_TOO_BIG;
22
+ return FLOAT_TOO_BIG;
20
23
  }
21
24
  }
@@ -1,4 +1,7 @@
1
- import { CommandSyntaxError } from "../exceptions/CommandSyntaxError";
1
+ import {
2
+ INTEGER_TOO_BIG,
3
+ INTEGER_TOO_SMALL,
4
+ } from "../exceptions/StandardErrorTypes";
2
5
  import type { StringReader } from "../StringReader";
3
6
  import { NumberArgumentType } from "./NumberArgumentType";
4
7
 
@@ -12,10 +15,10 @@ export class IntegerArgumentType extends NumberArgumentType {
12
15
  }
13
16
 
14
17
  getTooSmallError() {
15
- return CommandSyntaxError.INTEGER_TOO_SMALL;
18
+ return INTEGER_TOO_SMALL;
16
19
  }
17
20
 
18
21
  getTooBigError() {
19
- return CommandSyntaxError.INTEGER_TOO_BIG;
22
+ return INTEGER_TOO_BIG;
20
23
  }
21
24
  }
@@ -1,4 +1,4 @@
1
- import { CommandSyntaxError } from "../exceptions/CommandSyntaxError";
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 CommandSyntaxError.LONG_TOO_SMALL;
18
+ return LONG_TOO_SMALL;
19
19
  }
20
20
 
21
21
  getTooBigError() {
22
- return CommandSyntaxError.LONG_TOO_BIG;
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
+ );
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./context/StringRange";
18
18
  export * from "./context/SuggestionContext";
19
19
  export * from "./exceptions/CommandErrorType";
20
20
  export * from "./exceptions/CommandSyntaxError";
21
+ export * from "./exceptions/StandardErrorTypes";
21
22
  export * from "./ParseResults";
22
23
  export * from "./Predicate";
23
24
  export * from "./StringReader";
@@ -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 { CommandSyntaxError } from "../exceptions/CommandSyntaxError";
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,10 +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 CommandSyntaxError.LITERAL_INCORRECT.createWithContext(
38
- reader,
39
- this.literal,
40
- );
37
+ throw LITERAL_INCORRECT.createWithContext(reader, this.literal);
41
38
  }
42
39
 
43
40
  private parseInternal(reader: StringReader): number {