Expressions

- Commented out troublesome "distance_from_command" code.
- Commented out DOM diagnostics, for now.
- Commented out TDB2 diagnostics, for now.
- Category "seq" arguments are now assigned type "exp".
- All type "exp" arguments are now tokenized.
This commit is contained in:
Paul Beckingham 2011-07-17 13:52:55 -04:00
parent f0a9796683
commit 137b00a14a
5 changed files with 63 additions and 69 deletions

View file

@ -288,7 +288,7 @@ void Arguments::categorize ()
// Track where the command is, if possible. // Track where the command is, if possible.
int command_pos = -1; int command_pos = -1;
int distance_from_command = 0; // int distance_from_command = 0;
// Configurable support. // Configurable support.
bool enable_expressions = context.config.getBoolean ("expressions"); bool enable_expressions = context.config.getBoolean ("expressions");
@ -367,8 +367,8 @@ void Arguments::categorize ()
// <id>[-<id>][,...] // <id>[-<id>][,...]
else if (is_id (arg->_first)) else if (is_id (arg->_first))
{ {
if (found_something_after_sequence || if (found_something_after_sequence/* ||
(command_pos != -1 && distance_from_command > 0)) (command_pos != -1 && distance_from_command > 0)*/)
{ {
arg->_third = "word"; arg->_third = "word";
} }
@ -382,8 +382,8 @@ void Arguments::categorize ()
// <uuid>[,...] // <uuid>[,...]
else if (is_uuid (arg->_first)) else if (is_uuid (arg->_first))
{ {
if (found_something_after_sequence || if (found_something_after_sequence/* ||
(command_pos != -1 && distance_from_command > 0)) (command_pos != -1 && distance_from_command > 0)*/)
{ {
arg->_third = "word"; arg->_third = "word";
} }
@ -401,8 +401,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "tag"; arg->_third = "tag";
} }
@ -414,8 +414,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "attmod"; arg->_third = "attmod";
} }
@ -427,8 +427,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "attr"; arg->_third = "attr";
} }
@ -440,8 +440,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "subst"; arg->_third = "subst";
} }
@ -453,8 +453,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "pattern"; arg->_third = "pattern";
} }
@ -466,8 +466,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "op"; arg->_third = "op";
} }
@ -479,8 +479,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_second = "exp"; arg->_second = "exp";
arg->_third = "exp"; arg->_third = "exp";
@ -493,8 +493,8 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
if (command_pos != -1) // if (command_pos != -1)
++distance_from_command; // ++distance_from_command;
arg->_third = "word"; arg->_third = "word";
} }

View file

@ -309,7 +309,7 @@ bool DOM::is_primitive (const std::string& input)
if (n.getInt (i) && n.depleted ()) if (n.getInt (i) && n.depleted ())
return true; return true;
std::cout << "# DOM::is_primitive '" << input << "' --> unknown\n"; // std::cout << "# DOM::is_primitive '" << input << "' --> unknown\n";
return false; return false;
} }

View file

