Expressions

- Implemented Command::next_mod_group, which walks the A3 list looking for
  consecutive grouped args for modification purposes.
This commit is contained in:
Paul Beckingham 2011-09-11 00:49:56 -04:00
parent c7464a59b3
commit e31e80961a
2 changed files with 39 additions and 21 deletions

View file

@ -412,18 +412,17 @@ void Command::modify_task (
std::string& description) std::string& description)
{ {
// Coalesce arguments together into sets to be processed as a batch. // Coalesce arguments together into sets to be processed as a batch.
A3 grouped_arguments = group_arguments (arguments); unsigned int pos = 0;
Arg arg;
std::vector <Arg>::const_iterator arg; while (next_mod_group (arguments, arg, pos))
for (arg = grouped_arguments.begin (); arg != grouped_arguments.end (); ++arg)
{ {
// Attributes are essentially name:value pairs, and correspond directly // Attributes are essentially name:value pairs, and correspond directly
// to stored attributes. // to stored attributes.
if (arg->_category == Arg::cat_attr) if (arg._category == Arg::cat_attr)
{ {
std::string name; std::string name;
std::string value; std::string value;
A3::extract_attr (arg->_raw, name, value); A3::extract_attr (arg._raw, name, value);
if (A3::is_attribute (name, name)) // Canonicalize if (A3::is_attribute (name, name)) // Canonicalize
{ {
// std::cout << "# Command::modify_task name='" << name << "' value='" << value << "'\n"; // std::cout << "# Command::modify_task name='" << name << "' value='" << value << "'\n";
@ -434,7 +433,8 @@ void Command::modify_task (
// All values must be eval'd first. // All values must be eval'd first.
A3 fragment; A3 fragment;
fragment.capture (value); fragment.capture (value);
fragment = fragment.tokenize (fragment); fragment = fragment.postfix (fragment.tokenize (fragment));
E9 e (fragment); E9 e (fragment);
std::string result = e.evalExpression (task); std::string result = e.evalExpression (task);
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'"); context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
@ -489,11 +489,11 @@ void Command::modify_task (
// Tags need special handling because they are essentially a vector stored // Tags need special handling because they are essentially a vector stored
// in a single string, therefore Task::{add,remove}Tag must be called as // in a single string, therefore Task::{add,remove}Tag must be called as
// appropriate. // appropriate.
else if (arg->_category == Arg::cat_tag) else if (arg._category == Arg::cat_tag)
{ {
char type; char type;
std::string value; std::string value;
A3::extract_tag (arg->_raw, type, value); A3::extract_tag (arg._raw, type, value);
if (type == '+') if (type == '+')
task.addTag (value); task.addTag (value);
@ -502,12 +502,12 @@ void Command::modify_task (
} }
// Substitutions. // Substitutions.
else if (arg->_category == Arg::cat_subst) else if (arg._category == Arg::cat_subst)
{ {
std::string from; std::string from;
std::string to; std::string to;
bool global; bool global;
A3::extract_subst (arg->_raw, from, to, global); A3::extract_subst (arg._raw, from, to, global);
task.substitute (from, to, global); task.substitute (from, to, global);
} }
@ -518,7 +518,7 @@ void Command::modify_task (
if (description.length ()) if (description.length ())
description += " "; description += " ";
description += arg->_raw; description += arg._raw;
} }
} }
} }
@ -544,19 +544,37 @@ void Command::safety ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
A3 Command::group_arguments (const A3& input) // Special processing for modifications.
bool Command::next_mod_group (const A3& input, Arg& arg, unsigned int& pos)
{ {
A3 result; if (pos < input.size ())
std::vector <Arg>::const_iterator arg;
for (arg = input.begin (); arg != input.end (); ++arg)
{ {
// TODO Create a grouped set of args. arg = input[pos++];
result.push_back (*arg); // Date attributes aggregate durations and operators.
if (arg._type == Arg::type_date &&
arg._category == Arg::cat_attr)
{
while (input[pos]._type == Arg::type_duration ||
input[pos]._category == Arg::cat_op)
{
arg._raw += " " + input[pos++]._raw;
}
} }
return result; else if (arg._raw == "depends")
{
while (input[pos]._category == Arg::cat_op ||
input[pos]._type == Arg::type_number)
{
arg._raw += input[pos++]._raw;
}
}
return true;
}
return false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -65,7 +65,7 @@ protected:
void safety (); void safety ();
A3 group_arguments (const A3&); bool next_mod_group (const A3&, Arg&, unsigned int&);
protected: protected:
std::string _keyword; std::string _keyword;