- Implemented ::unsweetenAtts to resolve syntactic sugar to an expression.
This commit is contained in:
Paul Beckingham 2014-10-15 07:34:29 -04:00
parent f29b6a4be4
commit 8afb39dea6
2 changed files with 88 additions and 0 deletions

View file

@ -291,6 +291,7 @@ const std::string CLI::getFilter ()
{
// Remove all the syntactic sugar.
unsweetenTags ();
unsweetenAtts ();
// TODO all the other types: att, attmod, pattern, id, uuid ...
std::string filter = "";
@ -542,6 +543,92 @@ void CLI::unsweetenTags ()
_args = reconstructed;
}
////////////////////////////////////////////////////////////////////////////////
// <name>:['"][<value>]['"] --> name = value
void CLI::unsweetenAtts ()
{
std::vector <A> reconstructed;
std::vector <A>::iterator a;
for (a = _args.begin (); a != _args.end (); ++a)
{
// Look for a valid attribute name.
bool found = false;
Nibbler n (a->attribute ("raw"));
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 ())
{
if (value == "")
value = "''";
std::string canonical;
if (canonicalize (canonical, "uda", name))
{
A left ("argUDA", name);
left.attribute ("canonical", canonical);
left.tag ("UDA");
left.tag ("MODIFIABLE");
left.tag ("FILTER");
reconstructed.push_back (left);
found = true;
}
else if (canonicalize (canonical, "pseudo", name))
{
A left ("argUDA", name);
left.attribute ("canonical", canonical);
left.tag ("PSEUDO");
left.tag ("FILTER");
reconstructed.push_back (left);
found = true;
}
else if (canonicalize (canonical, "attribute", name))
{
A lhs ("argAtt", name);
lhs.attribute ("canonical", canonical);
lhs.tag ("ATTRIBUTE");
lhs.tag ("FILTER");
std::map <std::string, Column*>::const_iterator col;
col = context.columns.find (canonical);
if (col != context.columns.end () &&
col->second->modifiable ())
{
lhs.tag ("MODIFIABLE");
}
A op ("argAtt", "=");
op.tag ("OP");
op.tag ("FILTER");
A rhs ("argAtt", value);
rhs.tag ("FILTER");
reconstructed.push_back (lhs);
reconstructed.push_back (op);
reconstructed.push_back (rhs);
found = true;
}
}
}
}
if (!found)
reconstructed.push_back (*a);
}
_args = reconstructed;
}
////////////////////////////////////////////////////////////////////////////////
void CLI::dump (const std::string& label) const
{

View file

@ -77,6 +77,7 @@ private:
bool exactMatch (const std::string&, const std::string&) const;
bool canonicalize (std::string&, const std::string&, const std::string&) const;
void unsweetenTags ();
void unsweetenAtts ();
void dump (const std::string&) const;
public: