29 lines
1 KiB
Java
29 lines
1 KiB
Java
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);
|
|
}
|
|
}
|
|
}
|