mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
parsing fixes and improvements
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
struct Question {
|
struct Question {
|
||||||
double cooldown;
|
double cooldown;
|
||||||
std::string questionText;
|
std::string questionText;
|
||||||
std::string section;
|
|
||||||
|
|
||||||
virtual std::string toString() const = 0;
|
virtual std::string toString() const = 0;
|
||||||
virtual ~Question() = default;
|
virtual ~Question() = default;
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ void initTransitions() {
|
|||||||
TokenType::EndOfFile,
|
TokenType::EndOfFile,
|
||||||
};
|
};
|
||||||
(*transitions)[TokenType::MatchGroupEnd] = {
|
(*transitions)[TokenType::MatchGroupEnd] = {
|
||||||
TokenType::ElementDashStart
|
TokenType::ElementDashStart,
|
||||||
|
TokenType::EndOfFile
|
||||||
};
|
};
|
||||||
(*transitions)[TokenType::QuestionEnd] = {
|
(*transitions)[TokenType::QuestionEnd] = {
|
||||||
TokenType::ElementDashStart,
|
TokenType::ElementDashStart,
|
||||||
@@ -94,7 +95,7 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
.error=std::format(
|
.error=std::format(
|
||||||
"nekorekta tekstvienību secība: \"{}\" nevar būt pirms \"{}\"",
|
"Nekorekta tekstvienību secība: \"{}\" nevar būt pirms \"{}\"",
|
||||||
std::string(capitalize(Token::toString(&token.tokenType))),
|
std::string(capitalize(Token::toString(&token.tokenType))),
|
||||||
std::string(capitalize(Token::toString(&nextToken.tokenType)))
|
std::string(capitalize(Token::toString(&nextToken.tokenType)))
|
||||||
),
|
),
|
||||||
@@ -106,9 +107,6 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Fix: before EOF is acceptable
|
|
||||||
// @Fix: remove section from questions
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apstrādā tekstvienības, iegūstot datumu un laiku un vienu vai vairākus
|
* Apstrādā tekstvienības, iegūstot datumu un laiku un vienu vai vairākus
|
||||||
* dažāda veida jautājumus. Veiksmes gadījumā atgriež jautājumu norādes un
|
* dažāda veida jautājumus. Veiksmes gadījumā atgriež jautājumu norādes un
|
||||||
@@ -144,7 +142,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string section;
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -346,7 +343,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
auto *question = new GroupQuestion();
|
auto *question = new GroupQuestion();
|
||||||
question->cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
question->questionText = questionText;
|
question->questionText = questionText;
|
||||||
question->section = section;
|
|
||||||
|
|
||||||
// Izveido grupas; i - elementu iterators; k - grupu iterators.
|
// Izveido grupas; i - elementu iterators; k - grupu iterators.
|
||||||
int32_t k = -1;
|
int32_t k = -1;
|
||||||
@@ -375,7 +371,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
auto *question = new MultiElementQuestion();
|
auto *question = new MultiElementQuestion();
|
||||||
question->cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
question->questionText = cleanContent(questionText);
|
question->questionText = cleanContent(questionText);
|
||||||
question->section = section;
|
|
||||||
|
|
||||||
// Izveido vairāku elementu jautājumu.
|
// Izveido vairāku elementu jautājumu.
|
||||||
auto existingElements = std::set<std::string>();
|
auto existingElements = std::set<std::string>();
|
||||||
@@ -413,6 +408,11 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
std::cout << question->toString() << "\n";
|
std::cout << question->toString() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return makeResult(
|
||||||
|
"Jautājums nevar būt bez atbildes elementiem",
|
||||||
|
questionStartToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (tokens[i].tokenType == TokenType::EndOfFile) {
|
} else if (tokens[i].tokenType == TokenType::EndOfFile) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -453,8 +453,7 @@ std::string MultiElementQuestion::toString() const {
|
|||||||
ss << opener << " " << choice.answer << "; ";
|
ss << opener << " " << choice.answer << "; ";
|
||||||
}
|
}
|
||||||
return std::format(
|
return std::format(
|
||||||
"<Vairāku elementu jautājums>\nsekcija:{}\npārtraukums:{}\n{}\n{}",
|
"<Vairāku elementu jautājums>\npārtraukums:{}\n{}\n{}",
|
||||||
section,
|
|
||||||
cooldown,
|
cooldown,
|
||||||
questionText,
|
questionText,
|
||||||
ss.str()
|
ss.str()
|
||||||
@@ -474,8 +473,7 @@ std::string GroupQuestion::toString() const {
|
|||||||
ss << "; ";
|
ss << "; ";
|
||||||
}
|
}
|
||||||
return std::format(
|
return std::format(
|
||||||
"<Grupas jautājums>\nsekcija:{}\npārtraukums:{}\n{}\n{}",
|
"<Grupas jautājums>\npārtraukums:{}\n{}\n{}",
|
||||||
section,
|
|
||||||
cooldown,
|
cooldown,
|
||||||
questionText,
|
questionText,
|
||||||
ss.str()
|
ss.str()
|
||||||
|
|||||||
Reference in New Issue
Block a user