mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 04:13:07 +02:00
CLI
- Implemented the first two Lex disqualifiers.
This commit is contained in:
parent
6e906e4dbf
commit
237ef48b9c
2 changed files with 47 additions and 27 deletions
44
src/CLI.cpp
44
src/CLI.cpp
|
@ -629,6 +629,7 @@ void CLI::addArg (const std::string& arg)
|
||||||
if (isTerminator (raw)) // --
|
if (isTerminator (raw)) // --
|
||||||
_terminated = true;
|
_terminated = true;
|
||||||
|
|
||||||
|
// This is the case where the argument should not be lexed.
|
||||||
if (_terminated ||
|
if (_terminated ||
|
||||||
isRCOverride (raw) || // rc:<file>
|
isRCOverride (raw) || // rc:<file>
|
||||||
isConfigOverride (raw) || // rc.<attr>:<value>
|
isConfigOverride (raw) || // rc.<attr>:<value>
|
||||||
|
@ -646,7 +647,7 @@ void CLI::addArg (const std::string& arg)
|
||||||
_original_args.push_back (raw);
|
_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
|
else
|
||||||
{
|
{
|
||||||
// Lex each argument. If there are multiple lexemes, create sub branches,
|
// 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))
|
while (lex.token (lexeme, type))
|
||||||
lexemes.push_back (std::pair <std::string, Lexer::Type> (lexeme, type));
|
lexemes.push_back (std::pair <std::string, Lexer::Type> (lexeme, type));
|
||||||
|
|
||||||
bool foundOP = false;
|
// TODO First or last term is a binary operator
|
||||||
std::vector <std::pair <std::string, Lexer::Type> >::iterator l;
|
// TODO Only operators are parentheses
|
||||||
for (l = lexemes.begin (); l != lexemes.end (); ++l)
|
|
||||||
if (l->second == Lexer::typeOperator)
|
|
||||||
foundOP = true;
|
|
||||||
|
|
||||||
// This one looks interesting.
|
if (disqualifyInsufficientTerms (lexemes) ||
|
||||||
if (lexemes.size () > 2 &&
|
disqualifyNoOps (lexemes))
|
||||||
foundOP)
|
|
||||||
{
|
{
|
||||||
for (l = lexemes.begin (); l != lexemes.end (); ++l)
|
_original_args.push_back (raw);
|
||||||
{
|
|
||||||
_original_args.push_back (l->first);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_original_args.push_back (raw);
|
std::vector <std::pair <std::string, Lexer::Type> >::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 <std::pair <std::string, Lexer::Type> >& lexemes) const
|
||||||
|
{
|
||||||
|
return lexemes.size () < 3 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool CLI::disqualifyNoOps (
|
||||||
|
const std::vector <std::pair <std::string, Lexer::Type> >& lexemes) const
|
||||||
|
{
|
||||||
|
bool foundOP = false;
|
||||||
|
std::vector <std::pair <std::string, Lexer::Type> >::const_iterator l;
|
||||||
|
for (l = lexemes.begin (); l != lexemes.end (); ++l)
|
||||||
|
if (l->second == Lexer::typeOperator)
|
||||||
|
foundOP = true;
|
||||||
|
|
||||||
|
return ! foundOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <Lexer.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
|
||||||
|
@ -125,6 +126,9 @@ private:
|
||||||
bool isOperator (const std::string&) const;
|
bool isOperator (const std::string&) const;
|
||||||
bool isName (const std::string&) const;
|
bool isName (const std::string&) const;
|
||||||
|
|
||||||
|
bool disqualifyInsufficientTerms (const std::vector <std::pair <std::string, Lexer::Type> >&) const;
|
||||||
|
bool disqualifyNoOps (const std::vector <std::pair <std::string, Lexer::Type> >&) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::multimap <std::string, std::string> _entities;
|
std::multimap <std::string, std::string> _entities;
|
||||||
std::map <std::string, std::string> _aliases;
|
std::map <std::string, std::string> _aliases;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue