Debug: rc.sugar enables ID/UUID snytactic sugar

- This is not documented.  It is not for users.
This commit is contained in:
Paul Beckingham 2015-08-07 11:35:27 -04:00
parent 92d37e5124
commit 6f294e2968
4 changed files with 147 additions and 85 deletions

View file

@ -1313,6 +1313,10 @@ void CLI2::desugarFilterPatterns ()
// or a combination: 1,3,5-10 12 // or a combination: 1,3,5-10 12
// //
void CLI2::findIDs () void CLI2::findIDs ()
{
bool changes = false;
if (context.config.getBoolean ("sugar"))
{ {
bool previousFilterArgWasAnOperator = false; bool previousFilterArgWasAnOperator = false;
int filterCount = 0; int filterCount = 0;
@ -1328,6 +1332,7 @@ void CLI2::findIDs ()
// Skip any number that was preceded by an operator. // Skip any number that was preceded by an operator.
if (! previousFilterArgWasAnOperator) if (! previousFilterArgWasAnOperator)
{ {
changes = true;
std::string number = a.attribute ("raw"); std::string number = a.attribute ("raw");
_id_ranges.push_back (std::pair <std::string, std::string> (number, number)); _id_ranges.push_back (std::pair <std::string, std::string> (number, number));
} }
@ -1340,6 +1345,7 @@ void CLI2::findIDs ()
for (auto& element : elements) for (auto& element : elements)
{ {
changes = true;
auto hyphen = element.find ("-"); auto hyphen = element.find ("-");
if (hyphen != std::string::npos) if (hyphen != std::string::npos)
{ {
@ -1383,6 +1389,7 @@ void CLI2::findIDs ()
raw.find ('e') == std::string::npos && raw.find ('e') == std::string::npos &&
raw.find ('-') == std::string::npos) raw.find ('-') == std::string::npos)
{ {
changes = true;
a.unTag ("MODIFICATION"); a.unTag ("MODIFICATION");
a.tag ("FILTER"); a.tag ("FILTER");
_id_ranges.push_back (std::pair <std::string, std::string> (raw, raw)); _id_ranges.push_back (std::pair <std::string, std::string> (raw, raw));
@ -1398,6 +1405,7 @@ void CLI2::findIDs ()
for (auto& element : elements) for (auto& element : elements)
{ {
changes = true;
auto hyphen = element.find ("-"); auto hyphen = element.find ("-");
if (hyphen != std::string::npos) if (hyphen != std::string::npos)
{ {
@ -1412,20 +1420,49 @@ void CLI2::findIDs ()
} }
} }
} }
}
if (_id_ranges.size ()) // Sugar-free.
else
{
std::vector <A2> reconstructed;
for (auto& a : _args)
{
if (a.hasTag ("FILTER") &&
a._lextype == Lexer::Type::number)
{
changes = true;
A2 pair ("id:" + a.attribute ("raw"), Lexer::Type::pair);
pair.tag ("FILTER");
pair.decompose ();
reconstructed.push_back (pair);
}
else
reconstructed.push_back (a);
}
if (changes)
_args = reconstructed;
}
if (changes)
if (context.config.getInteger ("debug.parser") >= 3) if (context.config.getInteger ("debug.parser") >= 3)
context.debug (dump ("CLI2::prepareFilter findIDs")); context.debug (dump ("CLI2::prepareFilter findIDs"));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CLI2::findUUIDs () void CLI2::findUUIDs ()
{
bool changes = false;
if (context.config.getBoolean ("sugar"))
{ {
for (auto& a : _args) for (auto& a : _args)
{ {
if (a._lextype == Lexer::Type::uuid && if (a._lextype == Lexer::Type::uuid &&
a.hasTag ("FILTER")) a.hasTag ("FILTER"))
{ {
changes = true;
_uuid_list.push_back (a.attribute ("raw")); _uuid_list.push_back (a.attribute ("raw"));
} }
} }
@ -1437,14 +1474,39 @@ void CLI2::findUUIDs ()
if (a._lextype == Lexer::Type::uuid && if (a._lextype == Lexer::Type::uuid &&
a.hasTag ("MODIFICATION")) a.hasTag ("MODIFICATION"))
{ {
changes = true;
a.unTag ("MODIFICATION"); a.unTag ("MODIFICATION");
a.tag ("FILTER"); a.tag ("FILTER");
_uuid_list.push_back (a.attribute ("raw")); _uuid_list.push_back (a.attribute ("raw"));
} }
} }
} }
}
if (_uuid_list.size ()) // Sugar-free.
else
{
std::vector <A2> reconstructed;
for (auto& a : _args)
{
if (a.hasTag ("FILTER") &&
a._lextype == Lexer::Type::uuid)
{
changes = true;
A2 pair ("uuid:" + a.attribute ("raw"), Lexer::Type::pair);
pair.tag ("FILTER");
pair.decompose ();
reconstructed.push_back (pair);
}
else
reconstructed.push_back (a);
}
if (changes)
_args = reconstructed;
}
if (changes)
if (context.config.getInteger ("debug.parser") >= 3) if (context.config.getInteger ("debug.parser") >= 3)
context.debug (dump ("CLI2::prepareFilter findUUIDs")); context.debug (dump ("CLI2::prepareFilter findUUIDs"));
} }

View file

@ -47,8 +47,6 @@ public:
const std::string attribute (const std::string&) const; const std::string attribute (const std::string&) const;
const std::string getToken () const; const std::string getToken () const;
const std::string dump () const; const std::string dump () const;
private:
void decompose (); void decompose ();
public: public:

View file

@ -342,6 +342,7 @@ std::string Config::_defaults =
"list.all.tags=no # Include old tag names in 'tags' command\n" "list.all.tags=no # Include old tag names in 'tags' command\n"
"print.empty.columns=no # Print columns which have no data for any task\n" "print.empty.columns=no # Print columns which have no data for any task\n"
"debug=no # Display diagnostics\n" "debug=no # Display diagnostics\n"
"sugar=yes # Syntactic sugar\n"
"obfuscate=no # Obfuscate data for error reporting\n" "obfuscate=no # Obfuscate data for error reporting\n"
"fontunderline=yes # Uses underlines rather than -------\n" "fontunderline=yes # Uses underlines rather than -------\n"
"shell.prompt=task> # Prompt used by the shell command\n" "shell.prompt=task> # Prompt used by the shell command\n"

View file

@ -186,6 +186,7 @@ int CmdShow::execute (std::string& output)
" rule.precedence.color" " rule.precedence.color"
" search.case.sensitive" " search.case.sensitive"
" shell.prompt" " shell.prompt"
" sugar"
" summary.all.projects" " summary.all.projects"
" tag.indicator" " tag.indicator"
" taskd.server" " taskd.server"