mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
error if sequence question contains duplicates
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <format>
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "lexer.h"
|
||||
#include "result.h"
|
||||
@@ -90,7 +93,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)))
|
||||
),
|
||||
@@ -156,7 +159,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
time = parseToUTCTime(tokens[i].content.c_str(), "%d.%m.%Y %H:%M");
|
||||
} catch (std::exception e) {
|
||||
return makeResult(
|
||||
std::format("Parsēšanas kļūda - {}", e.what()),
|
||||
e.what(),
|
||||
tokens[i]
|
||||
);
|
||||
}
|
||||
@@ -171,6 +174,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
bool isOrderQuestion = false;
|
||||
bool isGroupQuestion = false;
|
||||
bool isPlusQuestion = false;
|
||||
Token questionStartToken;
|
||||
|
||||
// Start element parsing & add to the offset.
|
||||
if (isInBounds(i + 1) && tokens[i + 1].tokenType == TokenType::ElementOrderModifier) {
|
||||
@@ -179,6 +183,8 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
tokens[i + 1]
|
||||
);
|
||||
}
|
||||
|
||||
questionStartToken = tokens[i];
|
||||
if (isInBounds(i + 1) && tokens[i + 1].tokenType == TokenType::CooldownStart) {
|
||||
try {
|
||||
cooldown = std::stod(tokens[i + 2].content);
|
||||
@@ -317,13 +323,29 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
question->cooldown = cooldown;
|
||||
question->questionText = cleanContent(questionText);
|
||||
question->section = section;
|
||||
|
||||
auto existingElements = std::set<std::string>();
|
||||
for (const auto& elem : questionElements) {
|
||||
Choice choice;
|
||||
choice.answer = cleanContent(elem.content);
|
||||
choice.isCorrect = !elem.isDash;
|
||||
question->choices.push_back(choice);
|
||||
|
||||
if (isOrderQuestion) {
|
||||
if (existingElements.contains(choice.answer)) {
|
||||
return makeResult(
|
||||
"Secības jautājumi atbildes nedrīkst atkārtoties",
|
||||
questionStartToken
|
||||
);
|
||||
} else {
|
||||
question->choices.push_back(choice);
|
||||
existingElements.insert(choice.answer);
|
||||
}
|
||||
} else {
|
||||
question->choices.push_back(choice);
|
||||
}
|
||||
}
|
||||
questions.push_back(question);
|
||||
|
||||
if (isPlusQuestion) {
|
||||
question->type = MultiElementType::MultiChoice;
|
||||
} else if (isOrderQuestion) {
|
||||
|
||||
Reference in New Issue
Block a user