- Implemented ::disqualifyOnlyParenOps, which bypasses lexing if parentheses
  are the only operators found.
This commit is contained in:
Paul Beckingham 2014-11-09 14:58:51 -05:00
parent dc97348335
commit 84f9bc52ef
2 changed files with 29 additions and 7 deletions

View file

@ -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 <std::string, Lexer::Type> (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 <std::pair <std::string, Lexer::Type> >& lexemes) const
{
int opCount = 0;
int opParenCount = 0;
std::vector <std::pair <std::string, Lexer::Type> >::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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -128,6 +128,7 @@ private:
bool disqualifyInsufficientTerms (const std::vector <std::pair <std::string, Lexer::Type> >&) const;
bool disqualifyNoOps (const std::vector <std::pair <std::string, Lexer::Type> >&) const;
bool disqualifyOnlyParenOps (const std::vector <std::pair <std::string, Lexer::Type> >&) const;
public:
std::multimap <std::string, std::string> _entities;