fix: fix some bug in lexer
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "lexer.h"
|
||||
|
||||
#include "bs-utility.h"
|
||||
// clang-format off
|
||||
/**
|
||||
* @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 &keyword, double &price) {
|
||||
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);
|
||||
if (std::regex_match(command, main_pattern)) {
|
||||
std::stringstream ss(command);
|
||||
@ -349,6 +350,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN,
|
||||
price = -1;
|
||||
while (ss >> token) {
|
||||
if (token[1] == 'I') {
|
||||
// debugPrint("ISBN's token is ", token);
|
||||
ISBN = token.substr(6);
|
||||
} else if (token[1] == 'n') {
|
||||
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,
|
||||
double &total_cost) {
|
||||
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);
|
||||
if (std::regex_match(command, main_pattern)) {
|
||||
std::stringstream ss(command);
|
||||
|
Reference in New Issue
Block a user