CLI2: Implement inserting modification arguments

Method to inject mods into the command, to be used by writeable context.
This commit is contained in:
Tomas Babej 2021-01-28 00:41:06 -05:00
parent 9128798fee
commit 5c3cf0f438
2 changed files with 37 additions and 1 deletions

View file

@ -537,7 +537,8 @@ void CLI2::analyze ()
}
////////////////////////////////////////////////////////////////////////////////
// Process raw string.
// Process raw filter string.
// Insert filter arguments (wrapped in parentheses) immediatelly after the binary.
void CLI2::addFilter (const std::string& arg)
{
if (arg.length ())
@ -558,6 +559,40 @@ void CLI2::addFilter (const std::string& arg)
}
}
////////////////////////////////////////////////////////////////////////////////
// Process raw modification string.
// Insert modification arguments immediatelly after the command (i.e. 'add')
void CLI2::addModifications (const std::string& arg)
{
if (arg.length ())
{
std::vector <std::string> mods;
std::string lexeme;
Lexer::Type type;
Lexer lex (arg);
while (lex.token (lexeme, type))
mods.push_back (lexeme);
// Determine at which argument index does the task command reside
unsigned int cmdIndex = 0;
for (; cmdIndex < _args.size(); ++cmdIndex)
{
if (a._lextype == Lexer::Type::separator)
continue;
// Command found, stop iterating.
if (a.hasTag ("CMD"))
break;
}
// Insert modifications after the command.
add (mods, cmdIndex);
analyze ();
}
}
////////////////////////////////////////////////////////////////////////////////
// There are situations where a context filter is applied. This method
// determines whether one applies, and if so, applies it. Disqualifiers include:

View file

@ -73,6 +73,7 @@ public:
void add (const std::vector <std::string>&, int offset = 0);
void analyze ();
void addFilter (const std::string& arg);
void addModifications (const std::string& arg);
void addContextFilter ();
void prepareFilter ();
const std::vector <std::string> getWords ();