diff --git a/src/CLI.cpp b/src/CLI.cpp index 3ab44239c..04523405f 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -647,11 +647,14 @@ void CLI::addArg (const std::string& arg) _original_args.push_back (raw); } - // Lex the argument, but apply a series of diqualifying tests. + + // How often have I said to you that when you have eliminated the impossible, + // whatever remains, however improbable, must be the truth? else { - // Lex each argument. If there are multiple lexemes, create sub branches, - // otherwise no change. + // 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); @@ -661,11 +664,9 @@ void CLI::addArg (const std::string& arg) while (lex.token (lexeme, type)) lexemes.push_back (std::pair (lexeme, type)); - // TODO First or last term is a binary operator - // TODO Only operators are parentheses - if (disqualifyInsufficientTerms (lexemes) || - disqualifyNoOps (lexemes)) + disqualifyNoOps (lexemes) || + disqualifyOnlyParenOps (lexemes)) { _original_args.push_back (raw); } @@ -2350,3 +2351,23 @@ bool CLI::disqualifyNoOps ( } //////////////////////////////////////////////////////////////////////////////// +bool CLI::disqualifyOnlyParenOps ( + const std::vector >& lexemes) const +{ + int opCount = 0; + int opParenCount = 0; + + std::vector >::const_iterator l; + for (l = lexemes.begin (); l != lexemes.end (); ++l) + if (l->second == Lexer::typeOperator) + { + ++opCount; + + if (l->first == "(" || + l->first == ")") + ++opParenCount; + } + + return opCount == opParenCount; +} +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/CLI.h b/src/CLI.h index 0f467f7ee..51a9aa45f 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -128,6 +128,7 @@ private: bool disqualifyInsufficientTerms (const std::vector >&) const; bool disqualifyNoOps (const std::vector >&) const; + bool disqualifyOnlyParenOps (const std::vector >&) const; public: std::multimap _entities;