fix: fix some bug in lexer
This commit is contained in:
@ -17,10 +17,10 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
|||||||
std::string cmd;
|
std::string cmd;
|
||||||
while (std::getline(std::cin, cmd)) {
|
while (std::getline(std::cin, cmd)) {
|
||||||
auto result = std::move(engine.Execute(cmd, login_stack));
|
auto result = std::move(engine.Execute(cmd, login_stack));
|
||||||
// debugPrint(cmd);
|
debugPrint(cmd);
|
||||||
for (auto &line : result) {
|
for (auto &line : result) {
|
||||||
std::cout << line << '\n';
|
std::cout << line << '\n';
|
||||||
// debugPrint(line);
|
debugPrint(line);
|
||||||
}
|
}
|
||||||
// debugPrint();
|
// debugPrint();
|
||||||
if (BookStore_ZYM::shut_down) return;
|
if (BookStore_ZYM::shut_down) return;
|
||||||
|
@ -300,11 +300,16 @@ std::vector<std::string> BookStoreEngineClass::ExecuteMOdify(
|
|||||||
double price;
|
double price;
|
||||||
if (!CommandModifyLexer(cmd, new_ISBN, name, author, keyword, price))
|
if (!CommandModifyLexer(cmd, new_ISBN, name, author, keyword, price))
|
||||||
return std::vector<std::string>({"Invalid"});
|
return std::vector<std::string>({"Invalid"});
|
||||||
|
// debugPrint("successfully lexed modify");
|
||||||
|
// debugPrint("modify", new_ISBN, ' ', name, ' ', author, ' ', keyword, ' ',
|
||||||
|
// price);
|
||||||
if (login_stack.empty() ||
|
if (login_stack.empty() ||
|
||||||
user_data_base.GetPrevilege(login_stack.top().first) < 3)
|
user_data_base.GetPrevilege(login_stack.top().first) < 3)
|
||||||
return std::vector<std::string>({"Invalid"});
|
return std::vector<std::string>({"Invalid"});
|
||||||
|
// debugPrint("successfully checked authority");
|
||||||
if (login_stack.top().second == "" || login_stack.top().second == new_ISBN)
|
if (login_stack.top().second == "" || login_stack.top().second == new_ISBN)
|
||||||
return std::vector<std::string>({"Invalid"});
|
return std::vector<std::string>({"Invalid"});
|
||||||
|
// debugPrint("successfully checked ISBN");
|
||||||
if (keyword != "") {
|
if (keyword != "") {
|
||||||
std::vector<std::string> key_list;
|
std::vector<std::string> key_list;
|
||||||
if (!KeyWordSpliter(keyword, key_list, false))
|
if (!KeyWordSpliter(keyword, key_list, false))
|
||||||
@ -316,6 +321,7 @@ std::vector<std::string> BookStoreEngineClass::ExecuteMOdify(
|
|||||||
key_set.insert(i);
|
key_set.insert(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// debugPrint("successfully checked keyword");
|
||||||
book_data_base.ModifyInfo(login_stack.top().second, new_ISBN, name, author,
|
book_data_base.ModifyInfo(login_stack.top().second, new_ISBN, name, author,
|
||||||
keyword, price, -1);
|
keyword, price, -1);
|
||||||
return std::vector<std::string>();
|
return std::vector<std::string>();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
|
#include "bs-utility.h"
|
||||||
// clang-format off
|
// clang-format off
|
||||||
/**
|
/**
|
||||||
* @brief Lexer for command "su"
|
* @brief Lexer for command "su"
|
||||||
@ -336,7 +337,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN,
|
|||||||
std::string &name, std::string &author,
|
std::string &name, std::string &author,
|
||||||
std::string &keyword, double &price) {
|
std::string &keyword, double &price) {
|
||||||
static std::basic_regex main_pattern(
|
static std::basic_regex main_pattern(
|
||||||
R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}\.[0-9]{2})+ *$)",
|
R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}(?:\.[0-9]{1,2})?)+ *$)",
|
||||||
std::regex_constants::optimize);
|
std::regex_constants::optimize);
|
||||||
if (std::regex_match(command, main_pattern)) {
|
if (std::regex_match(command, main_pattern)) {
|
||||||
std::stringstream ss(command);
|
std::stringstream ss(command);
|
||||||
@ -349,6 +350,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN,
|
|||||||
price = -1;
|
price = -1;
|
||||||
while (ss >> token) {
|
while (ss >> token) {
|
||||||
if (token[1] == 'I') {
|
if (token[1] == 'I') {
|
||||||
|
// debugPrint("ISBN's token is ", token);
|
||||||
ISBN = token.substr(6);
|
ISBN = token.substr(6);
|
||||||
} else if (token[1] == 'n') {
|
} else if (token[1] == 'n') {
|
||||||
name = token.substr(6 + 1, token.size() - 7 - 1);
|
name = token.substr(6 + 1, token.size() - 7 - 1);
|
||||||
@ -383,7 +385,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN,
|
|||||||
bool CommandImportLexer(const std::string &command, int &quantity,
|
bool CommandImportLexer(const std::string &command, int &quantity,
|
||||||
double &total_cost) {
|
double &total_cost) {
|
||||||
static std::basic_regex main_pattern(
|
static std::basic_regex main_pattern(
|
||||||
R"(^ *import +[0-9]{1,10} +[0-9]{1,10}\.[0-9]{2} *$)",
|
R"(^ *import +[0-9]{1,10} +[0-9]{1,10}(?:\.[0-9]{1,2})? *$)",
|
||||||
std::regex_constants::optimize);
|
std::regex_constants::optimize);
|
||||||
if (std::regex_match(command, main_pattern)) {
|
if (std::regex_match(command, main_pattern)) {
|
||||||
std::stringstream ss(command);
|
std::stringstream ss(command);
|
||||||
|
Reference in New Issue
Block a user