CommandsInterpreter WIP

This commit is contained in:
MihailRis 2024-05-08 23:14:15 +03:00
parent 65e85f362c
commit b1c9e3dae5
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,13 @@
#include "CommandsInterpreter.hpp"
#include "../coders/commons.hpp"
using namespace cmd;
class SchemeParser : BasicParser {
};
Command Command::create(std::string_view scheme) {
}

View File

@ -0,0 +1,54 @@
#ifndef LOGIC_COMMANDS_INTERPRETER_HPP_
#define LOGIC_COMMANDS_INTERPRETER_HPP_
#include "../data/dynamic.hpp"
#include <string>
#include <vector>
#include <functional>
namespace cmd {
enum class ArgType {
number, integer, enumvalue, selector, string
};
struct Argument {
std::string name;
ArgType type;
bool optional;
dynamic::Value def;
};
struct CommandInput {
dynamic::List_sptr args; // positional arguments list
dynamic::Map_sptr kwargs; // keyword arguments table
};
using executor_func = std::function<dynamic::Value(
dynamic::List_sptr args,
dynamic::Map_sptr kwargs
)>;
class Command {
std::string name;
std::vector<Argument> args;
executor_func executor;
public:
Command(
std::string name,
std::vector<Argument> args,
executor_func executor
);
dynamic::Value execute(const CommandInput& input) {
return executor(input.args, input.kwargs);
}
static Command create(std::string_view scheme);
};
class CommandsInterpreter {
};
}
#endif // LOGIC_COMMANDS_INTERPRETER_HPP_