@wq2/brigadier-ts 1.0.1 → 1.0.3
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/Command.d.ts +2 -2
- package/dist/CommandDispatcher.d.ts +1 -1
- package/dist/ParseResults.d.ts +1 -1
- package/dist/arguments/ArgumentType.d.ts +5 -2
- package/dist/arguments/ArgumentType.js +2 -2
- package/dist/arguments/BoolArgumentType.d.ts +4 -4
- package/dist/arguments/BoolArgumentType.js +3 -5
- package/dist/arguments/FloatArgumentType.d.ts +2 -1
- package/dist/arguments/FloatArgumentType.js +5 -4
- package/dist/arguments/IntegerArgumentType.d.ts +2 -1
- package/dist/arguments/IntegerArgumentType.js +5 -4
- package/dist/arguments/LongArgumentType.d.ts +2 -1
- package/dist/arguments/LongArgumentType.js +5 -4
- package/dist/arguments/NumberArgumentType.d.ts +3 -1
- package/dist/arguments/NumberArgumentType.js +2 -2
- package/dist/arguments/StringArgumentType.d.ts +2 -1
- package/dist/arguments/StringArgumentType.js +2 -2
- package/dist/builder/ArgumentBuilder.d.ts +5 -2
- package/dist/builder/ArgumentBuilder.js +4 -3
- package/dist/builder/LiteralArgumentBuilder.d.ts +3 -2
- package/dist/builder/LiteralArgumentBuilder.js +4 -3
- package/dist/builder/RequiredArgumentBuilder.d.ts +4 -2
- package/dist/builder/RequiredArgumentBuilder.js +4 -3
- package/dist/context/CommandContext.d.ts +8 -3
- package/dist/context/CommandContextBuilder.d.ts +10 -3
- package/dist/context/CommandContextBuilder.js +12 -9
- package/dist/context/ParsedArgument.d.ts +1 -1
- package/dist/context/ParsedArgument.js +2 -2
- package/dist/context/ParsedCommandNode.d.ts +2 -1
- package/dist/context/SuggestionContext.d.ts +1 -1
- package/dist/exceptions/CommandErrorType.d.ts +3 -2
- package/dist/exceptions/CommandErrorType.js +3 -3
- package/dist/exceptions/CommandSyntaxError.d.ts +1 -1
- package/dist/exceptions/CommandSyntaxError.js +23 -23
- package/dist/index.d.ts +18 -18
- package/dist/index.js +18 -18
- package/dist/suggestion/Suggestion.d.ts +1 -1
- package/dist/suggestion/Suggestions.d.ts +2 -1
- package/dist/suggestion/Suggestions.js +3 -3
- package/dist/suggestion/SuggestionsBuilder.d.ts +1 -1
- package/dist/suggestion/SuggestionsBuilder.js +5 -3
- package/dist/tree/ArgumentCommandNode.d.ts +10 -1
- package/dist/tree/ArgumentCommandNode.js +4 -3
- package/dist/tree/CommandNode.d.ts +8 -1
- package/dist/tree/LiteralCommandNode.d.ts +9 -1
- package/dist/tree/LiteralCommandNode.js +8 -5
- package/dist/tree/RootCommandNode.d.ts +6 -1
- package/dist/tree/RootCommandNode.js +4 -3
- package/package.json +1 -1
- package/src/Command.ts +3 -2
- package/src/CommandDispatcher.ts +5 -5
- package/src/ParseResults.ts +1 -1
- package/src/arguments/ArgumentType.ts +5 -7
- package/src/arguments/BoolArgumentType.ts +6 -7
- package/src/arguments/FloatArgumentType.ts +3 -1
- package/src/arguments/IntegerArgumentType.ts +3 -1
- package/src/arguments/LongArgumentType.ts +3 -1
- package/src/arguments/NumberArgumentType.ts +3 -1
- package/src/arguments/StringArgumentType.ts +2 -1
- package/src/builder/ArgumentBuilder.ts +6 -8
- package/src/builder/LiteralArgumentBuilder.ts +3 -2
- package/src/builder/RequiredArgumentBuilder.ts +4 -2
- package/src/context/CommandContext.ts +10 -12
- package/src/context/CommandContextBuilder.ts +12 -14
- package/src/context/ParsedArgument.ts +1 -1
- package/src/context/ParsedCommandNode.ts +2 -1
- package/src/context/SuggestionContext.ts +1 -1
- package/src/exceptions/CommandErrorType.ts +3 -2
- package/src/exceptions/CommandSyntaxError.ts +1 -1
- package/src/index.ts +18 -18
- package/src/suggestion/Suggestion.ts +1 -1
- package/src/suggestion/Suggestions.ts +2 -1
- package/src/suggestion/SuggestionsBuilder.ts +3 -1
- package/src/tree/ArgumentCommandNode.ts +11 -13
- package/src/tree/CommandNode.ts +10 -13
- package/src/tree/LiteralCommandNode.ts +11 -13
- package/src/tree/RootCommandNode.ts +6 -8
- package/test/Arguments.test.ts +3 -4
package/dist/Command.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandContext } from "./";
|
|
2
|
-
export type Command<S> = (c: CommandContext<S>) => Promise<number |
|
|
1
|
+
import type { CommandContext } from "./context/CommandContext";
|
|
2
|
+
export type Command<S> = (c: CommandContext<S>) => Promise<number | void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CommandNode, type LiteralArgumentBuilder, type LiteralCommandNode, ParseResults, RootCommandNode, StringReader, Suggestions } from ".";
|
|
2
2
|
export declare class CommandDispatcher<S> {
|
|
3
3
|
private root;
|
|
4
4
|
private static USAGE_OPTIONAL_OPEN;
|
package/dist/ParseResults.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
2
|
+
import type { StringReader } from "../StringReader";
|
|
3
|
+
import { Suggestions } from "../suggestion/Suggestions";
|
|
4
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
2
5
|
export declare abstract class ArgumentType<T> {
|
|
3
6
|
abstract parse(reader: StringReader): T;
|
|
4
|
-
listSuggestions(context: CommandContext<
|
|
7
|
+
listSuggestions(context: CommandContext<unknown>, builder: SuggestionsBuilder): Promise<Suggestions>;
|
|
5
8
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArgumentType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const Suggestions_1 = require("../suggestion/Suggestions");
|
|
5
5
|
class ArgumentType {
|
|
6
6
|
listSuggestions(
|
|
7
7
|
// biome-ignore lint/correctness/noUnusedFunctionParameters: optional override
|
|
8
8
|
context,
|
|
9
9
|
// biome-ignore lint/correctness/noUnusedFunctionParameters: optional override
|
|
10
10
|
builder) {
|
|
11
|
-
return
|
|
11
|
+
return Suggestions_1.Suggestions.empty();
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.ArgumentType = ArgumentType;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ArgumentType } from "./ArgumentType";
|
|
2
|
-
import type { StringReader } from "../StringReader";
|
|
3
1
|
import type { CommandContext } from "../context/CommandContext";
|
|
4
|
-
import type {
|
|
2
|
+
import type { StringReader } from "../StringReader";
|
|
5
3
|
import type { Suggestions } from "../suggestion/Suggestions";
|
|
4
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
5
|
+
import { ArgumentType } from "./ArgumentType";
|
|
6
6
|
export declare class BoolArgumentType extends ArgumentType<boolean> {
|
|
7
7
|
parse(reader: StringReader): boolean;
|
|
8
|
-
listSuggestions(
|
|
8
|
+
listSuggestions(_ctx: CommandContext<unknown>, builder: SuggestionsBuilder): Promise<Suggestions>;
|
|
9
9
|
}
|
|
10
10
|
export declare function bool(): BoolArgumentType;
|
|
@@ -7,14 +7,12 @@ class BoolArgumentType extends ArgumentType_1.ArgumentType {
|
|
|
7
7
|
parse(reader) {
|
|
8
8
|
return reader.readBoolean();
|
|
9
9
|
}
|
|
10
|
-
listSuggestions(
|
|
11
|
-
// biome-ignore lint/correctness/noUnusedFunctionParameters: optional override
|
|
12
|
-
context, builder) {
|
|
10
|
+
listSuggestions(_ctx, builder) {
|
|
13
11
|
if ("true".startsWith(builder.getRemaining().toLowerCase())) {
|
|
14
|
-
builder.suggest("true");
|
|
12
|
+
return builder.suggest("true").buildPromise();
|
|
15
13
|
}
|
|
16
14
|
if ("false".startsWith(builder.getRemaining().toLowerCase())) {
|
|
17
|
-
builder.suggest("false");
|
|
15
|
+
return builder.suggest("false").buildPromise();
|
|
18
16
|
}
|
|
19
17
|
return builder.buildPromise();
|
|
20
18
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { NumberArgumentType } from "./NumberArgumentType";
|
|
2
3
|
export declare class FloatArgumentType extends NumberArgumentType {
|
|
3
4
|
constructor(minimum?: number, maximum?: number);
|
|
4
5
|
readNumber(reader: StringReader): number;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FloatArgumentType = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
|
|
5
|
+
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
|
+
class FloatArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
6
7
|
constructor(minimum = -Infinity, maximum = Infinity) {
|
|
7
8
|
super(minimum, maximum);
|
|
8
9
|
}
|
|
@@ -10,10 +11,10 @@ class FloatArgumentType extends __1.NumberArgumentType {
|
|
|
10
11
|
return reader.readFloat();
|
|
11
12
|
}
|
|
12
13
|
getTooSmallError() {
|
|
13
|
-
return
|
|
14
|
+
return CommandSyntaxError_1.CommandSyntaxError.FLOAT_TOO_SMALL;
|
|
14
15
|
}
|
|
15
16
|
getTooBigError() {
|
|
16
|
-
return
|
|
17
|
+
return CommandSyntaxError_1.CommandSyntaxError.FLOAT_TOO_BIG;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
exports.FloatArgumentType = FloatArgumentType;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { NumberArgumentType } from "./NumberArgumentType";
|
|
2
3
|
export declare class IntegerArgumentType extends NumberArgumentType {
|
|
3
4
|
constructor(minimum?: number, maximum?: number);
|
|
4
5
|
readNumber(reader: StringReader): number;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IntegerArgumentType = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
|
|
5
|
+
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
|
+
class IntegerArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
6
7
|
constructor(minimum = -2147483648, maximum = 2147483647) {
|
|
7
8
|
super(minimum, maximum);
|
|
8
9
|
}
|
|
@@ -10,10 +11,10 @@ class IntegerArgumentType extends __1.NumberArgumentType {
|
|
|
10
11
|
return reader.readInt();
|
|
11
12
|
}
|
|
12
13
|
getTooSmallError() {
|
|
13
|
-
return
|
|
14
|
+
return CommandSyntaxError_1.CommandSyntaxError.INTEGER_TOO_SMALL;
|
|
14
15
|
}
|
|
15
16
|
getTooBigError() {
|
|
16
|
-
return
|
|
17
|
+
return CommandSyntaxError_1.CommandSyntaxError.INTEGER_TOO_BIG;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
exports.IntegerArgumentType = IntegerArgumentType;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { NumberArgumentType } from "./NumberArgumentType";
|
|
2
3
|
export declare class LongArgumentType extends NumberArgumentType<bigint> {
|
|
3
4
|
private static readonly MIN;
|
|
4
5
|
private static readonly MAX;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LongArgumentType = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
|
|
5
|
+
const NumberArgumentType_1 = require("./NumberArgumentType");
|
|
6
|
+
class LongArgumentType extends NumberArgumentType_1.NumberArgumentType {
|
|
6
7
|
constructor(minimum = LongArgumentType.MIN, maximum = LongArgumentType.MAX) {
|
|
7
8
|
super(minimum, maximum);
|
|
8
9
|
}
|
|
@@ -10,10 +11,10 @@ class LongArgumentType extends __1.NumberArgumentType {
|
|
|
10
11
|
return reader.readLong();
|
|
11
12
|
}
|
|
12
13
|
getTooSmallError() {
|
|
13
|
-
return
|
|
14
|
+
return CommandSyntaxError_1.CommandSyntaxError.LONG_TOO_SMALL;
|
|
14
15
|
}
|
|
15
16
|
getTooBigError() {
|
|
16
|
-
return
|
|
17
|
+
return CommandSyntaxError_1.CommandSyntaxError.LONG_TOO_BIG;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
exports.LongArgumentType = LongArgumentType;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { CommandErrorType } from "../exceptions/CommandErrorType";
|
|
2
|
+
import type { StringReader } from "../StringReader";
|
|
3
|
+
import { ArgumentType } from "./ArgumentType";
|
|
2
4
|
export declare abstract class NumberArgumentType<N extends number | bigint = number> extends ArgumentType<N> {
|
|
3
5
|
private minimum;
|
|
4
6
|
private maximum;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NumberArgumentType = void 0;
|
|
4
|
-
const
|
|
5
|
-
class NumberArgumentType extends
|
|
4
|
+
const ArgumentType_1 = require("./ArgumentType");
|
|
5
|
+
class NumberArgumentType extends ArgumentType_1.ArgumentType {
|
|
6
6
|
constructor(minimum, maximum) {
|
|
7
7
|
super();
|
|
8
8
|
this.minimum = minimum;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { ArgumentType } from "./ArgumentType";
|
|
2
3
|
type StringType = "single_word" | "quotable_phrase" | "greedy_phrase";
|
|
3
4
|
export declare class StringArgumentType extends ArgumentType<string> {
|
|
4
5
|
private type;
|
|
@@ -4,8 +4,8 @@ exports.StringArgumentType = void 0;
|
|
|
4
4
|
exports.word = word;
|
|
5
5
|
exports.string = string;
|
|
6
6
|
exports.greedyString = greedyString;
|
|
7
|
-
const
|
|
8
|
-
class StringArgumentType extends
|
|
7
|
+
const ArgumentType_1 = require("./ArgumentType");
|
|
8
|
+
class StringArgumentType extends ArgumentType_1.ArgumentType {
|
|
9
9
|
constructor(type) {
|
|
10
10
|
super();
|
|
11
11
|
this.type = type;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Command } from "../Command";
|
|
2
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
3
|
+
import type { Predicate } from "../Predicate";
|
|
4
|
+
import { CommandNode } from "../tree/CommandNode";
|
|
2
5
|
export type RedirectModifier<S> = (context: CommandContext<S>) => S | S[];
|
|
3
6
|
export declare abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
|
4
7
|
private arguments;
|
|
@@ -9,7 +12,7 @@ export declare abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>
|
|
|
9
12
|
private forks;
|
|
10
13
|
constructor();
|
|
11
14
|
abstract getThis(): T;
|
|
12
|
-
then(argument: ArgumentBuilder<S,
|
|
15
|
+
then<A extends ArgumentBuilder<S, A>>(argument: ArgumentBuilder<S, A> | CommandNode<S>): T;
|
|
13
16
|
executes(command: Command<S>): T;
|
|
14
17
|
requires(requirement: Predicate<S>): T;
|
|
15
18
|
redirect(target: CommandNode<S>, modifier?: RedirectModifier<S>): T;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArgumentBuilder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandNode_1 = require("../tree/CommandNode");
|
|
5
|
+
const RootCommandNode_1 = require("../tree/RootCommandNode");
|
|
5
6
|
class ArgumentBuilder {
|
|
6
7
|
constructor() {
|
|
7
|
-
this.arguments = new
|
|
8
|
+
this.arguments = new RootCommandNode_1.RootCommandNode();
|
|
8
9
|
this.requirement = async (_) => true;
|
|
9
10
|
}
|
|
10
11
|
// biome-ignore lint/suspicious/noThenProperty: proof?
|
|
11
12
|
then(argument) {
|
|
12
|
-
const child = argument instanceof
|
|
13
|
+
const child = argument instanceof CommandNode_1.CommandNode ? argument : argument.build();
|
|
13
14
|
this.arguments.addChild(child);
|
|
14
15
|
return this.getThis();
|
|
15
16
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LiteralCommandNode } from "../tree/LiteralCommandNode";
|
|
2
|
+
import { ArgumentBuilder } from "./ArgumentBuilder";
|
|
2
3
|
export declare class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumentBuilder<S>> {
|
|
3
4
|
private literal;
|
|
4
5
|
constructor(literal: string);
|
|
@@ -6,4 +7,4 @@ export declare class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, Litera
|
|
|
6
7
|
getLiteral(): string;
|
|
7
8
|
build(): LiteralCommandNode<S>;
|
|
8
9
|
}
|
|
9
|
-
export declare function literal<S =
|
|
10
|
+
export declare function literal<S = unknown>(name: string): LiteralArgumentBuilder<S>;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiteralArgumentBuilder = void 0;
|
|
4
4
|
exports.literal = literal;
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const LiteralCommandNode_1 = require("../tree/LiteralCommandNode");
|
|
6
|
+
const ArgumentBuilder_1 = require("./ArgumentBuilder");
|
|
7
|
+
class LiteralArgumentBuilder extends ArgumentBuilder_1.ArgumentBuilder {
|
|
7
8
|
constructor(literal) {
|
|
8
9
|
super();
|
|
9
10
|
this.literal = literal;
|
|
@@ -15,7 +16,7 @@ class LiteralArgumentBuilder extends __1.ArgumentBuilder {
|
|
|
15
16
|
return this.literal;
|
|
16
17
|
}
|
|
17
18
|
build() {
|
|
18
|
-
const result = new
|
|
19
|
+
const result = new LiteralCommandNode_1.LiteralCommandNode(this.getLiteral(), this.getCommand(), this.getRequirement(), this.getRedirect(), this.getRedirectModifier(), this.isFork());
|
|
19
20
|
for (const argument of this.getArguments()) {
|
|
20
21
|
result.addChild(argument);
|
|
21
22
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ArgumentType } from "../arguments/ArgumentType";
|
|
2
|
+
import { ArgumentCommandNode } from "../tree/ArgumentCommandNode";
|
|
3
|
+
import { ArgumentBuilder } from "./ArgumentBuilder";
|
|
2
4
|
export declare class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredArgumentBuilder<S, T>> {
|
|
3
5
|
private name;
|
|
4
6
|
private type;
|
|
@@ -8,4 +10,4 @@ export declare class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, Re
|
|
|
8
10
|
getType(): ArgumentType<T>;
|
|
9
11
|
build(): ArgumentCommandNode<S, T>;
|
|
10
12
|
}
|
|
11
|
-
export declare function argument<S =
|
|
13
|
+
export declare function argument<S = unknown, T = unknown>(name: string, type: ArgumentType<T>): RequiredArgumentBuilder<S, T>;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequiredArgumentBuilder = void 0;
|
|
4
4
|
exports.argument = argument;
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const ArgumentCommandNode_1 = require("../tree/ArgumentCommandNode");
|
|
6
|
+
const ArgumentBuilder_1 = require("./ArgumentBuilder");
|
|
7
|
+
class RequiredArgumentBuilder extends ArgumentBuilder_1.ArgumentBuilder {
|
|
7
8
|
constructor(name, type) {
|
|
8
9
|
super();
|
|
9
10
|
this.name = name;
|
|
@@ -19,7 +20,7 @@ class RequiredArgumentBuilder extends __1.ArgumentBuilder {
|
|
|
19
20
|
return this.type;
|
|
20
21
|
}
|
|
21
22
|
build() {
|
|
22
|
-
const result = new
|
|
23
|
+
const result = new ArgumentCommandNode_1.ArgumentCommandNode(this.getName(), this.getType(), this.getCommand(), this.getRequirement(), this.getRedirect(), this.getRedirectModifier(), this.isFork());
|
|
23
24
|
for (const argument of this.getArguments()) {
|
|
24
25
|
result.addChild(argument);
|
|
25
26
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
2
|
+
import type { Command } from "../Command";
|
|
3
|
+
import type { CommandNode } from "../tree/CommandNode";
|
|
4
|
+
import type { ParsedArgument } from "./ParsedArgument";
|
|
5
|
+
import type { ParsedCommandNode } from "./ParsedCommandNode";
|
|
6
|
+
import type { StringRange } from "./StringRange";
|
|
2
7
|
export declare class CommandContext<S> {
|
|
3
8
|
private source;
|
|
4
9
|
private input;
|
|
@@ -10,14 +15,14 @@ export declare class CommandContext<S> {
|
|
|
10
15
|
private range;
|
|
11
16
|
private modifier;
|
|
12
17
|
private forks;
|
|
13
|
-
constructor(source: S, input: string, parsedArguments: Map<string, ParsedArgument<
|
|
18
|
+
constructor(source: S, input: string, parsedArguments: Map<string, ParsedArgument<unknown>>, command: Command<S>, rootNode: CommandNode<S>, nodes: ParsedCommandNode<S>[], range: StringRange, child: CommandContext<S>, modifier: RedirectModifier<S>, forks: boolean);
|
|
14
19
|
copyFor(source: S): CommandContext<S>;
|
|
15
20
|
getChild(): CommandContext<S>;
|
|
16
21
|
getLastChild(): CommandContext<S>;
|
|
17
22
|
getCommand(): Command<S>;
|
|
18
23
|
getSource(): S;
|
|
19
24
|
getRootNode(): CommandNode<S>;
|
|
20
|
-
get(name: string):
|
|
25
|
+
get<R = unknown>(name: string): R;
|
|
21
26
|
getRedirectModifier(): RedirectModifier<S>;
|
|
22
27
|
getRange(): StringRange;
|
|
23
28
|
getInput(): string;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Command } from "../Command";
|
|
2
|
+
import type { CommandDispatcher } from "../CommandDispatcher";
|
|
3
|
+
import type { CommandNode } from "../tree/CommandNode";
|
|
4
|
+
import { CommandContext } from "./CommandContext";
|
|
5
|
+
import type { ParsedArgument } from "./ParsedArgument";
|
|
6
|
+
import { ParsedCommandNode } from "./ParsedCommandNode";
|
|
7
|
+
import { StringRange } from "./StringRange";
|
|
8
|
+
import { SuggestionContext } from "./SuggestionContext";
|
|
2
9
|
export declare class CommandContextBuilder<S> {
|
|
3
10
|
private source;
|
|
4
11
|
private arguments;
|
|
@@ -14,8 +21,8 @@ export declare class CommandContextBuilder<S> {
|
|
|
14
21
|
withSource(source: S): CommandContextBuilder<S>;
|
|
15
22
|
getSource(): S;
|
|
16
23
|
getRootNode(): CommandNode<S>;
|
|
17
|
-
withArgument(name: string, argument: ParsedArgument<
|
|
18
|
-
getArguments(): Map<string, ParsedArgument<
|
|
24
|
+
withArgument(name: string, argument: ParsedArgument<unknown>): CommandContextBuilder<S>;
|
|
25
|
+
getArguments(): Map<string, ParsedArgument<unknown>>;
|
|
19
26
|
withChild(child: CommandContextBuilder<S>): CommandContextBuilder<S>;
|
|
20
27
|
getChild(): CommandContextBuilder<S>;
|
|
21
28
|
getLastChild(): CommandContextBuilder<S>;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandContextBuilder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandContext_1 = require("./CommandContext");
|
|
5
|
+
const ParsedCommandNode_1 = require("./ParsedCommandNode");
|
|
6
|
+
const StringRange_1 = require("./StringRange");
|
|
7
|
+
const SuggestionContext_1 = require("./SuggestionContext");
|
|
5
8
|
class CommandContextBuilder {
|
|
6
9
|
constructor(dispatcher, source, rootNode, start) {
|
|
7
10
|
this.dispatcher = dispatcher;
|
|
8
11
|
this.source = source;
|
|
9
12
|
this.rootNode = rootNode;
|
|
10
|
-
this.range =
|
|
13
|
+
this.range = StringRange_1.StringRange.at(start);
|
|
11
14
|
this.nodes = [];
|
|
12
15
|
this.arguments = new Map();
|
|
13
16
|
}
|
|
@@ -50,8 +53,8 @@ class CommandContextBuilder {
|
|
|
50
53
|
return this.command;
|
|
51
54
|
}
|
|
52
55
|
withNode(node, range) {
|
|
53
|
-
this.nodes.push(new
|
|
54
|
-
this.range =
|
|
56
|
+
this.nodes.push(new ParsedCommandNode_1.ParsedCommandNode(node, range));
|
|
57
|
+
this.range = StringRange_1.StringRange.encompassing(this.range, range);
|
|
55
58
|
this.modifier = node.getRedirectModifier();
|
|
56
59
|
this.forks = node.isFork();
|
|
57
60
|
return this;
|
|
@@ -72,7 +75,7 @@ class CommandContextBuilder {
|
|
|
72
75
|
}
|
|
73
76
|
build(input) {
|
|
74
77
|
const child = this.child == null ? null : this.child.build(input);
|
|
75
|
-
return new
|
|
78
|
+
return new CommandContext_1.CommandContext(this.source, input, this.arguments, this.command, this.rootNode, this.nodes, this.range, child, this.modifier, this.forks);
|
|
76
79
|
}
|
|
77
80
|
getDispatcher() {
|
|
78
81
|
return this.dispatcher;
|
|
@@ -88,10 +91,10 @@ class CommandContextBuilder {
|
|
|
88
91
|
}
|
|
89
92
|
else if (this.nodes.length > 0) {
|
|
90
93
|
const last = this.nodes[this.nodes.length - 1];
|
|
91
|
-
return new
|
|
94
|
+
return new SuggestionContext_1.SuggestionContext(last.getNode(), last.getRange().getEnd() + 1);
|
|
92
95
|
}
|
|
93
96
|
else {
|
|
94
|
-
return new
|
|
97
|
+
return new SuggestionContext_1.SuggestionContext(this.rootNode, this.range.getStart());
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
else {
|
|
@@ -99,14 +102,14 @@ class CommandContextBuilder {
|
|
|
99
102
|
for (const node of this.nodes) {
|
|
100
103
|
const nodeRange = node.getRange();
|
|
101
104
|
if (nodeRange.getStart() <= cursor && cursor <= nodeRange.getEnd()) {
|
|
102
|
-
return new
|
|
105
|
+
return new SuggestionContext_1.SuggestionContext(prev, nodeRange.getStart());
|
|
103
106
|
}
|
|
104
107
|
prev = node.getNode();
|
|
105
108
|
}
|
|
106
109
|
if (prev === null) {
|
|
107
110
|
throw new Error("Can't find node before cursor");
|
|
108
111
|
}
|
|
109
|
-
return new
|
|
112
|
+
return new SuggestionContext_1.SuggestionContext(prev, this.range.getStart());
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
throw new Error("Can't find node before cursor");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedArgument = void 0;
|
|
4
|
-
const
|
|
4
|
+
const StringRange_1 = require("./StringRange");
|
|
5
5
|
class ParsedArgument {
|
|
6
6
|
constructor(start, end, result) {
|
|
7
|
-
this.range = new
|
|
7
|
+
this.range = new StringRange_1.StringRange(start, end);
|
|
8
8
|
this.result = result;
|
|
9
9
|
}
|
|
10
10
|
getRange() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { CommandSyntaxError } from "./CommandSyntaxError";
|
|
3
|
+
type CommandErrorFunction = <A = unknown>(...args: A[]) => string;
|
|
3
4
|
export declare class CommandErrorType {
|
|
4
5
|
private func;
|
|
5
6
|
constructor(func: CommandErrorFunction);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandErrorType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandSyntaxError_1 = require("./CommandSyntaxError");
|
|
5
5
|
class CommandErrorType {
|
|
6
6
|
constructor(func) {
|
|
7
7
|
this.func = func;
|
|
8
8
|
}
|
|
9
9
|
create(...args) {
|
|
10
10
|
const message = this.func(...args);
|
|
11
|
-
return new
|
|
11
|
+
return new CommandSyntaxError_1.CommandSyntaxError(message);
|
|
12
12
|
}
|
|
13
13
|
createWithContext(reader, ...args) {
|
|
14
14
|
const message = this.func(...args);
|
|
15
|
-
return new
|
|
15
|
+
return new CommandSyntaxError_1.CommandSyntaxError(message, reader.getString(), reader.getCursor());
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.CommandErrorType = CommandErrorType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandSyntaxError = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandErrorType_1 = require("./CommandErrorType");
|
|
5
5
|
const CONTEXT_AMOUNT = 10;
|
|
6
6
|
class CommandSyntaxError extends Error {
|
|
7
7
|
constructor(message, input, cursor) {
|
|
@@ -19,25 +19,25 @@ class CommandSyntaxError extends Error {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.CommandSyntaxError = CommandSyntaxError;
|
|
22
|
-
CommandSyntaxError.DOUBLE_TOO_SMALL = new
|
|
23
|
-
CommandSyntaxError.DOUBLE_TOO_BIG = new
|
|
24
|
-
CommandSyntaxError.FLOAT_TOO_SMALL = new
|
|
25
|
-
CommandSyntaxError.FLOAT_TOO_BIG = new
|
|
26
|
-
CommandSyntaxError.INTEGER_TOO_SMALL = new
|
|
27
|
-
CommandSyntaxError.INTEGER_TOO_BIG = new
|
|
28
|
-
CommandSyntaxError.LONG_TOO_SMALL = new
|
|
29
|
-
CommandSyntaxError.LONG_TOO_BIG = new
|
|
30
|
-
CommandSyntaxError.LITERAL_INCORRECT = new
|
|
31
|
-
CommandSyntaxError.READER_EXPECTED_START_OF_QUOTE = new
|
|
32
|
-
CommandSyntaxError.READER_EXPECTED_END_OF_QUOTE = new
|
|
33
|
-
CommandSyntaxError.READER_INVALID_ESCAPE = new
|
|
34
|
-
CommandSyntaxError.READER_INVALID_BOOL = new
|
|
35
|
-
CommandSyntaxError.READER_EXPECTED_BOOL = new
|
|
36
|
-
CommandSyntaxError.READER_INVALID_INT = new
|
|
37
|
-
CommandSyntaxError.READER_EXPECTED_INT = new
|
|
38
|
-
CommandSyntaxError.READER_INVALID_FLOAT = new
|
|
39
|
-
CommandSyntaxError.READER_EXPECTED_FLOAT = new
|
|
40
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND = new
|
|
41
|
-
CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT = new
|
|
42
|
-
CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR = new
|
|
43
|
-
CommandSyntaxError.DISPATCHER_PARSE_ERROR = new
|
|
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}`);
|