mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CLI
- Implemnted ::unsweetenAttMods.
This commit is contained in:
parent
80b385ee93
commit
0603711aac
2 changed files with 173 additions and 1 deletions
173
src/CLI.cpp
173
src/CLI.cpp
|
@ -293,7 +293,8 @@ const std::string CLI::getFilter ()
|
|||
// Remove all the syntactic sugar.
|
||||
unsweetenTags ();
|
||||
unsweetenAtts ();
|
||||
// TODO all the other types: att, attmod, pattern, id, uuid ...
|
||||
unsweetenAttMods ();
|
||||
// TODO all the other types: pattern, id, uuid ...
|
||||
|
||||
std::string filter = "";
|
||||
if (_args.size ())
|
||||
|
@ -630,6 +631,176 @@ void CLI::unsweetenAtts ()
|
|||
_args = reconstructed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// <name>.<mod>[:=]['"]<value>['"] --> name <op> value
|
||||
void CLI::unsweetenAttMods ()
|
||||
{
|
||||
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.getUntil (".", name) &&
|
||||
name.length ())
|
||||
{
|
||||
std::string canonical;
|
||||
if (canonicalize (canonical, "attribute", name) ||
|
||||
canonicalize (canonical, "uda", name))
|
||||
{
|
||||
if (n.skip ('.'))
|
||||
{
|
||||
std::string sense = "+";
|
||||
if (n.skip ('~'))
|
||||
sense = "-";
|
||||
|
||||
std::string modifier;
|
||||
n.getUntilOneOf (":=", modifier);
|
||||
|
||||
if (n.skip (':') ||
|
||||
n.skip ('='))
|
||||
{
|
||||
std::string value;
|
||||
if (n.getQuoted ('"', value) ||
|
||||
n.getQuoted ('\'', value) ||
|
||||
n.getUntilEOS (value) ||
|
||||
n.depleted ())
|
||||
{
|
||||
if (value == "")
|
||||
value = "''";
|
||||
|
||||
A lhs ("argAttMod", name);
|
||||
lhs.tag ("ATTMOD");
|
||||
lhs.tag ("FILTER");
|
||||
|
||||
lhs.attribute ("name", canonical);
|
||||
lhs.attribute ("raw", value);
|
||||
lhs.attribute ("modifier", modifier);
|
||||
lhs.attribute ("sense", sense);
|
||||
|
||||
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 ("argAttmod", "");
|
||||
op.tag ("FILTER");
|
||||
|
||||
A rhs ("argAttMod", "");
|
||||
rhs.tag ("FILTER");
|
||||
|
||||
if (modifier == "before" || modifier == "under" || modifier == "below")
|
||||
{
|
||||
op.attribute ("raw", "<");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "after" || modifier == "over" || modifier == "above")
|
||||
{
|
||||
op.attribute ("raw", ">");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "none")
|
||||
{
|
||||
op.attribute ("raw", "==");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", "''");
|
||||
}
|
||||
else if (modifier == "any")
|
||||
{
|
||||
op.attribute ("raw", "!=");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", "''");
|
||||
}
|
||||
else if (modifier == "is" || modifier == "equals")
|
||||
{
|
||||
op.attribute ("raw", "==");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "isnt" || modifier == "not")
|
||||
{
|
||||
op.attribute ("raw", "!=");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "has" || modifier == "contains")
|
||||
{
|
||||
op.attribute ("raw", "~");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "hasnt")
|
||||
{
|
||||
op.attribute ("raw", "!~");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", value);
|
||||
}
|
||||
else if (modifier == "startswith" || modifier == "left")
|
||||
{
|
||||
op.attribute ("raw", "~");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", "'^" + value + "'");
|
||||
}
|
||||
else if (modifier == "endswith" || modifier == "right")
|
||||
{
|
||||
op.attribute ("raw", "~");
|
||||
op.tag ("OP");
|
||||
rhs.attribute ("raw", "'" + value + "$'");
|
||||
}
|
||||
else if (modifier == "word")
|
||||
{
|
||||
op.attribute ("raw", "~");
|
||||
op.tag ("OP");
|
||||
|
||||
|
||||
#if defined (DARWIN)
|
||||
rhs.attribute ("raw", value);
|
||||
#elif defined (SOLARIS)
|
||||
rhs.attribute ("raw", "'\\<" + value + "\\>'");
|
||||
#else
|
||||
rhs.attribute ("raw", "'\\b" + value + "\\b'");
|
||||
#endif
|
||||
}
|
||||
else if (modifier == "noword")
|
||||
{
|
||||
op.attribute ("raw", "!~");
|
||||
op.tag ("OP");
|
||||
|
||||
#if defined (DARWIN)
|
||||
rhs.attribute ("raw", value);
|
||||
#elif defined (SOLARIS)
|
||||
rhs.attribute ("raw", "'\\<" + value + "\\>'");
|
||||
#else
|
||||
rhs.attribute ("raw", "'\\b" + value + "\\b'");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
throw format (STRING_PARSER_UNKNOWN_ATTMOD, modifier);
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||
void unsweetenTags ();
|
||||
void unsweetenAtts ();
|
||||
void unsweetenAttMods ();
|
||||
void dump (const std::string&) const;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue