mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 04:13:07 +02:00
CLI
- Implemented ::unsweetenAtts to resolve syntactic sugar to an expression.
This commit is contained in:
parent
f29b6a4be4
commit
8afb39dea6
2 changed files with 88 additions and 0 deletions
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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue