mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Parser
- ::findAttributeModifier now repeats without breaking the iterator.
This commit is contained in:
parent
37614ac6b3
commit
13e49f6b00
1 changed files with 158 additions and 151 deletions
309
src/Parser.cpp
309
src/Parser.cpp
|
@ -1061,187 +1061,194 @@ void Parser::findAttribute ()
|
||||||
void Parser::findAttributeModifier ()
|
void Parser::findAttributeModifier ()
|
||||||
{
|
{
|
||||||
context.debug ("Parser::findAttributeModifier");
|
context.debug ("Parser::findAttributeModifier");
|
||||||
bool action = false;
|
bool action = true;
|
||||||
|
|
||||||
std::vector <Tree*> nodes;
|
do
|
||||||
collect (nodes);
|
|
||||||
std::vector <Tree*>::iterator i;
|
|
||||||
for (i = nodes.begin (); i != nodes.end (); ++i)
|
|
||||||
{
|
{
|
||||||
std::string raw = (*i)->attribute ("raw");
|
action = false;
|
||||||
Nibbler n (raw);
|
|
||||||
|
|
||||||
std::string name;
|
std::vector <Tree*> nodes;
|
||||||
if (n.getUntil (".", name))
|
collect (nodes);
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
std::string canonical;
|
std::string raw = (*i)->attribute ("raw");
|
||||||
if (canonicalize (canonical, "attribute", name) ||
|
Nibbler n (raw);
|
||||||
canonicalize (canonical, "uda", name))
|
|
||||||
|
std::string name;
|
||||||
|
if (n.getUntil (".", name))
|
||||||
{
|
{
|
||||||
if (n.skip ('.'))
|
std::string canonical;
|
||||||
|
if (canonicalize (canonical, "attribute", name) ||
|
||||||
|
canonicalize (canonical, "uda", name))
|
||||||
{
|
{
|
||||||
std::string sense = "+";
|
if (n.skip ('.'))
|
||||||
if (n.skip ('~'))
|
|
||||||
sense = "-";
|
|
||||||
|
|
||||||
std::string modifier;
|
|
||||||
n.getUntilOneOf (":=", modifier);
|
|
||||||
|
|
||||||
if (n.skip (':') ||
|
|
||||||
n.skip ('='))
|
|
||||||
{
|
{
|
||||||
std::string value;
|
std::string sense = "+";
|
||||||
if (n.getQuoted ('"', value) ||
|
if (n.skip ('~'))
|
||||||
n.getQuoted ('\'', value) ||
|
sense = "-";
|
||||||
n.getUntilEOS (value) ||
|
|
||||||
n.depleted ())
|
std::string modifier;
|
||||||
|
n.getUntilOneOf (":=", modifier);
|
||||||
|
|
||||||
|
if (n.skip (':') ||
|
||||||
|
n.skip ('='))
|
||||||
{
|
{
|
||||||
if (value == "")
|
std::string value;
|
||||||
value = "''";
|
if (n.getQuoted ('"', value) ||
|
||||||
|
n.getQuoted ('\'', value) ||
|
||||||
(*i)->unTag ("?");
|
n.getUntilEOS (value) ||
|
||||||
(*i)->removeAllBranches ();
|
n.depleted ())
|
||||||
(*i)->tag ("ATTMOD");
|
|
||||||
(*i)->attribute ("name", canonical);
|
|
||||||
(*i)->attribute ("raw", value);
|
|
||||||
(*i)->attribute ("modifier", modifier);
|
|
||||||
(*i)->attribute ("sense", sense);
|
|
||||||
action = true;
|
|
||||||
|
|
||||||
Tree* branch = (*i)->addBranch (new Tree ("argAttmod"));
|
|
||||||
branch->attribute ("raw", canonical);
|
|
||||||
|
|
||||||
if (modifier == "before" || modifier == "under" || modifier == "below")
|
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
if (value == "")
|
||||||
branch->attribute ("raw", "<");
|
value = "''";
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
(*i)->unTag ("?");
|
||||||
branch->attribute ("raw", value);
|
(*i)->removeAllBranches ();
|
||||||
}
|
(*i)->tag ("ATTMOD");
|
||||||
else if (modifier == "after" || modifier == "over" || modifier == "above")
|
(*i)->attribute ("name", canonical);
|
||||||
{
|
(*i)->attribute ("raw", value);
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
(*i)->attribute ("modifier", modifier);
|
||||||
branch->attribute ("raw", ">");
|
(*i)->attribute ("sense", sense);
|
||||||
branch->tag ("OP");
|
action = true;
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
Tree* branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", canonical);
|
||||||
}
|
|
||||||
else if (modifier == "none")
|
|
||||||
{
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
|
||||||
branch->attribute ("raw", "==");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
if (modifier == "before" || modifier == "under" || modifier == "below")
|
||||||
branch->attribute ("raw", "''");
|
{
|
||||||
}
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
else if (modifier == "any")
|
branch->attribute ("raw", "<");
|
||||||
{
|
branch->tag ("OP");
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
|
||||||
branch->attribute ("raw", "!=");
|
|
||||||
branch->tag ("OP");
|
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "''");
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "is" || modifier == "equals")
|
else if (modifier == "after" || modifier == "over" || modifier == "above")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "==");
|
branch->attribute ("raw", ">");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "isnt" || modifier == "not")
|
else if (modifier == "none")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!=");
|
branch->attribute ("raw", "==");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", "''");
|
||||||
}
|
}
|
||||||
else if (modifier == "has" || modifier == "contains")
|
else if (modifier == "any")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "~");
|
branch->attribute ("raw", "!=");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", "''");
|
||||||
}
|
}
|
||||||
else if (modifier == "hasnt")
|
else if (modifier == "is" || modifier == "equals")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!~");
|
branch->attribute ("raw", "==");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "startswith" || modifier == "left")
|
else if (modifier == "isnt" || modifier == "not")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "~");
|
branch->attribute ("raw", "!=");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "'^" + value + "'");
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "endswith" || modifier == "right")
|
else if (modifier == "has" || modifier == "contains")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "~");
|
branch->attribute ("raw", "~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "'" + value + "$'");
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "word")
|
else if (modifier == "hasnt")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "~");
|
branch->attribute ("raw", "!~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", value);
|
||||||
|
}
|
||||||
|
else if (modifier == "startswith" || modifier == "left")
|
||||||
|
{
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "~");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "'^" + value + "'");
|
||||||
|
}
|
||||||
|
else if (modifier == "endswith" || modifier == "right")
|
||||||
|
{
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "~");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "'" + value + "$'");
|
||||||
|
}
|
||||||
|
else if (modifier == "word")
|
||||||
|
{
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "~");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
|
||||||
#if defined (DARWIN)
|
#if defined (DARWIN)
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
#elif defined (SOLARIS)
|
#elif defined (SOLARIS)
|
||||||
branch->attribute ("raw", "'\\<" + value + "\\>'");
|
branch->attribute ("raw", "'\\<" + value + "\\>'");
|
||||||
#else
|
#else
|
||||||
branch->attribute ("raw", "'\\b" + value + "\\b'");
|
branch->attribute ("raw", "'\\b" + value + "\\b'");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (modifier == "noword")
|
else if (modifier == "noword")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!~");
|
branch->attribute ("raw", "!~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
||||||
|
|
||||||
#if defined (DARWIN)
|
#if defined (DARWIN)
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
#elif defined (SOLARIS)
|
#elif defined (SOLARIS)
|
||||||
branch->attribute ("raw", "'\\<" + value + "\\>'");
|
branch->attribute ("raw", "'\\<" + value + "\\>'");
|
||||||
#else
|
#else
|
||||||
branch->attribute ("raw", "'\\b" + value + "\\b'");
|
branch->attribute ("raw", "'\\b" + value + "\\b'");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw format (STRING_PARSER_UNKNOWN_ATTMOD, modifier);
|
throw format (STRING_PARSER_UNKNOWN_ATTMOD, modifier);
|
||||||
|
|
||||||
std::map <std::string, Column*>::const_iterator col;
|
std::map <std::string, Column*>::const_iterator col;
|
||||||
col = context.columns.find (canonical);
|
col = context.columns.find (canonical);
|
||||||
if (col != context.columns.end () &&
|
if (col != context.columns.end () &&
|
||||||
col->second->modifiable ())
|
col->second->modifiable ())
|
||||||
{
|
{
|
||||||
(*i)->tag ("MODIFIABLE");
|
(*i)->tag ("MODIFIABLE");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1249,9 +1256,9 @@ void Parser::findAttributeModifier ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (action);
|
||||||
|
|
||||||
if (action)
|
context.debug (_tree->dump ());
|
||||||
context.debug (_tree->dump ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue