mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Expressions
- Command line arguments are now handled a little differently. Each argument is subjected to further splitting, to break up expressions early in the process, prior to categorization. - Patterns are now treated as quoted string, where the quote character is /.
This commit is contained in:
parent
087cf7e5ed
commit
e0abee7f9f
4 changed files with 66 additions and 21 deletions
|
@ -148,7 +148,17 @@ Arguments::~Arguments ()
|
|||
void Arguments::capture (int argc, const char** argv)
|
||||
{
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
std::vector <std::string> parts;
|
||||
if (is_multipart (argv[i], parts))
|
||||
{
|
||||
std::vector <std::string>::iterator part;
|
||||
for (part = parts.begin (); part != parts.end (); ++part)
|
||||
this->push_back (std::make_pair (*part, ""));
|
||||
}
|
||||
else
|
||||
this->push_back (std::make_pair (argv[i], ""));
|
||||
}
|
||||
|
||||
categorize ();
|
||||
}
|
||||
|
@ -157,7 +167,16 @@ void Arguments::capture (int argc, const char** argv)
|
|||
// Add a pair with a category of "".
|
||||
void Arguments::capture (const std::string& arg)
|
||||
{
|
||||
std::vector <std::string> parts;
|
||||
if (is_multipart (arg, parts))
|
||||
{
|
||||
std::vector <std::string>::iterator part;
|
||||
for (part = parts.begin (); part != parts.end (); ++part)
|
||||
this->push_back (std::make_pair (*part, ""));
|
||||
}
|
||||
else
|
||||
this->push_back (std::make_pair (arg, ""));
|
||||
|
||||
categorize ();
|
||||
}
|
||||
|
||||
|
@ -617,6 +636,26 @@ bool Arguments::find_command (std::string& command)
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Arguments::is_multipart (
|
||||
const std::string& input,
|
||||
std::vector <std::string>& parts)
|
||||
{
|
||||
parts.clear ();
|
||||
Nibbler n (input);
|
||||
std::string part;
|
||||
while (n.getQuoted ('"', part) ||
|
||||
n.getQuoted ('\'', part) ||
|
||||
n.getQuoted ('/', part) ||
|
||||
n.getUntilWS (part))
|
||||
{
|
||||
n.skipWS ();
|
||||
parts.push_back (part);
|
||||
}
|
||||
|
||||
return parts.size () > 1 ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Arguments::is_command (
|
||||
const std::vector <std::string>& keywords,
|
||||
|
@ -758,12 +797,10 @@ bool Arguments::is_subst (const std::string& input)
|
|||
// /<pattern>/
|
||||
bool Arguments::is_pattern (const std::string& input)
|
||||
{
|
||||
unsigned int length = input.length ();
|
||||
|
||||
if (input[0] == '/' &&
|
||||
length > 2 &&
|
||||
input[length - 1] == '/' &&
|
||||
input.find ('/', 1) == length - 1)
|
||||
Nibbler n (input);
|
||||
std::string pattern;
|
||||
if (input.length () > 2 &&
|
||||
n.getQuoted ('/', pattern, true))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -975,6 +1012,7 @@ bool Arguments::extract_attr (
|
|||
// Both quoted and unquoted Att's are accepted.
|
||||
// Consider removing this for a stricter parse.
|
||||
if (n.getQuoted ('"', value) ||
|
||||
n.getQuoted ('\'', value) ||
|
||||
n.getUntilEOS (value))
|
||||
{
|
||||
return true;
|
||||
|
@ -1032,6 +1070,7 @@ bool Arguments::extract_attmod (
|
|||
// Both quoted and unquoted Att's are accepted.
|
||||
// Consider removing this for a stricter parse.
|
||||
if (n.getQuoted ('"', value) ||
|
||||
n.getQuoted ('\'', value) ||
|
||||
n.getUntilEOS (value))
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
|
||||
bool find_command (std::string&);
|
||||
|
||||
static bool is_multipart (const std::string&, std::vector <std::string>&);
|
||||
static bool is_command (const std::vector <std::string>&, std::string&);
|
||||
static bool is_attr (const std::string&);
|
||||
static bool is_attmod (const std::string&);
|
||||
|
|
|
@ -230,7 +230,9 @@ bool DOM::is_primitive (const std::string& input)
|
|||
|
||||
// String?
|
||||
Nibbler n (input);
|
||||
if (n.getQuoted ('"', s) && n.depleted ())
|
||||
if ((n.getQuoted ('"', s) ||
|
||||
n.getQuoted ('\'', s)) &&
|
||||
n.depleted ())
|
||||
return true;
|
||||
|
||||
// Number?
|
||||
|
|
|
@ -45,26 +45,26 @@ Expression::Expression (Arguments& arguments)
|
|||
{
|
||||
_args.dump ("Expression::Expression");
|
||||
|
||||
if (is_new_style () && context.config.getBoolean ("expressions"))
|
||||
{
|
||||
bool new_style = is_new_style () && context.config.getBoolean ("expressions");
|
||||
if (new_style)
|
||||
context.debug ("Filter --> new");
|
||||
expand_sequence ();
|
||||
expand_tokens ();
|
||||
postfix ();
|
||||
}
|
||||
else
|
||||
{
|
||||
context.debug ("Filter --> old");
|
||||
|
||||
expand_sequence ();
|
||||
|
||||
if (new_style)
|
||||
{
|
||||
implicit_and ();
|
||||
expand_tag ();
|
||||
expand_pattern ();
|
||||
expand_attr ();
|
||||
expand_attmod ();
|
||||
expand_word ();
|
||||
}
|
||||
|
||||
expand_tokens ();
|
||||
postfix ();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -226,6 +226,9 @@ void Expression::expand_tokens ()
|
|||
n.getQuoted ('\'', s, true))
|
||||
temp.push_back (std::make_pair (s, "string"));
|
||||
|
||||
else if (n.getQuoted ('/', s, true))
|
||||
temp.push_back (std::make_pair (s, "pattern"));
|
||||
|
||||
else if (n.getOneOf (operators, s))
|
||||
temp.push_back (std::make_pair (s, "op"));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue