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 {
|
||||
double cooldown;
|
||||
std::string questionText;
|
||||
std::string section;
|
||||
|
||||
virtual std::string toString() const = 0;
|
||||
virtual ~Question() = default;
|
||||
|
||||
@@ -34,7 +34,8 @@ void initTransitions() {
|
||||
TokenType::EndOfFile,
|
||||
};
|
||||
(*transitions)[TokenType::MatchGroupEnd] = {
|
||||
TokenType::ElementDashStart
|
||||
TokenType::ElementDashStart,
|
||||
TokenType::EndOfFile
|
||||
};
|
||||
(*transitions)[TokenType::QuestionEnd] = {
|
||||
TokenType::ElementDashStart,
|
||||
@@ -94,7 +95,7 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
||||
};
|
||||
return {
|
||||
.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(&nextToken.tokenType)))
|
||||
),
|
||||
@@ -106,9 +107,6 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
||||
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
|
||||
* 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;
|
||||
|
||||
if (debug) {
|
||||
@@ -346,7 +343,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
auto *question = new GroupQuestion();
|
||||
question->cooldown = cooldown;
|
||||
question->questionText = questionText;
|
||||
question->section = section;
|
||||
|
||||
// Izveido grupas; i - elementu iterators; k - grupu iterators.
|
||||
int32_t k = -1;
|
||||
@@ -375,7 +371,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
auto *question = new MultiElementQuestion();
|
||||
question->cooldown = cooldown;
|
||||
question->questionText = cleanContent(questionText);
|
||||
question->section = section;
|
||||
|
||||
// Izveido vairāku elementu jautājumu.
|
||||
auto existingElements = std::set<std::string>();
|
||||
@@ -413,6 +408,11 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
std::cout << question->toString() << "\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return makeResult(
|
||||
"Jautājums nevar būt bez atbildes elementiem",
|
||||
questionStartToken
|
||||
);
|
||||
}
|
||||
} else if (tokens[i].tokenType == TokenType::EndOfFile) {
|
||||
if (debug) {
|
||||
@@ -453,8 +453,7 @@ std::string MultiElementQuestion::toString() const {
|
||||
ss << opener << " " << choice.answer << "; ";
|
||||
}
|
||||
return std::format(
|
||||
"<Vairāku elementu jautājums>\nsekcija:{}\npārtraukums:{}\n{}\n{}",
|
||||
section,
|
||||
"<Vairāku elementu jautājums>\npārtraukums:{}\n{}\n{}",
|
||||
cooldown,
|
||||
questionText,
|
||||
ss.str()
|
||||
@@ -474,8 +473,7 @@ std::string GroupQuestion::toString() const {
|
||||
ss << "; ";
|
||||
}
|
||||
return std::format(
|
||||
"<Grupas jautājums>\nsekcija:{}\npārtraukums:{}\n{}\n{}",
|
||||
section,
|
||||
"<Grupas jautājums>\npārtraukums:{}\n{}\n{}",
|
||||
cooldown,
|
||||
questionText,
|
||||
ss.str()
|
||||
|
||||
Reference in New Issue
Block a user