CLI
- Implemented ::unsweetenAtts to resolve syntactic sugar to an expression.
This commit is contained in:
87
src/CLI.cpp
87
src/CLI.cpp
@@ -291,6 +291,7 @@ const std::string CLI::getFilter ()
|
|||||||
{
|
{
|
||||||
// Remove all the syntactic sugar.
|
// Remove all the syntactic sugar.
|
||||||
unsweetenTags ();
|
unsweetenTags ();
|
||||||
|
unsweetenAtts ();
|
||||||
// TODO all the other types: att, attmod, pattern, id, uuid ...
|
// TODO all the other types: att, attmod, pattern, id, uuid ...
|
||||||
|
|
||||||
std::string filter = "";
|
std::string filter = "";
|
||||||
@@ -542,6 +543,92 @@ void CLI::unsweetenTags ()
|
|||||||
_args = reconstructed;
|
_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
|
void CLI::dump (const std::string& label) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private:
|
|||||||
bool exactMatch (const std::string&, const std::string&) const;
|
bool exactMatch (const std::string&, const std::string&) const;
|
||||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||||
void unsweetenTags ();
|
void unsweetenTags ();
|
||||||
|
void unsweetenAtts ();
|
||||||
void dump (const std::string&) const;
|
void dump (const std::string&) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user