@wq2/brigadier-ts 1.0.4 → 1.0.5

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.
@@ -1,4 +1,10 @@
1
- import { type CommandNode, type LiteralArgumentBuilder, type LiteralCommandNode, ParseResults, RootCommandNode, StringReader, Suggestions } from ".";
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,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandDispatcher = void 0;
4
- const _1 = require(".");
4
+ const CommandContextBuilder_1 = require("./context/CommandContextBuilder");
5
+ const CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
6
+ const ParseResults_1 = require("./ParseResults");
7
+ const StringReader_1 = require("./StringReader");
8
+ const Suggestions_1 = require("./suggestion/Suggestions");
9
+ const SuggestionsBuilder_1 = require("./suggestion/SuggestionsBuilder");
10
+ const RootCommandNode_1 = require("./tree/RootCommandNode");
5
11
  class CommandDispatcher {
6
12
  constructor() {
7
- this.root = new _1.RootCommandNode();
13
+ this.root = new RootCommandNode_1.RootCommandNode();
8
14
  }
9
15
  register(command) {
10
16
  const build = command.build();
@@ -13,17 +19,17 @@ class CommandDispatcher {
13
19
  }
14
20
  async execute(parse, source) {
15
21
  if (typeof parse === "string") {
16
- parse = await this.parse(new _1.StringReader(parse), source);
22
+ parse = await this.parse(new StringReader_1.StringReader(parse), source);
17
23
  }
18
24
  if (parse.getReader().canRead()) {
19
25
  if (parse.getErrors().size === 1) {
20
26
  throw parse.getErrors().values().next();
21
27
  }
22
28
  else if (parse.getContext().getRange().isEmpty()) {
23
- throw _1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
29
+ throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
24
30
  }
25
31
  else {
26
- throw _1.CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
32
+ throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
27
33
  }
28
34
  }
29
35
  let result = 0;
@@ -78,13 +84,13 @@ class CommandDispatcher {
78
84
  next = [];
79
85
  }
80
86
  if (!foundCommand) {
81
- throw _1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
87
+ throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
82
88
  }
83
89
  return forked ? successfulForks : result;
84
90
  }
85
91
  async parse(reader, source) {
86
- reader = new _1.StringReader(reader);
87
- const context = new _1.CommandContextBuilder(this, source, this.root, reader.getCursor());
92
+ reader = new StringReader_1.StringReader(reader);
93
+ const context = new CommandContextBuilder_1.CommandContextBuilder(this, source, this.root, reader.getCursor());
88
94
  return this.parseNodes(this.root, reader, context);
89
95
  }
90
96
  async parseNodes(node, originalReader, contextSoFar) {
@@ -97,25 +103,25 @@ class CommandDispatcher {
97
103
  continue;
98
104
  }
99
105
  const context = contextSoFar.copy();
100
- const reader = new _1.StringReader(originalReader);
106
+ const reader = new StringReader_1.StringReader(originalReader);
101
107
  try {
102
108
  try {
103
109
  child.parse(reader, context);
104
110
  }
105
111
  catch (e) {
106
- if (e instanceof _1.CommandSyntaxError) {
112
+ if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
107
113
  throw e;
108
114
  }
109
115
  else {
110
- throw _1.CommandSyntaxError.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
116
+ throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
111
117
  }
112
118
  }
113
119
  if (reader.canRead() && reader.peek() !== " ") {
114
- throw _1.CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
120
+ throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
115
121
  }
116
122
  }
117
123
  catch (e) {
118
- if (e instanceof _1.CommandSyntaxError) {
124
+ if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
119
125
  errors.set(child, e);
120
126
  reader.setCursor(cursor);
121
127
  continue;
@@ -128,21 +134,21 @@ class CommandDispatcher {
128
134
  if (reader.canRead(child.getRedirect() === null ? 2 : 1)) {
129
135
  reader.skip();
130
136
  if (child.getRedirect()) {
131
- const childContext = new _1.CommandContextBuilder(this, source, child.getRedirect(), reader.getCursor());
137
+ const childContext = new CommandContextBuilder_1.CommandContextBuilder(this, source, child.getRedirect(), reader.getCursor());
132
138
  const parse = await this.parseNodes(child.getRedirect(), reader, childContext);
133
139
  context.withChild(parse.getContext());
134
- return new _1.ParseResults(context, parse.getReader(), parse.getErrors());
140
+ return new ParseResults_1.ParseResults(context, parse.getReader(), parse.getErrors());
135
141
  }
136
142
  else {
137
143
  potentials.push(this.parseNodes(child, reader, context));
138
144
  }
139
145
  }
140
146
  else {
141
- potentials.push(new _1.ParseResults(context, reader, new Map()));
147
+ potentials.push(new ParseResults_1.ParseResults(context, reader, new Map()));
142
148
  }
143
149
  }
144
150
  if (potentials.length === 0) {
145
- potentials.push(new _1.ParseResults(contextSoFar, originalReader, errors));
151
+ potentials.push(new ParseResults_1.ParseResults(contextSoFar, originalReader, errors));
146
152
  }
147
153
  return potentials[0];
148
154
  }
@@ -187,9 +193,9 @@ class CommandDispatcher {
187
193
  const truncatedInput = fullInput.substring(0, cursor);
188
194
  const promises = [];
189
195
  for (const node of parent.getChildren()) {
190
- let promise = _1.Suggestions.empty();
196
+ let promise = Suggestions_1.Suggestions.empty();
191
197
  try {
192
- promise = node.listSuggestions(context.build(truncatedInput), new _1.SuggestionsBuilder(truncatedInput, start));
198
+ promise = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder_1.SuggestionsBuilder(truncatedInput, start));
193
199
  }
194
200
  catch (ignored) {
195
201
  console.log("???", ignored);
@@ -197,7 +203,7 @@ class CommandDispatcher {
197
203
  promises.push(promise);
198
204
  }
199
205
  const suggestions = await Promise.all(promises);
200
- return _1.Suggestions.merge(fullInput, suggestions);
206
+ return Suggestions_1.Suggestions.merge(fullInput, suggestions);
201
207
  }
202
208
  getSmartUsage(node, source, optional, deep) {
203
209
  if (optional === undefined && deep === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wq2/brigadier-ts",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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,15 +1,13 @@
1
- import {
2
- CommandContextBuilder,
3
- type CommandNode,
4
- CommandSyntaxError,
5
- type LiteralArgumentBuilder,
6
- type LiteralCommandNode,
7
- ParseResults,
8
- RootCommandNode,
9
- StringReader,
10
- Suggestions,
11
- SuggestionsBuilder,
12
- } from ".";
1
+ import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
2
+ import { CommandContextBuilder } from "./context/CommandContextBuilder";
3
+ import { CommandSyntaxError } from "./exceptions/CommandSyntaxError";
4
+ import { ParseResults } from "./ParseResults";
5
+ import { StringReader } from "./StringReader";
6
+ import { Suggestions } from "./suggestion/Suggestions";
7
+ import { SuggestionsBuilder } from "./suggestion/SuggestionsBuilder";
8
+ import type { CommandNode } from "./tree/CommandNode";
9
+ import type { LiteralCommandNode } from "./tree/LiteralCommandNode";
10
+ import { RootCommandNode } from "./tree/RootCommandNode";
13
11
 
14
12
  export class CommandDispatcher<S> {
15
13
  private root: RootCommandNode<S>;