CommandsInterpreter WIP
This commit is contained in:
parent
65e85f362c
commit
b1c9e3dae5
13
src/logic/CommandsInterpreter.cpp
Normal file
13
src/logic/CommandsInterpreter.cpp
Normal 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) {
|
||||
|
||||
}
|
||||
54
src/logic/CommandsInterpreter.hpp
Normal file
54
src/logic/CommandsInterpreter.hpp
Normal 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_
|
||||
Loading…
x
Reference in New Issue
Block a user