CLI: Added ::canonicalizeNames for commands and keywords

This commit is contained in:
Paul Beckingham 2016-04-03 12:42:54 -04:00
parent 27f13f84ed
commit c2a10e6848
2 changed files with 41 additions and 0 deletions

View file

@ -224,6 +224,7 @@ void CLI::analyze ()
handleArg0 ();
lexArguments ();
findCommand ();
canonicalizeNames ();
}
////////////////////////////////////////////////////////////////////////////////
@ -288,6 +289,45 @@ const std::string CLI::dump (const std::string& title) const
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////
// Scan all arguments and canonicalize names that need it.
void CLI::canonicalizeNames ()
{
for (auto& a : _args)
{
auto raw = a.attribute ("raw");
std::string canonical;
// Commands.
if (exactMatch ("command", raw))
{
a.attribute ("canonical", raw);
a.tag ("CMD");
continue;
}
else if (canonicalize (canonical, "command", raw))
{
a.attribute ("canonical", canonical);
a.tag ("CMD");
continue;
}
// Commands.
if (exactMatch ("keyword", raw))
{
a.attribute ("canonical", raw);
a.tag ("KEYWORD");
continue;
}
else if (canonicalize (canonical, "keyword", raw))
{
a.attribute ("keyword", canonical);
a.tag ("KEYWORD");
continue;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Scan all arguments and if any are an exact match for a command name, then
// tag as CMD. If an argument is an exact match for an attribute, despite being

View file

@ -65,6 +65,7 @@ public:
private:
void handleArg0 ();
void lexArguments ();
void canonicalizeNames ();
bool findCommand ();
bool exactMatch (const std::string&, const std::string&) const;