From d43ca960560903c94a845e6f7beb8fa4c11ab1bc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 14 Jun 2015 09:28:20 -0400 Subject: [PATCH] CLI2: aliasExpansion & argv[0] handling - Added ::handleArg0 method to clean up ::analyze. - Implemented ::aliasExpansion, which now applies to lexemes, not full command line arguments. --- src/CLI2.cpp | 48 ++++++++++++++++++++++++------------------------ src/CLI2.h | 3 ++- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 21802a86f..c6879c0cf 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -41,10 +41,10 @@ extern Context context; // Overridden by rc.abbreviation.minimum. int CLI2::minimumMatchLength = 3; -/* // Alias expansion limit. Any more indicates some kind of error. static int safetyValveDefault = 10; +/* //////////////////////////////////////////////////////////////////////////////// A2::A2 () : _name ("") @@ -351,20 +351,10 @@ void CLI2::add (const std::string& argument) } //////////////////////////////////////////////////////////////////////////////// -// Intended to be called after ::add() to perform the final analysis. -void CLI2::analyze () +void CLI2::handleArg0 () { - // Start from scratch. - _args.clear (); - - if (context.config.getInteger ("debug.parser") >= 3) - { - context.debug ("---------------------------------------------------------------------------------"); - context.debug (dump ("CLI2::analyze start")); - } - - // Capture _original_args[0] separately, because it is the command run, and - // could need special handling. + // Capture arg0 separately, because it is the command that was run, and could + // need special handling. std::string raw = _original_args[0]; A2 a ("arg", raw, Lexer::Type::word); a.tag ("ORIGINAL"); @@ -388,19 +378,29 @@ void CLI2::analyze () A2 cal ("argCal", "calendar", Lexer::Type::word); _args.push_back (cal); } +} + +//////////////////////////////////////////////////////////////////////////////// +// Intended to be called after ::add() to perform the final analysis. +void CLI2::analyze () +{ + if (context.config.getInteger ("debug.parser") >= 3) + { + context.debug ("---------------------------------------------------------------------------------"); + context.debug (dump ("CLI2::analyze start")); + } + + // Start from scratch. + _args.clear (); + handleArg0 (); // Look at each arg, and decide if it warrants lexing. // Note: Starts interating at index 1. for (unsigned int i = 1; i < _original_args.size (); ++i) { - raw = _original_args[i]; - - // Lex each remaining argument. The apply a series of disqualifying tests - // that cause the lexemes to be ignored, and the original arugment used - // intact. std::string lexeme; Lexer::Type type; - Lexer lex (raw); + Lexer lex (_original_args[i]); lex.ambiguity (false); while (lex.token (lexeme, type)) @@ -408,6 +408,7 @@ void CLI2::analyze () } // Now process _args. + aliasExpansion (); findOverrides (); if (context.config.getInteger ("debug.parser") >= 3) @@ -822,7 +823,7 @@ void CLI2::addArg (const std::string& arg) } } } - +*/ //////////////////////////////////////////////////////////////////////////////// void CLI2::aliasExpansion () { @@ -832,7 +833,7 @@ void CLI2::aliasExpansion () do { action = false; - std::vector reconstructed; + std::vector reconstructed; bool terminated = false; std::string raw; @@ -849,7 +850,7 @@ void CLI2::aliasExpansion () auto lexed = Lexer::split (_aliases[raw]); for (auto& l : lexed) { - A a ("argLex", l); + A2 a ("argLex", l, Lexer::Type::word); a.tag ("ALIAS"); a.tag ("LEX"); reconstructed.push_back (a); @@ -876,7 +877,6 @@ void CLI2::aliasExpansion () context.config.getInteger ("debug.parser") >= 3) context.debug (dump ("CLI2::analyze aliasExpansion")); } -*/ //////////////////////////////////////////////////////////////////////////////// void CLI2::findOverrides () diff --git a/src/CLI2.h b/src/CLI2.h index 672c370d2..ed21e000d 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -110,8 +110,9 @@ public: private: /* void addArg (const std::string&); - void aliasExpansion (); */ + void handleArg0 (); + void aliasExpansion (); void findOverrides (); /* void categorize ();