refactor: we decide to remove the entire brigadier module
This commit is contained in:
@@ -42,10 +42,6 @@ PRIVATE
|
||||
yycc/carton/binstore/setting.cpp
|
||||
yycc/carton/binstore/configuration.cpp
|
||||
yycc/carton/binstore/storage.cpp
|
||||
yycc/carton/brigadier/types.cpp
|
||||
yycc/carton/brigadier/constraint.cpp
|
||||
yycc/carton/brigadier/node.cpp
|
||||
yycc/carton/brigadier/parser.cpp
|
||||
yycc/carton/lexer61.cpp
|
||||
)
|
||||
target_sources(YYCCommonplace
|
||||
@@ -115,11 +111,6 @@ FILES
|
||||
yycc/carton/binstore/configuration.hpp
|
||||
yycc/carton/binstore/storage.hpp
|
||||
yycc/carton/lexer61.hpp
|
||||
yycc/carton/brigadier.hpp
|
||||
yycc/carton/brigadier/types.hpp
|
||||
yycc/carton/brigadier/constraint.hpp
|
||||
yycc/carton/brigadier/node.hpp
|
||||
yycc/carton/brigadier/parser.hpp
|
||||
yycc/carton/fft.hpp
|
||||
)
|
||||
# Setup header infomations
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace yycc::carton::brigadier {}
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "constraint.hpp"
|
||||
|
||||
namespace yycc::carton::brigadier::constraint {
|
||||
|
||||
#pragma region Validator
|
||||
|
||||
IValidator::IValidator() {}
|
||||
|
||||
IValidator::~IValidator() {}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <concepts>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace yycc::carton::brigadier::constraint {
|
||||
|
||||
class IValidator {
|
||||
public:
|
||||
IValidator();
|
||||
virtual ~IValidator();
|
||||
|
||||
public:
|
||||
virtual bool validate(const std::u8string_view& sv) const = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept Converter = requires(const T& t, const std::u8string_view& sv) {
|
||||
// Check whether there is T::ReturnType type
|
||||
typename T::ReturnType;
|
||||
// Check whether there is "convert" member function and it has correct signature.
|
||||
{ t.convert(sv) } -> std::same_as<typename T::ReturnType>;
|
||||
};
|
||||
|
||||
//template<Converter T>
|
||||
//concept Constraint = requires(const T& t) {
|
||||
// { t.get_validator() } -> std::same_as<std::unique_ptr<IValidator>>;
|
||||
// { t.get_converter() } -> std::same_as<typename T::ReturnType>;
|
||||
//};
|
||||
|
||||
template<typename TValidator, Converter TConverter>
|
||||
requires std::is_base_of_v<IValidator, TValidator>
|
||||
struct Constraint {
|
||||
std::unique_ptr<IValidator> validator() const { throw std::logic_error("not implemented function"); }
|
||||
TConverter converter() const { throw std::logic_error("not implemented function"); }
|
||||
};
|
||||
|
||||
} // namespace yycc::carton::brigadier::constraint
|
||||
@@ -1,73 +0,0 @@
|
||||
#include "types.hpp"
|
||||
#include "../../patch/format.hpp"
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
#define FORMAT ::yycc::patch::format
|
||||
|
||||
namespace yycc::carton::brigadier::types {
|
||||
|
||||
#pragma region ArgumentStack
|
||||
|
||||
ArgumentStack::ArgumentStack(std::vector<std::u8string> &&args) : stack(std::move(args)), cursor(0) {}
|
||||
|
||||
ArgumentStack::~ArgumentStack() {}
|
||||
|
||||
void ArgumentStack::reset() {
|
||||
this->cursor = 0;
|
||||
}
|
||||
|
||||
bool ArgumentStack::empty() const {
|
||||
return cursor >= this->stack.size();
|
||||
}
|
||||
|
||||
std::u8string_view ArgumentStack::peek() const {
|
||||
return std::u8string_view(this->stack.at(this->cursor));
|
||||
}
|
||||
|
||||
void ArgumentStack::push() {
|
||||
if (cursor == 0) throw std::logic_error("no arguments can be pushed");
|
||||
else --cursor;
|
||||
}
|
||||
|
||||
void ArgumentStack::push() {
|
||||
if (cursor >= this->stack.size()) throw std::logic_error("no arguments can be poped");
|
||||
else ++cursor;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region ConflictSet
|
||||
|
||||
ConflictSet::ConflictSet() : inner() {}
|
||||
|
||||
ConflictSet::~ConflictSet() {}
|
||||
|
||||
void ConflictSet::add_literal(const std::u8string_view &value) {
|
||||
if (value.empty()) throw std::invalid_argument("try to insert empty item to conflict set.");
|
||||
auto entry = FORMAT::format(u8"literal:{}", value);
|
||||
|
||||
auto result = this->inner.emplace(std::move(entry));
|
||||
if (!result.second) throw std::runtime_error("try to insert duplicated item in conflict set.");
|
||||
}
|
||||
|
||||
void ConflictSet::add_argument(const std::u8string_view &value) {
|
||||
if (value.empty()) throw std::invalid_argument("try to insert empty item to conflict set.");
|
||||
auto entry = FORMAT::format(u8"argument:{}", value);
|
||||
|
||||
auto result = this->inner.emplace(std::move(entry));
|
||||
if (!result.second) throw std::runtime_error("try to insert duplicated item in conflict set.");
|
||||
}
|
||||
|
||||
bool ConflictSet::is_conflict_with(const ConflictSet &rhs) const {
|
||||
// create a cache to store computed intersection
|
||||
std::vector<std::u8string> intersection;
|
||||
// compute intersection
|
||||
std::set_intersection(this->inner.begin(), this->inner.end(), rhs.inner.begin(), rhs.inner.begin(), std::back_inserter(intersection));
|
||||
// check whether it is empty intersection
|
||||
return !intersection.empty();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
} // namespace yycc::carton::brigadier::types
|
||||
@@ -1,84 +0,0 @@
|
||||
#pragma once
|
||||
#include "../../macro/class_copy_move.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <set>
|
||||
|
||||
namespace yycc::carton::brigadier::types {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @brief A wrapper for argument visiting in brigadier.
|
||||
* @details
|
||||
* When using this stack, the top of stack is the first argument,
|
||||
* and the bottom of stack is the last argument for the convenient calling from brigadier.
|
||||
*
|
||||
* Actually, in all usage, all poped items will be finally pushed with FILO order again.
|
||||
* So I simply use a vector and cursor to represent a fake stack.
|
||||
*/
|
||||
class ArgumentStack {
|
||||
public:
|
||||
ArgumentStack(std::vector<std::u8string>&& args);
|
||||
~ArgumentStack();
|
||||
YYCC_DEFAULT_COPY_MOVE(ArgumentStack)
|
||||
|
||||
public:
|
||||
void reset();
|
||||
bool empty() const;
|
||||
std::u8string_view peek() const;
|
||||
void pop();
|
||||
void push();
|
||||
|
||||
private:
|
||||
std::vector<std::u8string> stack;
|
||||
size_t cursor;
|
||||
};
|
||||
|
||||
/// @private
|
||||
/// @brief Internal node used conflict set for detecting potential conflict.
|
||||
class ConflictSet {
|
||||
public:
|
||||
ConflictSet();
|
||||
~ConflictSet();
|
||||
YYCC_DEFAULT_COPY_MOVE(ConflictSet)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Add literal item into conflict set.
|
||||
* @param[in] value Literal item.
|
||||
* @remarks
|
||||
* \li Literal item is the string input in command line.
|
||||
* \li The word in Literal, and the vocabulary in Choice should be put by this function.
|
||||
* \li Added item will add \c literal: prefix to make it in literal scope,
|
||||
* so that it will not be compared with argument name items.
|
||||
* Because we allow 2 literal item and argument name item have same name.
|
||||
*/
|
||||
void add_literal(const std::u8string_view& value);
|
||||
/**
|
||||
* @brief Add argument name item into conflict
|
||||
* @param[in] value Argument name item.
|
||||
* @remarks
|
||||
* \li Argument name item is the key name put in ArgumentsMap.
|
||||
* \li The argument name in Choice and Argument should be put by this function.
|
||||
* \li Added item will add \c argument: prefix to make it in argument name scope,
|
||||
* so that it will not be compared with literal items.
|
||||
* Because we allow 2 literal item and argument name item have same name.
|
||||
*/
|
||||
void add_argument(const std::u8string_view& value);
|
||||
/**
|
||||
* @brief Check whether this set is conflict with another.
|
||||
* @param[in] rhs The set to be compared.
|
||||
* @return True if they have conflict.
|
||||
* @remarks
|
||||
* This function simply compute the intersection of two set.
|
||||
* If the result is not empty, it means that there is a conflict.
|
||||
*/
|
||||
bool is_conflict_with(const ConflictSet& rhs) const;
|
||||
|
||||
private:
|
||||
std::set<std::u8string> inner;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user