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)
|
void Arguments::capture (int argc, const char** argv)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
this->push_back (std::make_pair (argv[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 ();
|
categorize ();
|
||||||
}
|
}
|
||||||
|
@ -157,7 +167,16 @@ void Arguments::capture (int argc, const char** argv)
|
||||||
// Add a pair with a category of "".
|
// Add a pair with a category of "".
|
||||||
void Arguments::capture (const std::string& arg)
|
void Arguments::capture (const std::string& arg)
|
||||||
{
|
{
|
||||||
this->push_back (std::make_pair (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 ();
|
categorize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,6 +636,26 @@ bool Arguments::find_command (std::string& command)
|
||||||
return false;
|
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 (
|
bool Arguments::is_command (
|
||||||
const std::vector <std::string>& keywords,
|
const std::vector <std::string>& keywords,
|
||||||
|
@ -758,12 +797,10 @@ bool Arguments::is_subst (const std::string& input)
|
||||||
// /<pattern>/
|
// /<pattern>/
|
||||||
bool Arguments::is_pattern (const std::string& input)
|
bool Arguments::is_pattern (const std::string& input)
|
||||||
{
|
{
|
||||||
unsigned int length = input.length ();
|
Nibbler n (input);
|
||||||
|
std::string pattern;
|
||||||
if (input[0] == '/' &&
|
if (input.length () > 2 &&
|
||||||
length > 2 &&
|
n.getQuoted ('/', pattern, true))
|
||||||
input[length - 1] == '/' &&
|
|
||||||
input.find ('/', 1) == length - 1)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -974,7 +1011,8 @@ bool Arguments::extract_attr (
|
||||||
{
|
{
|
||||||
// Both quoted and unquoted Att's are accepted.
|
// Both quoted and unquoted Att's are accepted.
|
||||||
// Consider removing this for a stricter parse.
|
// Consider removing this for a stricter parse.
|
||||||
if (n.getQuoted ('"', value) ||
|
if (n.getQuoted ('"', value) ||
|
||||||
|
n.getQuoted ('\'', value) ||
|
||||||
n.getUntilEOS (value))
|
n.getUntilEOS (value))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -1031,7 +1069,8 @@ bool Arguments::extract_attmod (
|
||||||
{
|
{
|
||||||
// Both quoted and unquoted Att's are accepted.
|
// Both quoted and unquoted Att's are accepted.
|
||||||
// Consider removing this for a stricter parse.
|
// Consider removing this for a stricter parse.
|
||||||
if (n.getQuoted ('"', value) ||
|
if (n.getQuoted ('"', value) ||
|
||||||
|
n.getQuoted ('\'', value) ||
|
||||||
n.getUntilEOS (value))
|
n.getUntilEOS (value))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
|
|
||||||
bool find_command (std::string&);
|
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_command (const std::vector <std::string>&, std::string&);
|
||||||
static bool is_attr (const std::string&);
|
static bool is_attr (const std::string&);
|
||||||
static bool is_attmod (const std::string&);
|
static bool is_attmod (const std::string&);
|
||||||
|
|
|
@ -230,7 +230,9 @@ bool DOM::is_primitive (const std::string& input)
|
||||||
|
|
||||||
// String?
|
// String?
|
||||||
Nibbler n (input);
|
Nibbler n (input);
|
||||||
if (n.getQuoted ('"', s) && n.depleted ())
|
if ((n.getQuoted ('"', s) ||
|
||||||
|
n.getQuoted ('\'', s)) &&
|
||||||
|
n.depleted ())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Number?
|
// Number?
|
||||||
|
|
|
@ -45,26 +45,26 @@ Expression::Expression (Arguments& arguments)
|
||||||
{
|
{
|
||||||
_args.dump ("Expression::Expression");
|
_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");
|
context.debug ("Filter --> new");
|
||||||
expand_sequence ();
|
|
||||||
expand_tokens ();
|
|
||||||
postfix ();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
context.debug ("Filter --> old");
|
context.debug ("Filter --> old");
|
||||||
expand_sequence ();
|
|
||||||
|
expand_sequence ();
|
||||||
|
|
||||||
|
if (new_style)
|
||||||
|
{
|
||||||
implicit_and ();
|
implicit_and ();
|
||||||
expand_tag ();
|
expand_tag ();
|
||||||
expand_pattern ();
|
expand_pattern ();
|
||||||
expand_attr ();
|
expand_attr ();
|
||||||
expand_attmod ();
|
expand_attmod ();
|
||||||
expand_word ();
|
expand_word ();
|
||||||
expand_tokens ();
|
|
||||||
postfix ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expand_tokens ();
|
||||||
|
postfix ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -226,6 +226,9 @@ void Expression::expand_tokens ()
|
||||||
n.getQuoted ('\'', s, true))
|
n.getQuoted ('\'', s, true))
|
||||||
temp.push_back (std::make_pair (s, "string"));
|
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))
|
else if (n.getOneOf (operators, s))
|
||||||
temp.push_back (std::make_pair (s, "op"));
|
temp.push_back (std::make_pair (s, "op"));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue