stylistic parsing fixes

This commit is contained in:
jorenchik
2025-01-03 19:40:44 +02:00
parent aebd17f79e
commit 0822ae5f0d
2 changed files with 274 additions and 272 deletions

View File

@@ -546,7 +546,6 @@ Mdem* makeMdem() {
// Aizmuguras saturs.
for (size_t i = 0; i < 20; ++i) {
// @Improve: back label pooling
QLabel *elBackText = new QLabel();
mdem->hBack.addWidget(elBackText);
mdem->backLabels.push_back(elBackText);

View File

@@ -75,7 +75,7 @@ void initTransitions() {
* Pārbauda, vai tekstvienību saraksts atbilst valodas
* definētām pieļaujamām pārejām.
* */
Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
Result<NoneType> validateGrammar(const std::vector<Token>& tokens) {
if (!transitions) {
initTransitions();
}
@@ -125,6 +125,9 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
// kļūdas informāciju.
auto makeResult = [&questions, &time](std::string error, Token token)
-> Result<ParseInfo> {
if (debug) {
std::cout << "SECTION END: PARSER:\n";
}
return {
{ questions, time },
error,
@@ -137,7 +140,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
if (tokens.size() == 0) {
return makeResult("", Token());
}
auto result = ValidateGrammar(tokens);
auto result = validateGrammar(tokens);
if (result.error.length() > 0) {
return makeResult(
result.error,
@@ -145,8 +148,6 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
);
}
size_t i = 0;
if (debug) {
std::cout << "SECTION: PARSER:\n";
}
@@ -157,6 +158,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
return i < tokens.size() && tokens[i].tokenType != TokenType::EndOfFile;
};
size_t i = 0;
// Sākuma datumu un laiku mēģina nolasīt, ja tāds ir norādīts.
if (isInBounds(i) && tokens[i].tokenType == TokenType::TextFragment) {
@@ -191,7 +193,8 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
// Pamata parsēšana.
while (i < tokens.size()) {
if (tokens[i].tokenType == TokenType::ElementDashStart) {
switch (tokens[i].tokenType) {
case TokenType::ElementDashStart: {
std::string questionText;
std::vector<QuestionElement> questionElements;
double cooldown;
@@ -379,9 +382,9 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
i += offset;
}
// Izveido jautājuma objektu.
// Fix: else block - jautājums bez elementiem.
if (questionElements.size() > 0) {
// Izveido jautājuma objektu.
if (isGroupQuestion) {
auto *question = new GroupQuestion();
question->cooldown = cooldown;
@@ -457,22 +460,22 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
questionStartToken
);
}
} else if (tokens[i].tokenType == TokenType::EndOfFile) {
if (debug) {
std::cout << "Fails beidzās: EndOfFile\n";
}
break;
} else {
} break;
case TokenType::EndOfFile: {
return makeResult(
"Negaidīta tekstvienība",
tokens[i]
"",
Token()
);
} break;
default: {
return makeResult(
"",
Token()
);
} break;
}
}
if (debug) {
std::cout << "SECTION END: PARSER:\n";
}
return makeResult(
"",
Token()