- Converted ::findAttribute to use recusive ::scan.
This commit is contained in:
Paul Beckingham 2014-08-17 01:04:08 -04:00
parent 3a8d42dae7
commit 989c503446
2 changed files with 61 additions and 70 deletions

View file

@ -181,7 +181,7 @@ Tree* Parser::parse ()
findSubstitution ();
findPattern ();
findTag ();
findAttribute ();
scan (&Parser::findAttribute);
scan (&Parser::findAttributeModifier);
findOperator ();
findCommand ();
@ -910,86 +910,77 @@ void Parser::findTag ()
////////////////////////////////////////////////////////////////////////////////
// <name>:['"][<value>]['"]
void Parser::findAttribute ()
void Parser::findAttribute (Tree* t)
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
context.debug ("findAttribute");
context.debug (t->dump ());
std::string raw = t->attribute ("raw");
Nibbler n (raw);
// Look for a valid attribute name.
std::string name;
if (n.getName (name) &&
name.length ())
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
// Skip known args.
if (! (*i)->hasTag ("?"))
continue;
std::string raw = (*i)->attribute ("raw");
Nibbler n (raw);
// Look for a valid attribute name.
std::string name;
if (n.getName (name) &&
name.length ())
if (n.skip (':'))
{
if (n.skip (':'))
std::string value;
if (n.getQuoted ('"', value) ||
n.getQuoted ('\'', value) ||
n.getUntilEOS (value) ||
n.depleted ())
{
std::string value;
if (n.getQuoted ('"', value) ||
n.getQuoted ('\'', value) ||
n.getUntilEOS (value) ||
n.depleted ())
if (value == "")
value = "''";
std::string canonical;
if (canonicalize (canonical, "uda", name))
{
if (value == "")
value = "''";
t->tag ("UDA");
t->tag ("MODIFIABLE");
}
std::string canonical;
if (canonicalize (canonical, "uda", name))
else if (canonicalize (canonical, "pseudo", 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 ())
{
(*i)->tag ("UDA");
(*i)->tag ("MODIFIABLE");
t->tag ("MODIFIABLE");
}
else if (canonicalize (canonical, "pseudo", name))
{
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("PSEUDO");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
}
Tree* branch = t->addBranch (new Tree ("argAtt"));
branch->attribute ("raw", canonical);
else if (canonicalize (canonical, "attribute", name))
{
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("ATTRIBUTE");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
branch = t->addBranch (new Tree ("argAtt"));
branch->tag ("OP");
std::map <std::string, Column*>::const_iterator col;
col = context.columns.find (canonical);
if (col != context.columns.end () &&
col->second->modifiable ())
{
(*i)->tag ("MODIFIABLE");
}
// All 'project' attributes are partial matches.
if (canonical == "project" ||
canonical == "uuid")
branch->attribute ("raw", "=");
else
branch->attribute ("raw", "==");
Tree* branch = (*i)->addBranch (new Tree ("argAtt"));
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);
}
branch = t->addBranch (new Tree ("argAtt"));
branch->attribute ("raw", value);
}
}
}

View file

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