mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Parser
- Converted ::findAttributeModifier to use the recursive scanner.
This commit is contained in:
parent
24c2c0cbee
commit
3a8d42dae7
2 changed files with 150 additions and 159 deletions
307
src/Parser.cpp
307
src/Parser.cpp
|
@ -182,7 +182,7 @@ Tree* Parser::parse ()
|
||||||
findPattern ();
|
findPattern ();
|
||||||
findTag ();
|
findTag ();
|
||||||
findAttribute ();
|
findAttribute ();
|
||||||
findAttributeModifier ();
|
scan (&Parser::findAttributeModifier);
|
||||||
findOperator ();
|
findOperator ();
|
||||||
findCommand ();
|
findCommand ();
|
||||||
findUUIDList ();
|
findUUIDList ();
|
||||||
|
@ -998,193 +998,184 @@ void Parser::findAttribute ()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// <name>.<mod>[:=]['"]<value>['"]
|
// <name>.<mod>[:=]['"]<value>['"]
|
||||||
void Parser::findAttributeModifier ()
|
void Parser::findAttributeModifier (Tree* t)
|
||||||
{
|
{
|
||||||
std::vector <Tree*>::iterator i;
|
context.debug ("findAttributeModifier");
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
context.debug (t->dump ());
|
||||||
|
|
||||||
|
std::string raw = t->attribute ("raw");
|
||||||
|
Nibbler n (raw);
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
if (n.getUntil (".", name))
|
||||||
{
|
{
|
||||||
// Parser override operator.
|
std::string canonical;
|
||||||
if ((*i)->attribute ("raw") == "--")
|
if (canonicalize (canonical, "attribute", name) ||
|
||||||
break;
|
canonicalize (canonical, "uda", name))
|
||||||
|
|
||||||
// Skip known args.
|
|
||||||
if (! (*i)->hasTag ("?"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::string raw = (*i)->attribute ("raw");
|
|
||||||
Nibbler n (raw);
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
if (n.getUntil (".", name))
|
|
||||||
{
|
{
|
||||||
std::string canonical;
|
if (n.skip ('.'))
|
||||||
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 sense = "+";
|
std::string value;
|
||||||
if (n.skip ('~'))
|
if (n.getQuoted ('"', value) ||
|
||||||
sense = "-";
|
n.getQuoted ('\'', value) ||
|
||||||
|
n.getUntilEOS (value) ||
|
||||||
std::string modifier;
|
n.depleted ())
|
||||||
n.getUntilOneOf (":=", modifier);
|
|
||||||
|
|
||||||
if (n.skip (':') ||
|
|
||||||
n.skip ('='))
|
|
||||||
{
|
{
|
||||||
std::string value;
|
if (value == "")
|
||||||
if (n.getQuoted ('"', value) ||
|
value = "''";
|
||||||
n.getQuoted ('\'', value) ||
|
|
||||||
n.getUntilEOS (value) ||
|
t->unTag ("?");
|
||||||
n.depleted ())
|
t->removeAllBranches ();
|
||||||
|
t->tag ("ATTMOD");
|
||||||
|
t->attribute ("name", canonical);
|
||||||
|
t->attribute ("raw", value);
|
||||||
|
t->attribute ("modifier", modifier);
|
||||||
|
t->attribute ("sense", sense);
|
||||||
|
|
||||||
|
Tree* branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", canonical);
|
||||||
|
|
||||||
|
if (modifier == "before" || modifier == "under" || modifier == "below")
|
||||||
{
|
{
|
||||||
if (value == "")
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
value = "''";
|
branch->attribute ("raw", "<");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
(*i)->unTag ("?");
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
(*i)->removeAllBranches ();
|
branch->attribute ("raw", value);
|
||||||
(*i)->tag ("ATTMOD");
|
}
|
||||||
(*i)->attribute ("name", canonical);
|
else if (modifier == "after" || modifier == "over" || modifier == "above")
|
||||||
(*i)->attribute ("raw", value);
|
{
|
||||||
(*i)->attribute ("modifier", modifier);
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
(*i)->attribute ("sense", sense);
|
branch->attribute ("raw", ">");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
Tree* branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", canonical);
|
branch->attribute ("raw", value);
|
||||||
|
}
|
||||||
|
else if (modifier == "none")
|
||||||
|
{
|
||||||
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "==");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
if (modifier == "before" || modifier == "under" || modifier == "below")
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
{
|
branch->attribute ("raw", "''");
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
}
|
||||||
branch->attribute ("raw", "<");
|
else if (modifier == "any")
|
||||||
branch->tag ("OP");
|
{
|
||||||
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
|
branch->attribute ("raw", "!=");
|
||||||
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", "''");
|
||||||
}
|
}
|
||||||
else if (modifier == "after" || modifier == "over" || modifier == "above")
|
else if (modifier == "is" || modifier == "equals")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", ">");
|
branch->attribute ("raw", "==");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "none")
|
else if (modifier == "isnt" || modifier == "not")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "==");
|
branch->attribute ("raw", "!=");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "''");
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "any")
|
else if (modifier == "has" || modifier == "contains")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!=");
|
branch->attribute ("raw", "~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "''");
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "is" || modifier == "equals")
|
else if (modifier == "hasnt")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "==");
|
branch->attribute ("raw", "!~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", value);
|
||||||
}
|
}
|
||||||
else if (modifier == "isnt" || modifier == "not")
|
else if (modifier == "startswith" || modifier == "left")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!=");
|
branch->attribute ("raw", "~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", "'^" + value + "'");
|
||||||
}
|
}
|
||||||
else if (modifier == "has" || modifier == "contains")
|
else if (modifier == "endswith" || modifier == "right")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "~");
|
branch->attribute ("raw", "~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", value);
|
branch->attribute ("raw", "'" + value + "$'");
|
||||||
}
|
}
|
||||||
else if (modifier == "hasnt")
|
else if (modifier == "word")
|
||||||
{
|
{
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!~");
|
branch->attribute ("raw", "~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->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 = t->addBranch (new Tree ("argAttmod"));
|
||||||
branch->attribute ("raw", "!~");
|
branch->attribute ("raw", "!~");
|
||||||
branch->tag ("OP");
|
branch->tag ("OP");
|
||||||
|
|
||||||
branch = (*i)->addBranch (new Tree ("argAttmod"));
|
branch = t->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");
|
t->tag ("MODIFIABLE");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ private:
|
||||||
void findSubstitution ();
|
void findSubstitution ();
|
||||||
void findTag ();
|
void findTag ();
|
||||||
void findAttribute ();
|
void findAttribute ();
|
||||||
void findAttributeModifier ();
|
void findAttributeModifier (Tree*);
|
||||||
void findOperator ();
|
void findOperator ();
|
||||||
void findFilter ();
|
void findFilter ();
|
||||||
void findModifications ();
|
void findModifications ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue