mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-01 09:17:19 +02:00
Parser
- ::findIdSequence now safely removes nodes out of the iterator loop.
This commit is contained in:
parent
4f1b63ff02
commit
f898953a2e
1 changed files with 147 additions and 134 deletions
281
src/Parser.cpp
281
src/Parser.cpp
|
@ -1273,159 +1273,172 @@ void Parser::findAttributeModifier ()
|
||||||
void Parser::findIdSequence ()
|
void Parser::findIdSequence ()
|
||||||
{
|
{
|
||||||
context.debug ("Parser::findIdSequence");
|
context.debug ("Parser::findIdSequence");
|
||||||
bool action = false;
|
bool action = true;
|
||||||
|
|
||||||
std::vector <Tree*> nodes;
|
do
|
||||||
collect (nodes);
|
|
||||||
std::vector <Tree*>::iterator i;
|
|
||||||
for (i = nodes.begin (); i != nodes.end (); ++i)
|
|
||||||
{
|
{
|
||||||
// Container for min/max ID ranges.
|
action = false;
|
||||||
std::vector <std::pair <int, int> > ranges;
|
|
||||||
|
|
||||||
// Split the ID list into elements.
|
std::vector <Tree*> nodes;
|
||||||
std::string raw = (*i)->attribute ("raw");
|
collect (nodes, collectAll);
|
||||||
std::vector <std::string> elements;
|
std::vector <Tree*>::iterator i;
|
||||||
split (elements, raw, ',');
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
|
|
||||||
bool not_an_id = false;
|
|
||||||
std::vector <std::string>::iterator e;
|
|
||||||
for (e = elements.begin (); e != elements.end (); ++e)
|
|
||||||
{
|
{
|
||||||
// Split the ID range into min/max.
|
std::string raw = (*i)->attribute ("raw");
|
||||||
std::vector <std::string> terms;
|
|
||||||
split (terms, *e, '-');
|
|
||||||
|
|
||||||
if (terms.size () == 1)
|
if (raw == "--")
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (! (*i)->hasTag ("?"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Container for min/max ID ranges.
|
||||||
|
std::vector <std::pair <int, int> > ranges;
|
||||||
|
|
||||||
|
// Split the ID list into elements.
|
||||||
|
std::vector <std::string> elements;
|
||||||
|
split (elements, raw, ',');
|
||||||
|
|
||||||
|
bool not_an_id = false;
|
||||||
|
std::vector <std::string>::iterator e;
|
||||||
|
for (e = elements.begin (); e != elements.end (); ++e)
|
||||||
{
|
{
|
||||||
if (! digitsOnly (terms[0]))
|
// Split the ID range into min/max.
|
||||||
|
std::vector <std::string> terms;
|
||||||
|
split (terms, *e, '-');
|
||||||
|
|
||||||
|
if (terms.size () == 1)
|
||||||
{
|
{
|
||||||
not_an_id = true;
|
if (! digitsOnly (terms[0]))
|
||||||
break;
|
{
|
||||||
|
not_an_id = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nibbler n (terms[0]);
|
||||||
|
int id;
|
||||||
|
if (n.getUnsignedInt (id) &&
|
||||||
|
n.depleted ())
|
||||||
|
{
|
||||||
|
ranges.push_back (std::pair <int, int> (id, id));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
not_an_id = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (terms.size () == 2)
|
||||||
|
{
|
||||||
|
if (! digitsOnly (terms[0]) ||
|
||||||
|
! digitsOnly (terms[1]))
|
||||||
|
{
|
||||||
|
not_an_id = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nibbler n_min (terms[0]);
|
||||||
|
Nibbler n_max (terms[1]);
|
||||||
|
int id_min;
|
||||||
|
int id_max;
|
||||||
|
if (n_min.getUnsignedInt (id_min) &&
|
||||||
|
n_min.depleted () &&
|
||||||
|
n_max.getUnsignedInt (id_max) &&
|
||||||
|
n_max.depleted ())
|
||||||
|
{
|
||||||
|
if (id_min > id_max)
|
||||||
|
throw std::string (STRING_PARSER_RANGE_INVERTED);
|
||||||
|
|
||||||
|
ranges.push_back (std::pair <int, int> (id_min, id_max));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
not_an_id = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not_an_id)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Now convert the ranges into an infix expression.
|
||||||
|
(*i)->unTag ("?");
|
||||||
|
(*i)->removeAllBranches ();
|
||||||
|
(*i)->tag ("ID");
|
||||||
|
|
||||||
|
Tree* branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "(");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
std::vector <std::pair <int, int> >::iterator r;
|
||||||
|
for (r = ranges.begin (); r != ranges.end (); ++r)
|
||||||
|
{
|
||||||
|
if (r != ranges.begin ())
|
||||||
|
{
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "or");
|
||||||
|
branch->tag ("OP");
|
||||||
}
|
}
|
||||||
|
|
||||||
Nibbler n (terms[0]);
|
if (r->first == r->second)
|
||||||
int id;
|
|
||||||
if (n.getUnsignedInt (id) &&
|
|
||||||
n.depleted ())
|
|
||||||
{
|
{
|
||||||
ranges.push_back (std::pair <int, int> (id, id));
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "id");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "==");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", r->first);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
not_an_id = true;
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
break;
|
branch->attribute ("raw", "(");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "id");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", ">=");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", r->first);
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "and");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "id");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", "<=");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", r->second);
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
|
branch->attribute ("raw", ")");
|
||||||
|
branch->tag ("OP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (terms.size () == 2)
|
|
||||||
{
|
|
||||||
if (! digitsOnly (terms[0]) ||
|
|
||||||
! digitsOnly (terms[1]))
|
|
||||||
{
|
|
||||||
not_an_id = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Nibbler n_min (terms[0]);
|
branch = (*i)->addBranch (new Tree ("argSeq"));
|
||||||
Nibbler n_max (terms[1]);
|
branch->attribute ("raw", ")");
|
||||||
int id_min;
|
branch->tag ("OP");
|
||||||
int id_max;
|
action = true;
|
||||||
if (n_min.getUnsignedInt (id_min) &&
|
break;
|
||||||
n_min.depleted () &&
|
|
||||||
n_max.getUnsignedInt (id_max) &&
|
|
||||||
n_max.depleted ())
|
|
||||||
{
|
|
||||||
if (id_min > id_max)
|
|
||||||
throw std::string (STRING_PARSER_RANGE_INVERTED);
|
|
||||||
|
|
||||||
ranges.push_back (std::pair <int, int> (id_min, id_max));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
not_an_id = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not_an_id)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Now convert the ranges into an infix expression.
|
|
||||||
(*i)->unTag ("?");
|
|
||||||
(*i)->removeAllBranches ();
|
|
||||||
(*i)->tag ("ID");
|
|
||||||
|
|
||||||
Tree* branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "(");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
std::vector <std::pair <int, int> >::iterator r;
|
|
||||||
for (r = ranges.begin (); r != ranges.end (); ++r)
|
|
||||||
{
|
|
||||||
if (r != ranges.begin ())
|
|
||||||
{
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "or");
|
|
||||||
branch->tag ("OP");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r->first == r->second)
|
|
||||||
{
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "id");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "==");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", r->first);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "(");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "id");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", ">=");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", r->first);
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "and");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "id");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", "<=");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", r->second);
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", ")");
|
|
||||||
branch->tag ("OP");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argSeq"));
|
|
||||||
branch->attribute ("raw", ")");
|
|
||||||
branch->tag ("OP");
|
|
||||||
action = true;
|
|
||||||
}
|
}
|
||||||
|
while (action);
|
||||||
|
|
||||||
if (action)
|
context.debug (_tree->dump ());
|
||||||
context.debug (_tree->dump ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue