CLI2: Added ::handleTerminator

- CLI2::handleTerminator removes all terminator arguments it finds
  and downgrades all subsequent arguments to Lexer::Type::word. This
  simplifies all further processing.
This commit is contained in:
Paul Beckingham 2015-06-14 16:33:34 -04:00
parent 370df8e07f
commit 2cab600674
2 changed files with 33 additions and 0 deletions

View file

@ -393,6 +393,37 @@ void CLI2::lexArguments ()
context.debug (dump ("CLI2::analyze lexArguments"));
}
////////////////////////////////////////////////////////////////////////////////
void CLI2::handleTerminator ()
{
bool changes = false;
bool terminated = false;
std::vector <A2> reconstructed;
for (auto& a : _args)
{
if (a._lextype == Lexer::Type::separator)
{
terminated = true;
changes = true;
}
else
{
if (terminated)
a._lextype = Lexer::Type::word;
reconstructed.push_back (a);
}
}
if (changes)
{
_args = reconstructed;
if (context.config.getInteger ("debug.parser") >= 3)
context.debug (dump ("CLI2::analyze handleTerminator"));
}
}
////////////////////////////////////////////////////////////////////////////////
// Intended to be called after ::add() to perform the final analysis.
void CLI2::analyze ()
@ -407,6 +438,7 @@ void CLI2::analyze ()
_args.clear ();
handleArg0 ();
lexArguments ();
handleTerminator ();
// Process _args.
aliasExpansion ();

View file

@ -110,6 +110,7 @@ private:
*/
void handleArg0 ();
void lexArguments ();
void handleTerminator ();
void aliasExpansion ();
void findOverrides ();
void findCommand ();