UI: RuleTextParser: Minor refactor

This commit is contained in:
Nodir Temirkhodjaev 2024-11-07 10:58:23 +05:00
parent ce9e323f18
commit bf99e98c9d
2 changed files with 27 additions and 19 deletions

View File

@ -97,14 +97,8 @@ bool RuleTextParser::parseLines()
const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_OR); const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_OR);
for (;;) { for (;;) {
if (!skipComments(CharLineBegin)) { if (!parseLineComments())
if (!isEmpty()) {
setError(ErrorUnexpectedStartOfLine, tr("Unexpected start of line"));
return false;
}
break; break;
}
if (!parseLine()) if (!parseLine())
break; break;
@ -115,6 +109,19 @@ bool RuleTextParser::parseLines()
return !hasError(); return !hasError();
} }
bool RuleTextParser::parseLineComments()
{
if (!skipComments(CharLineBegin)) {
if (!isEmpty()) {
setError(ErrorUnexpectedStartOfLine, tr("Unexpected start of line"));
}
return false;
}
return true;
}
bool RuleTextParser::parseLine() bool RuleTextParser::parseLine()
{ {
const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_AND); const int nodeIndex = beginList(FORT_RULE_FILTER_TYPE_LIST_AND);
@ -157,27 +164,27 @@ bool RuleTextParser::parseLineSection(RuleCharTypes expectedSeparator)
if (!nextCharType(CharLineBegin | expectedSeparator, CharSpace)) if (!nextCharType(CharLineBegin | expectedSeparator, CharSpace))
return false; return false;
if (!processSection()) if (!parseSection())
break; break;
} }
return !hasError(); return !hasError();
} }
bool RuleTextParser::processSection() bool RuleTextParser::parseSection()
{ {
if ((m_charType & (CharListBegin | CharBracketBegin | CharDigit | CharValueBegin)) != 0) { if ((m_charType & (CharListBegin | CharBracketBegin | CharDigit | CharValueBegin)) != 0) {
return processSectionBlock(); return parseSectionBlock();
} }
return processSectionChar(); return parseSectionChar();
} }
bool RuleTextParser::processSectionBlock() bool RuleTextParser::parseSectionBlock()
{ {
switch (m_charType) { switch (m_charType) {
case CharListBegin: { case CharListBegin: {
processSectionList(); parseSectionList();
} break; } break;
case CharBracketBegin: { case CharBracketBegin: {
parseBracketValues(); parseBracketValues();
@ -193,7 +200,7 @@ bool RuleTextParser::processSectionBlock()
return false; return false;
} }
bool RuleTextParser::processSectionChar() bool RuleTextParser::parseSectionChar()
{ {
switch (m_charType) { switch (m_charType) {
case CharLetter: { case CharLetter: {
@ -218,7 +225,7 @@ bool RuleTextParser::processSectionChar()
return false; return false;
} }
void RuleTextParser::processSectionList() void RuleTextParser::parseSectionList()
{ {
if (!checkListBegin()) if (!checkListBegin())
return; return;

View File

@ -94,12 +94,13 @@ private:
void setupCharPtr(); void setupCharPtr();
bool parseLines(); bool parseLines();
bool parseLineComments();
bool parseLine(); bool parseLine();
bool parseLineSection(RuleCharTypes expectedSeparator); bool parseLineSection(RuleCharTypes expectedSeparator);
bool processSection(); bool parseSection();
bool processSectionBlock(); bool parseSectionBlock();
bool processSectionChar(); bool parseSectionChar();
void processSectionList(); void parseSectionList();
bool checkListBegin(); bool checkListBegin();
bool checkListEnd(); bool checkListEnd();