mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
A3t::findOperator
- Added support for operator identification. - Extended test script.
This commit is contained in:
parent
8fddf97c73
commit
b83e6d0dea
3 changed files with 64 additions and 0 deletions
|
@ -71,6 +71,7 @@ Tree* A3t::parse ()
|
|||
findAttributeModifier ();
|
||||
findUUIDList (); // Before findIdSequence
|
||||
findIdSequence ();
|
||||
findOperator ();
|
||||
|
||||
validate ();
|
||||
|
||||
|
@ -611,6 +612,45 @@ void A3t::findUUIDList ()
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void A3t::findOperator ()
|
||||
{
|
||||
// Find the category.
|
||||
std::pair <std::multimap <std::string, std::string>::const_iterator, std::multimap <std::string, std::string>::const_iterator> c;
|
||||
c = _entities.equal_range ("operator");
|
||||
|
||||
// Extract a list of entities for category.
|
||||
std::vector <std::string> options;
|
||||
std::multimap <std::string, std::string>::const_iterator e;
|
||||
for (e = c.first; e != c.second; ++e)
|
||||
options.push_back (e->second);
|
||||
|
||||
std::vector <Tree*>::iterator i;
|
||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
||||
{
|
||||
// Parser override operator.
|
||||
if ((*i)->attribute ("raw") == "--")
|
||||
break;
|
||||
|
||||
// Skip known args.
|
||||
if (! (*i)->hasTag ("?"))
|
||||
continue;
|
||||
|
||||
std::string raw = (*i)->attribute ("raw");
|
||||
|
||||
std::vector <std::string>::iterator opt;
|
||||
for (opt = options.begin (); opt != options.end (); ++opt)
|
||||
{
|
||||
if (*opt == raw)
|
||||
{
|
||||
(*i)->unTag ("?");
|
||||
(*i)->tag ("OP");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Validate the parse tree.
|
||||
void A3t::validate ()
|
||||
|
|
|
@ -53,6 +53,7 @@ private:
|
|||
void findAttributeModifier ();
|
||||
void findIdSequence ();
|
||||
void findUUIDList ();
|
||||
void findOperator ();
|
||||
void validate ();
|
||||
|
||||
private:
|
||||
|
|
|
@ -108,6 +108,29 @@ int main (int argc, char** argv)
|
|||
a3t.identity ("modifier", "word");
|
||||
a3t.identity ("modifier", "noword");
|
||||
|
||||
// Operators.
|
||||
a3t.identity ("operator", "and");
|
||||
a3t.identity ("operator", "or");
|
||||
a3t.identity ("operator", "xor");
|
||||
a3t.identity ("operator", "<=");
|
||||
a3t.identity ("operator", ">=");
|
||||
a3t.identity ("operator", "!~");
|
||||
a3t.identity ("operator", "!=");
|
||||
a3t.identity ("operator", "=");
|
||||
a3t.identity ("operator", ">");
|
||||
a3t.identity ("operator", "~");
|
||||
a3t.identity ("operator", "!");
|
||||
a3t.identity ("operator", "_hastag_");
|
||||
a3t.identity ("operator", "_notag_");
|
||||
a3t.identity ("operator", "-");
|
||||
a3t.identity ("operator", "*");
|
||||
a3t.identity ("operator", "/");
|
||||
a3t.identity ("operator", "+");
|
||||
a3t.identity ("operator", "-");
|
||||
a3t.identity ("operator", "<");
|
||||
a3t.identity ("operator", "(");
|
||||
a3t.identity ("operator", ")");
|
||||
|
||||
Tree* tree = a3t.parse ();
|
||||
if (tree)
|
||||
tree->dump ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue