Skip to content

Commit

Permalink
[XML parsing] Add sequence checker child node validation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryLeMasurier authored Jun 2, 2021
1 parent ea61748 commit 4f9fd7c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,45 @@ void VerifyXML(const std::string& xml_text,
"A Control node must have at least 1 child");
}
}
else if (StrEqual(name, "CheckerSequence"))
{
if (children_count < 3)
{
ThrowError(node->GetLineNum(),
"A CheckerSequence node must have at least 3 children");
}
auto child = node->FirstChildElement();
if(child == nullptr)
ThrowError(node->GetLineNum(),
"A CheckerSequence node must have a condition node as its first child");
else if(!StrEqual(child->Name(), "Condition"))
ThrowError(child->GetLineNum(),
"A CheckerSequence node must have a condition node as its first child");

for (; child != nullptr; child = child->NextSiblingElement())
{
if(!StrEqual(child->Name(), "Condition"))
break;
}
if(child == nullptr)
ThrowError(node->GetLineNum(),
"A CheckerSequence node must have an Action node following the first set of Condition nodes");
else if(!StrEqual(child->Name(), "Action"))
ThrowError(child->GetLineNum(),
"A CheckerSequence node must have an Action node following the first set of Condition nodes");
if(child != nullptr)
child = child->NextSiblingElement();
if(child == nullptr)
ThrowError(node->GetLineNum(),
"A CheckerSequence node must have a Condition node following the Action node");
for (; child != nullptr; child = child->NextSiblingElement())
{
if(!StrEqual(child->Name(), "Condition"))
ThrowError(child->GetLineNum(),
"A CheckerSequence node must only have Condition nodes following the Action node");
}

}
else if (StrEqual(name, "SubTree"))
{
for (auto child = node->FirstChildElement(); child != nullptr;
Expand Down

0 comments on commit 4f9fd7c

Please sign in to comment.