.
This commit is contained in:
parent
b8a2124c80
commit
678762f797
2 changed files with 30 additions and 1 deletions
|
|
@ -9,7 +9,7 @@ public interface LiteralNode<T, S extends CommandContext<T>> {
|
||||||
|
|
||||||
void addLiteral(@NotNull CommandNode<? extends T, ? extends S> commandNode);
|
void addLiteral(@NotNull CommandNode<? extends T, ? extends S> commandNode);
|
||||||
|
|
||||||
CommandNode<? extends T, ? extends S> getLiteral(@NotNull String name);
|
CommandNode<T, S> getLiteral(@NotNull String name);
|
||||||
|
|
||||||
@NotNull Set<CommandNode<? extends T, ? extends S>> getLiterals();
|
@NotNull Set<CommandNode<? extends T, ? extends S>> getLiterals();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package de.kencommand.impl.parsing;
|
||||||
|
|
||||||
|
import de.kencommand.api.processing.CommandContext;
|
||||||
|
import de.kencommand.api.processing.CommandExecutor;
|
||||||
|
import de.kencommand.api.structure.node.CommandNode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CommandNodeParser<T, S extends CommandContext<T>> {
|
||||||
|
|
||||||
|
public CommandExecutor<? extends S> parse(CommandNode<T, S> commandNode, String[] args) {
|
||||||
|
var iter = Arrays.stream(args).iterator();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (!iter.hasNext()) {
|
||||||
|
// literals/arguments are optional if the node itself is executable
|
||||||
|
if (commandNode.getExecutor() == null) throw new RuntimeException("no literal given but required");
|
||||||
|
// TODO parse arguments for executor ig, or rather do that in a separate method
|
||||||
|
return commandNode.getExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
final var arg = iter.next();
|
||||||
|
// TODO rethink
|
||||||
|
return parse(commandNode.getLiteral(arg), args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue