mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
CLI2: Better algorithm for ::desugarFilterPlainArgs which appears to work well
This commit is contained in:
parent
f240c783cb
commit
81fc158dc9
2 changed files with 56 additions and 21 deletions
74
src/CLI2.cpp
74
src/CLI2.cpp
|
@ -652,7 +652,7 @@ void CLI2::prepareFilter (bool applyContext)
|
||||||
findIDs ();
|
findIDs ();
|
||||||
findUUIDs ();
|
findUUIDs ();
|
||||||
insertIDExpr ();
|
insertIDExpr ();
|
||||||
desugarFilterPlainArgs (); // Unimplemented.
|
desugarFilterPlainArgs ();
|
||||||
findStrayModifications ();
|
findStrayModifications ();
|
||||||
desugarFilterTags ();
|
desugarFilterTags ();
|
||||||
desugarFilterAttributes ();
|
desugarFilterAttributes ();
|
||||||
|
@ -1517,44 +1517,81 @@ void CLI2::insertIDExpr ()
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO Removed because this algorithm is unreliable. Fix it.
|
// FILTER, Lexer::Type::word args are treated as search terms.
|
||||||
|
//
|
||||||
|
// Algorithm:
|
||||||
|
// Given:
|
||||||
|
// - task ... argX candidate argY
|
||||||
|
// Where:
|
||||||
|
// - neither argX nor argY are an operator, except (, ), and, or, xor
|
||||||
|
// - candidate is Lexer::Type::word
|
||||||
|
//
|
||||||
void CLI2::desugarFilterPlainArgs ()
|
void CLI2::desugarFilterPlainArgs ()
|
||||||
{
|
{
|
||||||
/*
|
// First walk the arg list looking for plain words that are not part of an
|
||||||
bool changes = false;
|
// existing expression.
|
||||||
std::vector <A2> reconstructed;
|
auto prevprev = &_args[0];
|
||||||
auto prev = &_args[0];
|
auto prev = &_args[0];
|
||||||
for (auto& a : _args)
|
for (auto& a : _args)
|
||||||
{
|
{
|
||||||
if (prev->_lextype != Lexer::Type::op &&
|
auto raw = a.attribute ("raw");
|
||||||
a.hasTag ("FILTER") &&
|
auto praw = prev->attribute ("raw");
|
||||||
(a._lextype == Lexer::Type::dom ||
|
auto ppraw = prevprev->attribute ("raw");
|
||||||
a._lextype == Lexer::Type::identifier ||
|
|
||||||
a._lextype == Lexer::Type::word ||
|
if ((prevprev->_lextype != Lexer::Type::op || // argX
|
||||||
a._lextype == Lexer::Type::string ||
|
ppraw == "(" ||
|
||||||
a._lextype == Lexer::Type::number ||
|
ppraw == ")" ||
|
||||||
a._lextype == Lexer::Type::hex))
|
ppraw == "and" ||
|
||||||
|
ppraw == "or" ||
|
||||||
|
ppraw == "xor") &&
|
||||||
|
|
||||||
|
prev->_lextype == Lexer::Type::word && // candidate
|
||||||
|
|
||||||
|
prev->hasTag ("FILTER") && // candidate
|
||||||
|
|
||||||
|
(a._lextype != Lexer::Type::op || // argY
|
||||||
|
raw == "(" ||
|
||||||
|
raw == ")" ||
|
||||||
|
raw == "and" ||
|
||||||
|
raw == "or" ||
|
||||||
|
raw == "xor"))
|
||||||
|
{
|
||||||
|
prev->tag ("PLAIN");
|
||||||
|
}
|
||||||
|
|
||||||
|
prevprev = prev;
|
||||||
|
prev = &a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk the list again, upgrading PLAIN args.
|
||||||
|
bool changes = false;
|
||||||
|
std::vector <A2> reconstructed;
|
||||||
|
for (auto& a : _args)
|
||||||
|
{
|
||||||
|
if (a.hasTag ("PLAIN"))
|
||||||
{
|
{
|
||||||
changes = true;
|
changes = true;
|
||||||
|
|
||||||
A2 lhs ("description", Lexer::Type::dom);
|
A2 lhs ("description", Lexer::Type::dom);
|
||||||
|
lhs.attribute ("canonical", "description");
|
||||||
lhs.tag ("FILTER");
|
lhs.tag ("FILTER");
|
||||||
|
lhs.tag ("PLAIN");
|
||||||
reconstructed.push_back (lhs);
|
reconstructed.push_back (lhs);
|
||||||
|
|
||||||
A2 op ("~", Lexer::Type::op);
|
A2 op ("~", Lexer::Type::op);
|
||||||
op.tag ("FILTER");
|
op.tag ("FILTER");
|
||||||
|
op.tag ("PLAIN");
|
||||||
reconstructed.push_back (op);
|
reconstructed.push_back (op);
|
||||||
|
|
||||||
std::string raw = a.attribute ("raw");
|
std::string word = a.attribute ("raw");
|
||||||
Lexer::dequote (raw);
|
Lexer::dequote (word);
|
||||||
A2 rhs (raw, Lexer::Type::string);
|
A2 rhs (word, Lexer::Type::string);
|
||||||
rhs.tag ("FILTER");
|
rhs.tag ("FILTER");
|
||||||
|
rhs.tag ("PLAIN");
|
||||||
reconstructed.push_back (rhs);
|
reconstructed.push_back (rhs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
reconstructed.push_back (a);
|
reconstructed.push_back (a);
|
||||||
|
|
||||||
prev = &a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes)
|
if (changes)
|
||||||
|
@ -1564,7 +1601,6 @@ void CLI2::desugarFilterPlainArgs ()
|
||||||
if (context.config.getInteger ("debug.parser") >= 3)
|
if (context.config.getInteger ("debug.parser") >= 3)
|
||||||
context.debug (dump ("CLI2::prepareFilter desugarFilterPlainArgs"));
|
context.debug (dump ("CLI2::prepareFilter desugarFilterPlainArgs"));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -129,12 +129,11 @@ For anyone looking for test-related tasks to take on, here are some suggestions:
|
||||||
* Select a bug.*.t Perl test and convert it to Python using the template.
|
* Select a bug.*.t Perl test and convert it to Python using the template.
|
||||||
|
|
||||||
* Look at the latest todo.txt file format spec, and make sure that
|
* Look at the latest todo.txt file format spec, and make sure that
|
||||||
import.todo.sh.t is testing the current format.
|
import.todo.sh.t is thoroughly testing the current format.
|
||||||
|
|
||||||
* Select a feature.*.t Perl test, convert it to Python using the template,
|
* Select a feature.*.t Perl test, convert it to Python using the template,
|
||||||
then rename it to <feature>.t
|
then rename it to <feature>.t
|
||||||
|
|
||||||
* Find and eliminate individuals test that do the same thing.
|
* Find and eliminate individuals test that do the same thing.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue