- ::findAttribute now repeats without breaking the iterator.
This commit is contained in:
Paul Beckingham 2014-08-23 17:26:28 -04:00
parent 63808b8920
commit 37614ac6b3

View file

@ -25,7 +25,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <cmake.h> #include <cmake.h>
#include <iostream> // TODO Remove.
#include <algorithm> #include <algorithm>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -964,90 +963,97 @@ void Parser::findTag ()
void Parser::findAttribute () void Parser::findAttribute ()
{ {
context.debug ("Parser::findAttribute"); context.debug ("Parser::findAttribute");
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)
{ {
std::string raw = (*i)->attribute ("raw"); action = false;
Nibbler n (raw);
// Look for a valid attribute name. std::vector <Tree*> nodes;
std::string name; collect (nodes);
if (n.getName (name) && std::vector <Tree*>::iterator i;
name.length ()) for (i = nodes.begin (); i != nodes.end (); ++i)
{ {
if (n.skip (':')) std::string raw = (*i)->attribute ("raw");
Nibbler n (raw);
// Look for a valid attribute name.
std::string name;
if (n.getName (name) &&
name.length ())
{ {
std::string value; if (n.skip (':'))
if (n.getQuoted ('"', value) ||
n.getQuoted ('\'', value) ||
n.getUntilEOS (value) ||
n.depleted ())
{ {
if (value == "") std::string value;
value = "''"; if (n.getQuoted ('"', value) ||
n.getQuoted ('\'', value) ||
std::string canonical; n.getUntilEOS (value) ||
if (canonicalize (canonical, "uda", name)) n.depleted ())
{ {
(*i)->tag ("UDA"); if (value == "")
(*i)->tag ("MODIFIABLE"); value = "''";
action = true;
}
else if (canonicalize (canonical, "pseudo", name)) std::string canonical;
{ if (canonicalize (canonical, "uda", name))
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("PSEUDO");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
action = true;
}
else if (canonicalize (canonical, "attribute", name))
{
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("ATTRIBUTE");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
std::map <std::string, Column*>::const_iterator col;
col = context.columns.find (canonical);
if (col != context.columns.end () &&
col->second->modifiable ())
{ {
(*i)->tag ("UDA");
(*i)->tag ("MODIFIABLE"); (*i)->tag ("MODIFIABLE");
action = true;
} }
Tree* branch = (*i)->addBranch (new Tree ("argAtt")); else if (canonicalize (canonical, "pseudo", name))
branch->attribute ("raw", canonical); {
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("PSEUDO");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
action = true;
break;
}
branch = (*i)->addBranch (new Tree ("argAtt")); else if (canonicalize (canonical, "attribute", name))
branch->tag ("OP"); {
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("ATTRIBUTE");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
// All 'project' attributes are partial matches. std::map <std::string, Column*>::const_iterator col;
if (canonical == "project" || col = context.columns.find (canonical);
canonical == "uuid") if (col != context.columns.end () &&
branch->attribute ("raw", "="); col->second->modifiable ())
else {
branch->attribute ("raw", "=="); (*i)->tag ("MODIFIABLE");
}
branch = (*i)->addBranch (new Tree ("argAtt")); Tree* branch = (*i)->addBranch (new Tree ("argAtt"));
branch->attribute ("raw", value); branch->attribute ("raw", canonical);
action = true;
branch = (*i)->addBranch (new Tree ("argAtt"));
branch->tag ("OP");
// All 'project' attributes are partial matches.
if (canonical == "project" ||
canonical == "uuid")
branch->attribute ("raw", "=");
else
branch->attribute ("raw", "==");
branch = (*i)->addBranch (new Tree ("argAtt"));
branch->attribute ("raw", value);
action = true;
break;
}
} }
} }
} }
} }
} }
while (action);
if (action) context.debug (_tree->dump ());
context.debug (_tree->dump ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////