From 2cab600674ddd27e7037f442eef037bd5ab05c3d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 14 Jun 2015 16:33:34 -0400 Subject: [PATCH] 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. --- src/CLI2.cpp | 32 ++++++++++++++++++++++++++++++++ src/CLI2.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index b3e470b1c..a756a1b67 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -393,6 +393,37 @@ void CLI2::lexArguments () context.debug (dump ("CLI2::analyze lexArguments")); } +//////////////////////////////////////////////////////////////////////////////// +void CLI2::handleTerminator () +{ + bool changes = false; + bool terminated = false; + std::vector 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 (); diff --git a/src/CLI2.h b/src/CLI2.h index 1f244c8e7..85e11528e 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -110,6 +110,7 @@ private: */ void handleArg0 (); void lexArguments (); + void handleTerminator (); void aliasExpansion (); void findOverrides (); void findCommand ();