diff --git a/src/CLI.cpp b/src/CLI.cpp index 4a5f412c7..3ab44239c 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -629,6 +629,7 @@ void CLI::addArg (const std::string& arg) if (isTerminator (raw)) // -- _terminated = true; + // This is the case where the argument should not be lexed. if (_terminated || isRCOverride (raw) || // rc: isConfigOverride (raw) || // rc.: @@ -646,7 +647,7 @@ void CLI::addArg (const std::string& arg) _original_args.push_back (raw); } - // Lex, but only use lexemes if an operator is found in there. + // Lex the argument, but apply a series of diqualifying tests. else { // Lex each argument. If there are multiple lexemes, create sub branches, @@ -660,24 +661,19 @@ void CLI::addArg (const std::string& arg) while (lex.token (lexeme, type)) lexemes.push_back (std::pair (lexeme, type)); - bool foundOP = false; - std::vector >::iterator l; - for (l = lexemes.begin (); l != lexemes.end (); ++l) - if (l->second == Lexer::typeOperator) - foundOP = true; + // TODO First or last term is a binary operator + // TODO Only operators are parentheses - // This one looks interesting. - if (lexemes.size () > 2 && - foundOP) + if (disqualifyInsufficientTerms (lexemes) || + disqualifyNoOps (lexemes)) { - for (l = lexemes.begin (); l != lexemes.end (); ++l) - { - _original_args.push_back (l->first); - } + _original_args.push_back (raw); } else { - _original_args.push_back (raw); + std::vector >::iterator l; + for (l = lexemes.begin (); l != lexemes.end (); ++l) + _original_args.push_back (l->first); } } } @@ -2334,3 +2330,23 @@ bool CLI::isName (const std::string& raw) const } //////////////////////////////////////////////////////////////////////////////// +bool CLI::disqualifyInsufficientTerms ( + const std::vector >& lexemes) const +{ + return lexemes.size () < 3 ? true : false; +} + +//////////////////////////////////////////////////////////////////////////////// +bool CLI::disqualifyNoOps ( + const std::vector >& lexemes) const +{ + bool foundOP = false; + std::vector >::const_iterator l; + for (l = lexemes.begin (); l != lexemes.end (); ++l) + if (l->second == Lexer::typeOperator) + foundOP = true; + + return ! foundOP; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/CLI.h b/src/CLI.h index 1e461dc07..0f467f7ee 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -110,20 +111,23 @@ private: void decomposeModTags (); void decomposeModSubstitutions (); - bool isTerminator (const std::string&) const; - bool isRCOverride (const std::string&) const; + bool isTerminator (const std::string&) const; + bool isRCOverride (const std::string&) const; bool isConfigOverride (const std::string&) const; - bool isCommand (const std::string&) const; - bool isTag (const std::string&) const; - bool isUUIDList (const std::string&) const; - bool isUUID (const std::string&) const; - bool isIDSequence (const std::string&) const; - bool isID (const std::string&) const; - bool isPattern (const std::string&) const; - bool isSubstitution (const std::string&) const; - bool isAttribute (const std::string&) const; - bool isOperator (const std::string&) const; - bool isName (const std::string&) const; + bool isCommand (const std::string&) const; + bool isTag (const std::string&) const; + bool isUUIDList (const std::string&) const; + bool isUUID (const std::string&) const; + bool isIDSequence (const std::string&) const; + bool isID (const std::string&) const; + bool isPattern (const std::string&) const; + bool isSubstitution (const std::string&) const; + bool isAttribute (const std::string&) const; + bool isOperator (const std::string&) const; + bool isName (const std::string&) const; + + bool disqualifyInsufficientTerms (const std::vector >&) const; + bool disqualifyNoOps (const std::vector >&) const; public: std::multimap _entities;