mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Parser
- ::findCommand now checks for any abbreviated command. If it finds either an exact match, or no ambiguity, it checks again to determine READCMD, WRITECMD or HELPER.
This commit is contained in:
parent
a4d908d8b2
commit
1b19414178
3 changed files with 34 additions and 19 deletions
|
@ -156,6 +156,8 @@ int Context::initialize (int argc, const char** argv)
|
|||
std::map <std::string, Command*>::iterator cmd;
|
||||
for (cmd = commands.begin (); cmd != commands.end (); ++cmd)
|
||||
{
|
||||
parser.entity ("cmd", cmd->first);
|
||||
|
||||
if (cmd->first[0] == '_')
|
||||
parser.entity ("helper", cmd->first);
|
||||
else if (cmd->second->read_only ())
|
||||
|
|
|
@ -165,6 +165,29 @@ void Parser::entity (const std::string& name, const std::string& value)
|
|||
_entities.insert (std::pair <std::string, std::string> (name, value));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Search for exact 'value' in _entities category.
|
||||
bool Parser::exactMatch (
|
||||
const std::string& category,
|
||||
const std::string& value) const
|
||||
{
|
||||
// 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 (category);
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Shortcut: if an exact match is found, success.
|
||||
if (value == e->second)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Search for 'value' in _entities category, return canonicalized value.
|
||||
bool Parser::canonicalize (
|
||||
|
@ -278,31 +301,20 @@ void Parser::findCommand ()
|
|||
if (! (*i)->hasTag ("?"))
|
||||
continue;
|
||||
|
||||
if (canonicalize (command, "writecmd", (*i)->attribute ("raw")))
|
||||
if (canonicalize (command, "cmd", (*i)->attribute ("raw")))
|
||||
{
|
||||
(*i)->unTag ("?");
|
||||
(*i)->tag ("CMD");
|
||||
(*i)->tag ("WRITECMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "readcmd", (*i)->attribute ("raw")))
|
||||
{
|
||||
(*i)->unTag ("?");
|
||||
(*i)->tag ("CMD");
|
||||
(*i)->tag ("READCMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
break;
|
||||
}
|
||||
if (exactMatch ("writecmd", (*i)->attribute ("raw")))
|
||||
(*i)->tag ("WRITECMD");
|
||||
else if (exactMatch ("writecmd", (*i)->attribute ("raw")))
|
||||
(*i)->tag ("READCMD");
|
||||
else if (exactMatch ("writecmd", (*i)->attribute ("raw")))
|
||||
(*i)->tag ("HELPER");
|
||||
|
||||
else if (canonicalize (command, "helper", (*i)->attribute ("raw")))
|
||||
{
|
||||
(*i)->unTag ("?");
|
||||
(*i)->tag ("CMD");
|
||||
(*i)->tag ("HELPER");
|
||||
(*i)->attribute ("canonical", command);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
Tree* tree ();
|
||||
Tree* parse ();
|
||||
void entity (const std::string&, const std::string&);
|
||||
bool exactMatch (const std::string&, const std::string&) const;
|
||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||
|
||||
void findBinary ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue