mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Expression reboot
- Implemented A3::is_id and A3::is_uuid. - Obsolted old is_operator. - Obsolted old is_modifier. - Obsolted old is_expression.
This commit is contained in:
parent
0ecf93553c
commit
b3a73f2da1
2 changed files with 84 additions and 127 deletions
204
src/A3.cpp
204
src/A3.cpp
|
@ -691,6 +691,18 @@ const A3 A3::tokenize (const A3& input) const
|
||||||
output.push_back (Arg (s, "duration"));
|
output.push_back (Arg (s, "duration"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (is_id (n, s))
|
||||||
|
{
|
||||||
|
std::cout << "# id '" << s << "'\n";
|
||||||
|
output.push_back (Arg (s, "id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (is_uuid (n, s))
|
||||||
|
{
|
||||||
|
std::cout << "# uuid '" << s << "'\n";
|
||||||
|
output.push_back (Arg (s, "uuid"));
|
||||||
|
}
|
||||||
|
|
||||||
else if (n.getNumber (d))
|
else if (n.getNumber (d))
|
||||||
{
|
{
|
||||||
std::cout << "# num '" << d << "'\n";
|
std::cout << "# num '" << d << "'\n";
|
||||||
|
@ -1021,6 +1033,76 @@ bool A3::is_subst (Nibbler& n, std::string& result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// <uuid>[,...]
|
||||||
|
bool A3::is_uuid (Nibbler& n, std::string& result)
|
||||||
|
{
|
||||||
|
n.save ();
|
||||||
|
result = "";
|
||||||
|
std::string uuid;
|
||||||
|
if (n.getUUID (uuid))
|
||||||
|
{
|
||||||
|
result += uuid;
|
||||||
|
while (n.skip (',') &&
|
||||||
|
n.getUUID (uuid))
|
||||||
|
{
|
||||||
|
result += ',' + uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
n.restore ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// <id>[-<id>][,<id>[-<id>]]
|
||||||
|
bool A3::is_id (Nibbler& n, std::string& result)
|
||||||
|
{
|
||||||
|
n.save ();
|
||||||
|
std::string::size_type start = n.cursor ();
|
||||||
|
int id;
|
||||||
|
|
||||||
|
if (n.getUnsignedInt (id))
|
||||||
|
{
|
||||||
|
if (n.skip ('-') &&
|
||||||
|
!n.getUnsignedInt (id))
|
||||||
|
{
|
||||||
|
n.restore ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (n.skip (','))
|
||||||
|
{
|
||||||
|
if (n.getUnsignedInt (id))
|
||||||
|
{
|
||||||
|
if (n.skip ('-'))
|
||||||
|
{
|
||||||
|
if (!n.getUnsignedInt (id))
|
||||||
|
{
|
||||||
|
n.restore ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n.restore ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string::size_type end = n.cursor ();
|
||||||
|
n.restore ();
|
||||||
|
if (n.getN (end - start, result))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
n.restore ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1035,62 +1117,6 @@ bool A3::is_subst (Nibbler& n, std::string& result)
|
||||||
|
|
||||||
|
|
||||||
#ifdef NOPE
|
#ifdef NOPE
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// <id>[-<id>][,<id>[-<id>]]
|
|
||||||
bool A3::is_id (const std::string& input)
|
|
||||||
{
|
|
||||||
Nibbler n (input);
|
|
||||||
int id;
|
|
||||||
|
|
||||||
if (n.getUnsignedInt (id))
|
|
||||||
{
|
|
||||||
if (n.skip ('-'))
|
|
||||||
{
|
|
||||||
if (!n.getUnsignedInt (id))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (n.skip (','))
|
|
||||||
{
|
|
||||||
if (n.getUnsignedInt (id))
|
|
||||||
{
|
|
||||||
if (n.skip ('-'))
|
|
||||||
{
|
|
||||||
if (!n.getUnsignedInt (id))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return n.depleted ();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// <uuid>[,...]
|
|
||||||
bool A3::is_uuid (const std::string& input)
|
|
||||||
{
|
|
||||||
Nibbler n (input);
|
|
||||||
std::string uuid;
|
|
||||||
|
|
||||||
if (n.getUUID (uuid))
|
|
||||||
{
|
|
||||||
while (n.skip (','))
|
|
||||||
{
|
|
||||||
if (!n.getUUID (uuid))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return n.depleted ();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// [+-]<tag>
|
// [+-]<tag>
|
||||||
bool A3::is_tag (const std::string& input)
|
bool A3::is_tag (const std::string& input)
|
||||||
|
@ -1108,16 +1134,6 @@ bool A3::is_tag (const std::string& input)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool A3::is_operator (const std::string& input)
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < NUM_OPERATORS; ++i)
|
|
||||||
if (operators[i].op == input)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool A3::is_operator (
|
bool A3::is_operator (
|
||||||
const std::string& input,
|
const std::string& input,
|
||||||
|
@ -1148,62 +1164,6 @@ bool A3::is_symbol_operator (const std::string& input)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool A3::is_modifier (const std::string& input)
|
|
||||||
{
|
|
||||||
// Guess at the full attribute name.
|
|
||||||
std::vector <std::string> candidates;
|
|
||||||
for (unsigned i = 0; i < NUM_MODIFIER_NAMES; ++i)
|
|
||||||
{
|
|
||||||
// Short-circuit: exact matches cause immediate return.
|
|
||||||
if (modifierNames[i] == input)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
candidates.push_back (modifierNames[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector <std::string> matches;
|
|
||||||
autoComplete (input,
|
|
||||||
candidates,
|
|
||||||
matches,
|
|
||||||
context.config.getInteger ("abbreviation.minimum"));
|
|
||||||
|
|
||||||
if (matches.size () == 1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool A3::is_expression (const std::string& input)
|
|
||||||
{
|
|
||||||
std::string unquoted = unquoteText (input);
|
|
||||||
|
|
||||||
// Look for space-separated operators.
|
|
||||||
std::vector <std::string> tokens;
|
|
||||||
split (tokens, unquoted, ' ');
|
|
||||||
std::vector <std::string>::iterator token;
|
|
||||||
for (token = tokens.begin (); token != tokens.end (); ++token)
|
|
||||||
if (is_operator (*token))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Look for bare or cuddled operators.
|
|
||||||
Lexer lexer (unquoted);
|
|
||||||
lexer.skipWhitespace (true);
|
|
||||||
lexer.coalesceAlpha (true);
|
|
||||||
lexer.coalesceDigits (true);
|
|
||||||
lexer.coalesceQuoted (true);
|
|
||||||
|
|
||||||
tokens.clear ();
|
|
||||||
lexer.tokenize (tokens);
|
|
||||||
|
|
||||||
for (token = tokens.begin (); token != tokens.end (); ++token)
|
|
||||||
if (is_operator (*token))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// <name>:['"]<value>['"]
|
// <name>:['"]<value>['"]
|
||||||
bool A3::extract_attr (
|
bool A3::extract_attr (
|
||||||
|
|
7
src/A3.h
7
src/A3.h
|
@ -113,16 +113,13 @@ public:
|
||||||
static bool is_duration (Nibbler&, std::string&);
|
static bool is_duration (Nibbler&, std::string&);
|
||||||
static bool is_pattern (Nibbler&, std::string&);
|
static bool is_pattern (Nibbler&, std::string&);
|
||||||
static bool is_subst (Nibbler&, std::string&);
|
static bool is_subst (Nibbler&, std::string&);
|
||||||
|
static bool is_id (Nibbler&, std::string&);
|
||||||
|
static bool is_uuid (Nibbler&, std::string&);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static bool is_id (const std::string&);
|
|
||||||
static bool is_uuid (const std::string&);
|
|
||||||
static bool is_tag (const std::string&);
|
static bool is_tag (const std::string&);
|
||||||
static bool is_operator (const std::string&);
|
|
||||||
static bool is_operator (const std::string&, char&, int&, char&);
|
static bool is_operator (const std::string&, char&, int&, char&);
|
||||||
static bool is_symbol_operator (const std::string&);
|
static bool is_symbol_operator (const std::string&);
|
||||||
static bool is_modifier (const std::string&);
|
|
||||||
static bool is_expression (const std::string&);
|
|
||||||
|
|
||||||
static bool extract_attr (const std::string&, std::string&, std::string&);
|
static bool extract_attr (const std::string&, std::string&, std::string&);
|
||||||
static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);
|
static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue