- Modified ::findAttribute to use collect.
This commit is contained in:
Paul Beckingham 2014-08-17 12:28:40 -04:00
parent ed07e47135
commit 56ab8e7920
2 changed files with 72 additions and 60 deletions

View file

@ -181,8 +181,8 @@ Tree* Parser::parse ()
findSubstitution (); findSubstitution ();
findPattern (); findPattern ();
findTag (); findTag ();
findAttribute ();
// GOOD ^^^ // GOOD ^^^
scan (&Parser::findAttribute);
scan (&Parser::findAttributeModifier); scan (&Parser::findAttributeModifier);
scan (&Parser::findOperator); scan (&Parser::findOperator);
findCommand (); findCommand ();
@ -958,81 +958,93 @@ void Parser::findTag ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// <name>:['"][<value>]['"] // <name>:['"][<value>]['"]
void Parser::findAttribute (Tree* t) void Parser::findAttribute ()
{ {
context.debug ("findAttribute"); context.debug ("Parser::findAttribute");
context.debug (t->dump ()); bool action = false;
std::string raw = t->attribute ("raw"); std::vector <Tree*> nodes;
Nibbler n (raw); collect (nodes, false);
std::vector <Tree*>::iterator i;
// Look for a valid attribute name. for (i = nodes.begin (); i != nodes.end (); ++i)
std::string name;
if (n.getName (name) &&
name.length ())
{ {
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 ())
{ {
t->tag ("UDA"); if (value == "")
t->tag ("MODIFIABLE"); value = "''";
}
else if (canonicalize (canonical, "pseudo", name)) std::string canonical;
{ if (canonicalize (canonical, "uda", name))
t->unTag ("?");
t->removeAllBranches ();
t->tag ("PSEUDO");
t->attribute ("name", canonical);
t->attribute ("raw", value);
}
else if (canonicalize (canonical, "attribute", name))
{
t->unTag ("?");
t->removeAllBranches ();
t->tag ("ATTRIBUTE");
t->attribute ("name", canonical);
t->attribute ("raw", value);
std::map <std::string, Column*>::const_iterator col;
col = context.columns.find (canonical);
if (col != context.columns.end () &&
col->second->modifiable ())
{ {
t->tag ("MODIFIABLE"); (*i)->tag ("UDA");
(*i)->tag ("MODIFIABLE");
action = true;
} }
Tree* branch = t->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;
}
branch = t->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 = t->addBranch (new Tree ("argAtt")); Tree* branch = (*i)->addBranch (new Tree ("argAtt"));
branch->attribute ("raw", value); branch->attribute ("raw", canonical);
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;
}
} }
} }
} }
} }
if (action)
context.debug (_tree->dump ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -75,7 +75,7 @@ private:
void findPattern (); void findPattern ();
void findSubstitution (); void findSubstitution ();
void findTag (); void findTag ();
void findAttribute (Tree*); void findAttribute ();
void findAttributeModifier (Tree*); void findAttributeModifier (Tree*);
void findOperator (Tree*); void findOperator (Tree*);
void findFilter (); void findFilter ();