@ -59,8 +59,6 @@ bool Expression::evalFilter (const Task& task)
return true; return true;
if (!_prepared) if (!_prepared)
{
if (_args.size ())
{ {
_args.dump ("Expression::evalFilter"); _args.dump ("Expression::evalFilter");
@ -73,7 +71,6 @@ bool Expression::evalFilter (const Task& task)
expand_word (); expand_word ();
expand_tokens (); expand_tokens ();
postfix (); postfix ();
}
_prepared = true; _prepared = true;
} }
@ -96,9 +93,7 @@ std::string Expression::evalExpression (const Task& task)
if (!_prepared) if (!_prepared)
{ {
if (_args.size ()) _args.dump ("Expression::evalExpression");
{
_args.dump ("Expression::evalFilter");
expand_sequence (); expand_sequence ();
implicit_and (); implicit_and ();
@ -109,7 +104,6 @@ std::string Expression::evalExpression (const Task& task)
expand_word (); expand_word ();
expand_tokens (); expand_tokens ();
postfix (); postfix ();
}
_prepared = true; _prepared = true;
} }
@ -558,7 +552,7 @@ void Expression::expand_sequence ()
} }
// Now insert the new sequence expression. // Now insert the new sequence expression.
temp.push_back (Triple (sequence.str (), "", "seq")); temp.push_back (Triple (sequence.str (), "exp", "seq"));
// Now copy everything after the last id/uuid. // Now copy everything after the last id/uuid.
bool found_id = false; bool found_id = false;
@ -588,8 +582,7 @@ void Expression::expand_tokens ()
std::vector <Triple>::iterator arg; std::vector <Triple>::iterator arg;
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
{ {
if (arg->_third == "seq" || if (arg->_second == "exp")
arg->_third == "exp")
{ {
tokenize (arg->_first, arg->_third, operators, temp); tokenize (arg->_first, arg->_third, operators, temp);
delta = true; delta = true;

View file

@ -54,13 +54,13 @@ void TF2::target (const std::string& f)
_file = File (f); _file = File (f);
_read_only = ! _file.writable (); _read_only = ! _file.writable ();
std::cout << "# TF2::target " << f << "\n"; // std::cout << "# TF2::target " << f << "\n";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TF2::get_tasks () const std::vector <Task>& TF2::get_tasks ()
{ {
std::cout << "# TF2::get_tasks\n"; // std::cout << "# TF2::get_tasks\n";
if (! _loaded_tasks) if (! _loaded_tasks)
load_tasks (); load_tasks ();
@ -71,7 +71,7 @@ const std::vector <Task>& TF2::get_tasks ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::vector <std::string>& TF2::get_lines () const std::vector <std::string>& TF2::get_lines ()
{ {
std::cout << "# TF2::get_lines\n"; // std::cout << "# TF2::get_lines\n";
if (! _loaded_lines) if (! _loaded_lines)
load_lines (); load_lines ();
@ -82,7 +82,7 @@ const std::vector <std::string>& TF2::get_lines ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::string& TF2::get_contents () const std::string& TF2::get_contents ()
{ {
std::cout << "# TF2::get_contents\n"; // std::cout << "# TF2::get_contents\n";
if (! _loaded_contents) if (! _loaded_contents)
load_contents (); load_contents ();
@ -93,7 +93,7 @@ const std::string& TF2::get_contents ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::add_task (const Task& task) void TF2::add_task (const Task& task)
{ {
std::cout << "# TF2::add_task\n"; // std::cout << "# TF2::add_task\n";
_tasks.push_back (task); // For subsequent queries _tasks.push_back (task); // For subsequent queries
_added_tasks.push_back (task); // For commit/synch _added_tasks.push_back (task); // For commit/synch
@ -103,7 +103,7 @@ void TF2::add_task (const Task& task)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::modify_task (const Task& task) void TF2::modify_task (const Task& task)
{ {
std::cout << "# TF2::modify_task\n"; // std::cout << "# TF2::modify_task\n";
// Modify in-place. // Modify in-place.
std::vector <Task>::iterator i; std::vector <Task>::iterator i;
@ -123,7 +123,7 @@ void TF2::modify_task (const Task& task)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::add_line (const std::string& line) void TF2::add_line (const std::string& line)
{ {
std::cout << "# TF2::add_line\n"; // std::cout << "# TF2::add_line\n";
_added_lines.push_back (line); _added_lines.push_back (line);
_dirty = true; _dirty = true;
@ -133,7 +133,7 @@ void TF2::add_line (const std::string& line)
// This is so that synch.key can just overwrite and not grow. // This is so that synch.key can just overwrite and not grow.
void TF2::clear_lines () void TF2::clear_lines ()
{ {
std::cout << "# TF2::clear_lines\n"; // std::cout << "# TF2::clear_lines\n";
_lines.clear (); _lines.clear ();
_dirty = true; _dirty = true;
} }
@ -142,7 +142,7 @@ void TF2::clear_lines ()
// Top-down recomposition. // Top-down recomposition.
void TF2::commit () void TF2::commit ()
{ {
std::cout << "# TF2::commit " << _file.data << "\n"; // std::cout << "# TF2::commit " << _file.data << "\n";
// The _dirty flag indicates that the file needs to be written. // The _dirty flag indicates that the file needs to be written.
if (_dirty) if (_dirty)
@ -239,7 +239,7 @@ void TF2::commit ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::load_tasks () void TF2::load_tasks ()
{ {
std::cout << "# TF2::load_tasks\n"; // std::cout << "# TF2::load_tasks\n";
if (! _loaded_lines) if (! _loaded_lines)
load_lines (); load_lines ();
@ -274,7 +274,7 @@ void TF2::load_tasks ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::load_lines () void TF2::load_lines ()
{ {
std::cout << "# TF2::load_lines\n"; // std::cout << "# TF2::load_lines\n";
if (! _loaded_contents) if (! _loaded_contents)
load_contents (); load_contents ();
@ -286,7 +286,7 @@ void TF2::load_lines ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::load_contents () void TF2::load_contents ()
{ {
std::cout << "# TF2::load_contents\n"; // std::cout << "# TF2::load_contents\n";
_contents = ""; _contents = "";
@ -330,7 +330,7 @@ TDB2::~TDB2 ()
// read. // read.
void TDB2::set_location (const std::string& location) void TDB2::set_location (const std::string& location)
{ {
std::cout << "# TDB2::set_location " << location << "\n"; // std::cout << "# TDB2::set_location " << location << "\n";
_location = location; _location = location;
pending.target (location + "/pending.data"); pending.target (location + "/pending.data");
@ -344,7 +344,7 @@ void TDB2::set_location (const std::string& location)
// Add the new task to the appropriate file. // Add the new task to the appropriate file.
void TDB2::add (const Task& task) void TDB2::add (const Task& task)
{ {
std::cout << "# TDB2::add\n"; // std::cout << "# TDB2::add\n";
std::string status = task.get ("status"); std::string status = task.get ("status");
if (status == "completed" || if (status == "completed" ||
@ -359,7 +359,7 @@ void TDB2::add (const Task& task)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TDB2::modify (const Task& task) void TDB2::modify (const Task& task)
{ {
std::cout << "# TDB2::modify\n"; // std::cout << "# TDB2::modify\n";
std::string status = task.get ("status"); std::string status = task.get ("status");
if (status == "completed" || if (status == "completed" ||
@ -375,7 +375,7 @@ void TDB2::modify (const Task& task)
void TDB2::commit () void TDB2::commit ()
{ {
dump (); dump ();
std::cout << "# TDB2::commit\n"; // std::cout << "# TDB2::commit\n";
pending.commit (); pending.commit ();
completed.commit (); completed.commit ();
undo.commit (); undo.commit ();
@ -391,7 +391,7 @@ void TDB2::commit ()
// Now cleans up dangling dependencies. // Now cleans up dangling dependencies.
int TDB2::gc () int TDB2::gc ()
{ {
std::cout << "# TDB2::gc\n"; // std::cout << "# TDB2::gc\n";
/* /*
pending.load_tasks pending.load_tasks
completed.load_tasks completed.load_tasks

View file

@ -263,6 +263,7 @@ bool Command::displays_id () const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Filter a specific list of tasks.
void Command::filter (std::vector <Task>& input, std::vector <Task>& output) void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
{ {
Timer timer ("Command::filter"); Timer timer ("Command::filter");
@ -287,6 +288,7 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Filter all tasks.
void Command::filter (std::vector <Task>& output) void Command::filter (std::vector <Task>& output)
{ {
Timer timer ("Command::filter"); Timer timer ("Command::filter");
@ -300,7 +302,6 @@ void Command::filter (std::vector <Task>& output)
if (f.size ()) if (f.size ())
{ {
const std::vector <Task>& pending = context.tdb2.pending.get_tasks (); const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
Expression e (f); Expression e (f);
output.clear (); output.clear ();