mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 07:57:20 +02:00
CLI2: Implemented ::findIDs using Lexer::Type::set
This commit is contained in:
parent
b2803bddda
commit
d97aab799a
2 changed files with 50 additions and 80 deletions
120
src/CLI2.cpp
120
src/CLI2.cpp
|
@ -27,8 +27,8 @@
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
//#include <Nibbler.h>
|
|
||||||
#include <CLI2.h>
|
#include <CLI2.h>
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
@ -596,8 +596,10 @@ const std::string CLI2::getFilter (bool applyContext)
|
||||||
// sugar as necessary.
|
// sugar as necessary.
|
||||||
void CLI2::prepareFilter (bool applyContext)
|
void CLI2::prepareFilter (bool applyContext)
|
||||||
{
|
{
|
||||||
// TODO This is from the old CLI::categorize method, and needs to be replicated
|
// Clear and re-populate.
|
||||||
// here.
|
_id_ranges.clear ();
|
||||||
|
|
||||||
|
// Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD.
|
||||||
bool changes = false;
|
bool changes = false;
|
||||||
bool foundCommand = false;
|
bool foundCommand = false;
|
||||||
bool readOnly = false;
|
bool readOnly = false;
|
||||||
|
@ -632,11 +634,12 @@ void CLI2::prepareFilter (bool applyContext)
|
||||||
context.config.getInteger ("debug.parser") >= 3)
|
context.config.getInteger ("debug.parser") >= 3)
|
||||||
context.debug (dump ("CLI2::prepareFilter categorize"));
|
context.debug (dump ("CLI2::prepareFilter categorize"));
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO This is from the old CLI::analyze method, but need to be replicated here.
|
// TODO This is from the old CLI::analyze method, but need to be replicated here.
|
||||||
|
|
||||||
// Remove all the syntactic sugar for FILTERs.
|
// Remove all the syntactic sugar for FILTERs.
|
||||||
|
changes = false;
|
||||||
findIDs ();
|
findIDs ();
|
||||||
|
/*
|
||||||
findUUIDs ();
|
findUUIDs ();
|
||||||
insertIDExpr ();
|
insertIDExpr ();
|
||||||
desugarFilterTags ();
|
desugarFilterTags ();
|
||||||
|
@ -655,6 +658,10 @@ void CLI2::prepareFilter (bool applyContext)
|
||||||
decomposeModTags ();
|
decomposeModTags ();
|
||||||
decomposeModSubstitutions ();
|
decomposeModSubstitutions ();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (changes &&
|
||||||
|
context.config.getInteger ("debug.parser") >= 3)
|
||||||
|
context.debug (dump ("CLI2::prepareFilter desugar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1406,6 +1413,7 @@ void CLI2::desugarFilterPatterns ()
|
||||||
context.debug (dump ("CLI2::analyze desugarFilterPatterns"));
|
context.debug (dump ("CLI2::analyze desugarFilterPatterns"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// An ID sequence can be:
|
// An ID sequence can be:
|
||||||
|
@ -1422,97 +1430,57 @@ void CLI2::findIDs ()
|
||||||
{
|
{
|
||||||
if (a.hasTag ("FILTER"))
|
if (a.hasTag ("FILTER"))
|
||||||
{
|
{
|
||||||
// IDs have a limited character set.
|
if (a._lextype == Lexer::Type::number)
|
||||||
std::string raw = a.attribute ("raw");
|
{
|
||||||
if (raw.find_first_not_of ("0123456789,-") == std::string::npos)
|
unsigned int number = strtol (a.attribute ("raw").c_str (), NULL, 10);
|
||||||
|
_id_ranges.push_back (std::pair <int, int> (number, number));
|
||||||
|
}
|
||||||
|
else if (a._lextype == Lexer::Type::set)
|
||||||
{
|
{
|
||||||
// Container for min/max ID ranges.
|
|
||||||
std::vector <std::pair <int, int>> ranges;
|
|
||||||
|
|
||||||
// Split the ID list into elements.
|
// Split the ID list into elements.
|
||||||
std::vector <std::string> elements;
|
std::vector <std::string> elements;
|
||||||
split (elements, raw, ',');
|
split (elements, a.attribute ("raw"), ',');
|
||||||
|
|
||||||
bool is_an_id = true;
|
for (auto& element : elements)
|
||||||
for (auto& e : elements)
|
|
||||||
{
|
{
|
||||||
// Split the ID range into min/max.
|
auto hyphen = element.find ("-");
|
||||||
std::vector <std::string> terms;
|
if (hyphen != std::string::npos)
|
||||||
split (terms, e, '-');
|
|
||||||
|
|
||||||
if (terms.size () == 1)
|
|
||||||
{
|
{
|
||||||
if (! Lexer::isAllDigits (terms[0]))
|
unsigned int number_low = strtol (element.substr (0, hyphen).c_str (), NULL, 10);
|
||||||
{
|
unsigned int number_high = strtol (element.substr (hyphen + 1).c_str (), NULL, 10);
|
||||||
is_an_id = false;
|
_id_ranges.push_back (std::pair <int, int> (number_low, number_high));
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Nibbler n (terms[0]);
|
|
||||||
int id;
|
|
||||||
if (n.getUnsignedInt (id) &&
|
|
||||||
n.depleted ())
|
|
||||||
{
|
|
||||||
ranges.push_back (std::pair <int, int> (id, id));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is_an_id = false;
|
unsigned int number = strtol (element.c_str (), NULL, 10);
|
||||||
break;
|
_id_ranges.push_back (std::pair <int, int> (number, number));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (terms.size () == 2)
|
|
||||||
{
|
|
||||||
if (! Lexer::isAllDigits (terms[0]) ||
|
|
||||||
! Lexer::isAllDigits (terms[1]))
|
|
||||||
{
|
|
||||||
is_an_id = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Nibbler n_min (terms[0]);
|
|
||||||
Nibbler n_max (terms[1]);
|
|
||||||
int id_min;
|
|
||||||
int id_max;
|
|
||||||
if (n_min.getUnsignedInt (id_min) &&
|
|
||||||
n_min.depleted () &&
|
|
||||||
n_max.getUnsignedInt (id_max) &&
|
|
||||||
n_max.depleted ())
|
|
||||||
{
|
|
||||||
if (id_min > id_max)
|
|
||||||
{
|
|
||||||
is_an_id = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ranges.push_back (std::pair <int, int> (id_min, id_max));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
is_an_id = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
is_an_id = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_an_id)
|
|
||||||
{
|
|
||||||
a.tag ("ID");
|
a.tag ("ID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save the ranges.
|
if (_id_ranges.size () &&
|
||||||
for (auto& r : ranges)
|
context.config.getInteger ("debug.parser") >= 3)
|
||||||
_id_ranges.push_back (r);
|
{
|
||||||
}
|
Color colorRanges ("gray10 on gray4");
|
||||||
}
|
std::string ids;
|
||||||
|
for (auto& range : _id_ranges)
|
||||||
|
{
|
||||||
|
ids += " ";
|
||||||
|
if (range.first != range.second)
|
||||||
|
ids += colorRanges.colorize (format ("{1}-{2}", range.first, range.second));
|
||||||
|
else
|
||||||
|
ids += colorRanges.colorize (format ("{1}", range.first));
|
||||||
}
|
}
|
||||||
|
context.debug ("CLI2::prepareFilter findIDs");
|
||||||
|
context.debug (" _id_ranges" + ids + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void CLI2::findUUIDs ()
|
void CLI2::findUUIDs ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,7 +120,9 @@ private:
|
||||||
void desugarFilterAttributes ();
|
void desugarFilterAttributes ();
|
||||||
void desugarFilterAttributeModifiers ();
|
void desugarFilterAttributeModifiers ();
|
||||||
void desugarFilterPatterns ();
|
void desugarFilterPatterns ();
|
||||||
|
*/
|
||||||
void findIDs ();
|
void findIDs ();
|
||||||
|
/*
|
||||||
void findUUIDs ();
|
void findUUIDs ();
|
||||||
void insertIDExpr ();
|
void insertIDExpr ();
|
||||||
void desugarFilterPlainArgs ();
|
void desugarFilterPlainArgs ();
|
||||||
|
@ -160,8 +162,8 @@ public:
|
||||||
std::vector <std::string> _original_args;
|
std::vector <std::string> _original_args;
|
||||||
std::vector <A2> _args;
|
std::vector <A2> _args;
|
||||||
|
|
||||||
/*
|
|
||||||
std::vector <std::pair <int, int>> _id_ranges;
|
std::vector <std::pair <int, int>> _id_ranges;
|
||||||
|
/*
|
||||||
std::vector <std::string> _uuid_list;
|
std::vector <std::string> _uuid_list;
|
||||||
bool _strict;
|
bool _strict;
|
||||||
bool _terminated;
|
bool _terminated;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue