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

View file

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

View file

@ -60,20 +60,17 @@ bool Expression::evalFilter (const Task& task)
if (!_prepared)
{
if (_args.size ())
{
_args.dump ("Expression::evalFilter");
_args.dump ("Expression::evalFilter");
expand_sequence ();
implicit_and ();
expand_tag ();
expand_pattern ();
expand_attr ();
expand_attmod ();
expand_word ();
expand_tokens ();
postfix ();
}
expand_sequence ();
implicit_and ();
expand_tag ();
expand_pattern ();
expand_attr ();
expand_attmod ();
expand_word ();
expand_tokens ();
postfix ();
_prepared = true;
}
@ -96,20 +93,17 @@ std::string Expression::evalExpression (const Task& task)
if (!_prepared)
{
if (_args.size ())
{
_args.dump ("Expression::evalFilter");
_args.dump ("Expression::evalExpression");
expand_sequence ();
implicit_and ();
expand_tag ();
expand_pattern ();
expand_attr ();
expand_attmod ();
expand_word ();
expand_tokens ();
postfix ();
}
expand_sequence ();
implicit_and ();
expand_tag ();
expand_pattern ();
expand_attr ();
expand_attmod ();
expand_word ();
expand_tokens ();
postfix ();
_prepared = true;
}
@ -558,7 +552,7 @@ void Expression::expand_sequence ()
}
// 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.
bool found_id = false;
@ -588,8 +582,7 @@ void Expression::expand_tokens ()
std::vector <Triple>::iterator arg;
for (arg = _args.begin (); arg != _args.end (); ++arg)
{
if (arg->_third == "seq" ||
arg->_third == "exp")
if (arg->_second == "exp")
{
tokenize (arg->_first, arg->_third, operators, temp);
delta = true;

View file

@ -54,13 +54,13 @@ void TF2::target (const std::string& f)
_file = File (f);
_read_only = ! _file.writable ();
std::cout << "# TF2::target " << f << "\n";
// std::cout << "# TF2::target " << f << "\n";
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TF2::get_tasks ()
{
std::cout << "# TF2::get_tasks\n";
// std::cout << "# TF2::get_tasks\n";
if (! _loaded_tasks)
load_tasks ();
@ -71,7 +71,7 @@ const std::vector <Task>& TF2::get_tasks ()
////////////////////////////////////////////////////////////////////////////////
const std::vector <std::string>& TF2::get_lines ()
{
std::cout << "# TF2::get_lines\n";
// std::cout << "# TF2::get_lines\n";
if (! _loaded_lines)
load_lines ();
@ -82,7 +82,7 @@ const std::vector <std::string>& TF2::get_lines ()
////////////////////////////////////////////////////////////////////////////////
const std::string& TF2::get_contents ()
{
std::cout << "# TF2::get_contents\n";
// std::cout << "# TF2::get_contents\n";
if (! _loaded_contents)
load_contents ();
@ -93,7 +93,7 @@ const std::string& TF2::get_contents ()
////////////////////////////////////////////////////////////////////////////////
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
_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)
{
std::cout << "# TF2::modify_task\n";
// std::cout << "# TF2::modify_task\n";
// Modify in-place.
std::vector <Task>::iterator i;
@ -123,7 +123,7 @@ void TF2::modify_task (const Task& task)
////////////////////////////////////////////////////////////////////////////////
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);
_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.
void TF2::clear_lines ()
{
std::cout << "# TF2::clear_lines\n";
// std::cout << "# TF2::clear_lines\n";
_lines.clear ();
_dirty = true;
}
@ -142,7 +142,7 @@ void TF2::clear_lines ()
// Top-down recomposition.
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.
if (_dirty)
@ -239,7 +239,7 @@ void TF2::commit ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_tasks ()
{
std::cout << "# TF2::load_tasks\n";
// std::cout << "# TF2::load_tasks\n";
if (! _loaded_lines)
load_lines ();
@ -274,7 +274,7 @@ void TF2::load_tasks ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_lines ()
{
std::cout << "# TF2::load_lines\n";
// std::cout << "# TF2::load_lines\n";
if (! _loaded_contents)
load_contents ();
@ -286,7 +286,7 @@ void TF2::load_lines ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_contents ()
{
std::cout << "# TF2::load_contents\n";
// std::cout << "# TF2::load_contents\n";
_contents = "";
@ -330,7 +330,7 @@ TDB2::~TDB2 ()
// read.
void TDB2::set_location (const std::string& location)
{
std::cout << "# TDB2::set_location " << location << "\n";
// std::cout << "# TDB2::set_location " << location << "\n";
_location = location;
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.
void TDB2::add (const Task& task)
{
std::cout << "# TDB2::add\n";
// std::cout << "# TDB2::add\n";
std::string status = task.get ("status");
if (status == "completed" ||
@ -359,7 +359,7 @@ void TDB2::add (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");
if (status == "completed" ||
@ -375,7 +375,7 @@ void TDB2::modify (const Task& task)
void TDB2::commit ()
{
dump ();
std::cout << "# TDB2::commit\n";
// std::cout << "# TDB2::commit\n";
pending.commit ();
completed.commit ();
undo.commit ();
@ -391,7 +391,7 @@ void TDB2::commit ()
// Now cleans up dangling dependencies.
int TDB2::gc ()
{
std::cout << "# TDB2::gc\n";
// std::cout << "# TDB2::gc\n";
/*
pending.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)
{
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)
{
Timer timer ("Command::filter");
@ -300,7 +302,6 @@ void Command::filter (std::vector <Task>& output)
if (f.size ())
{
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
Expression e (f);
output.clear ();