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:
@@ -99,7 +99,7 @@ Result<ParseInfo> transpile(std::string fileContent) {
|
|||||||
return {
|
return {
|
||||||
{},
|
{},
|
||||||
std::format(
|
std::format(
|
||||||
"Lexical analysis error: {}",
|
"Leksiskās analīzes kļūda: {}",
|
||||||
lexRes.error
|
lexRes.error
|
||||||
),
|
),
|
||||||
lexRes.row,
|
lexRes.row,
|
||||||
@@ -112,10 +112,7 @@ Result<ParseInfo> transpile(std::string fileContent) {
|
|||||||
if (parseRes.error.length() > 0) {
|
if (parseRes.error.length() > 0) {
|
||||||
return {
|
return {
|
||||||
{},
|
{},
|
||||||
std::format(
|
parseRes.error,
|
||||||
"Parsing error: {}",
|
|
||||||
parseRes.error
|
|
||||||
),
|
|
||||||
parseRes.row,
|
parseRes.row,
|
||||||
parseRes.column
|
parseRes.column
|
||||||
};
|
};
|
||||||
@@ -123,7 +120,7 @@ Result<ParseInfo> transpile(std::string fileContent) {
|
|||||||
|
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
if (showTimes) {
|
if (showTimes) {
|
||||||
std::cout << showTime("Transpilation time") << std::endl;
|
std::cout << showTime("Transpilācijas laiks") << std::endl;
|
||||||
}
|
}
|
||||||
return {questions};
|
return {questions};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <exception>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
@@ -90,7 +93,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)))
|
||||||
),
|
),
|
||||||
@@ -156,7 +159,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
time = parseToUTCTime(tokens[i].content.c_str(), "%d.%m.%Y %H:%M");
|
time = parseToUTCTime(tokens[i].content.c_str(), "%d.%m.%Y %H:%M");
|
||||||
} catch (std::exception e) {
|
} catch (std::exception e) {
|
||||||
return makeResult(
|
return makeResult(
|
||||||
std::format("Parsēšanas kļūda - {}", e.what()),
|
e.what(),
|
||||||
tokens[i]
|
tokens[i]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -171,6 +174,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
bool isOrderQuestion = false;
|
bool isOrderQuestion = false;
|
||||||
bool isGroupQuestion = false;
|
bool isGroupQuestion = false;
|
||||||
bool isPlusQuestion = false;
|
bool isPlusQuestion = false;
|
||||||
|
Token questionStartToken;
|
||||||
|
|
||||||
// Start element parsing & add to the offset.
|
// Start element parsing & add to the offset.
|
||||||
if (isInBounds(i + 1) && tokens[i + 1].tokenType == TokenType::ElementOrderModifier) {
|
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]
|
tokens[i + 1]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
questionStartToken = tokens[i];
|
||||||
if (isInBounds(i + 1) && tokens[i + 1].tokenType == TokenType::CooldownStart) {
|
if (isInBounds(i + 1) && tokens[i + 1].tokenType == TokenType::CooldownStart) {
|
||||||
try {
|
try {
|
||||||
cooldown = std::stod(tokens[i + 2].content);
|
cooldown = std::stod(tokens[i + 2].content);
|
||||||
@@ -317,13 +323,29 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
question->cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
question->questionText = cleanContent(questionText);
|
question->questionText = cleanContent(questionText);
|
||||||
question->section = section;
|
question->section = section;
|
||||||
|
|
||||||
|
auto existingElements = std::set<std::string>();
|
||||||
for (const auto& elem : questionElements) {
|
for (const auto& elem : questionElements) {
|
||||||
Choice choice;
|
Choice choice;
|
||||||
choice.answer = cleanContent(elem.content);
|
choice.answer = cleanContent(elem.content);
|
||||||
choice.isCorrect = !elem.isDash;
|
choice.isCorrect = !elem.isDash;
|
||||||
|
|
||||||
|
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);
|
question->choices.push_back(choice);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
questions.push_back(question);
|
questions.push_back(question);
|
||||||
|
|
||||||
if (isPlusQuestion) {
|
if (isPlusQuestion) {
|
||||||
question->type = MultiElementType::MultiChoice;
|
question->type = MultiElementType::MultiChoice;
|
||||||
} else if (isOrderQuestion) {
|
} else if (isOrderQuestion) {
|
||||||
|
|||||||
Reference in New Issue
Block a user