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

View file

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