Expressions

- Attribute values are now run through the expression evaluator.  This
  is good.  The evaluator fails.  This is bad, but progress has been
  made.
This commit is contained in:
Paul Beckingham
2011-07-17 15:33:09 -04:00
parent ddbf9d374e
commit dd75c1af1e
2 changed files with 36 additions and 24 deletions

View File

@@ -95,13 +95,13 @@ std::string Expression::evalExpression (const Task& task)
{
_args.dump ("Expression::evalExpression");
expand_sequence ();
implicit_and ();
expand_tag ();
expand_pattern ();
expand_attr ();
expand_attmod ();
expand_word ();
// expand_sequence ();
// implicit_and ();
// expand_tag ();
// expand_pattern ();
// expand_attr ();
// expand_attmod ();
// expand_word ();
expand_tokens ();
postfix ();
@@ -786,10 +786,11 @@ void Expression::expand_attr ()
// Canonicalize 'name'.
Arguments::is_attribute (name, name);
/*
// Always quote the value, so that empty values, or values containing spaces
// are preserved.
value = "\"" + value + "\"";
*/
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("=", "op", arg->_third));
temp.push_back (Triple (value, "exp", arg->_third));
@@ -833,10 +834,12 @@ void Expression::expand_attmod ()
Arguments::is_attribute (name, name);
Arguments::is_modifier (mod);
/*
// Always quote the value, so that empty values, or values containing spaces
// are preserved.
std::string raw_value = value;
value = "\"" + value + "\"";
*/
if (mod == "before" || mod == "under" || mod == "below")
{
@@ -888,27 +891,31 @@ void Expression::expand_attmod ()
}
else if (mod == "startswith" || mod == "left")
{
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
temp.push_back (Triple ("^" + raw_value, "rx", arg->_third));
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
// temp.push_back (Triple ("^" + raw_value, "rx", arg->_third));
temp.push_back (Triple ("^" + value, "rx", arg->_third));
}
else if (mod == "endswith" || mod == "right")
{
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
temp.push_back (Triple (raw_value + "$", "rx", arg->_third));
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
// temp.push_back (Triple (raw_value + "$", "rx", arg->_third));
temp.push_back (Triple (value + "$", "rx", arg->_third));
}
else if (mod == "word")
{
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
temp.push_back (Triple ("\\b" + raw_value + "\\b", "rx", arg->_third));
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("~", "op", arg->_third));
// temp.push_back (Triple ("\\b" + raw_value + "\\b", "rx", arg->_third));
temp.push_back (Triple ("\\b" + value + "\\b", "rx", arg->_third));
}
else if (mod == "noword")
{
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("!~", "op", arg->_third));
temp.push_back (Triple ("\\b" + raw_value + "\\b", "rx", arg->_third));
temp.push_back (Triple (name, "lvalue", arg->_third));
temp.push_back (Triple ("!~", "op", arg->_third));
// temp.push_back (Triple ("\\b" + raw_value + "\\b", "rx", arg->_third));
temp.push_back (Triple ("\\b" + value + "\\b", "rx", arg->_third));
}
else
throw std::string ("Error: unrecognized attribute modifier '") + mod + "'.";

View File

@@ -417,16 +417,21 @@ void Command::modify_task (
std::string name;
std::string value;
Arguments::extract_attr (arg->_first, name, value);
if (Arguments::is_attribute (name, name))
if (Arguments::is_attribute (name, name)) // Canonicalize
{
// TODO All 'value's must be eval'd first.
// All values must be eval'd first.
Arguments fragment;
fragment.push_back (Triple (value, "exp", "attr"));
Expression e (fragment);
std::string result = e.evalExpression (task);
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
// Dependencies must be resolved to UUIDs.
if (name == "depends")
{
// Convert ID to UUID.
std::vector <std::string> deps;
split (deps, value, ',');
split (deps, result, ',');
// Apply or remove dendencies in turn.
std::vector <std::string>::iterator i;
@@ -442,7 +447,7 @@ void Command::modify_task (
// By default, just add it.
else
task.set (name, value);
task.set (name, result);
}
else
throw format (STRING_CMD_ADD_BAD_ATTRIBUTE, name);