Expressions/Arguments

- Converted the arguments parsed from a pair (token/modified-category)
  to a triple (token/type/category)
This commit is contained in:
Paul Beckingham 2011-07-02 11:47:39 -04:00
parent e1aea08f81
commit 42becb9e41
6 changed files with 327 additions and 278 deletions

View file

@ -158,10 +158,10 @@ void Arguments::capture (int argc, const char** argv)
{ {
std::vector <std::string>::iterator part; std::vector <std::string>::iterator part;
for (part = parts.begin (); part != parts.end (); ++part) for (part = parts.begin (); part != parts.end (); ++part)
this->push_back (std::make_pair (*part, "")); this->push_back (Triple (*part, "?", ""));
} }
else else
this->push_back (std::make_pair (argv[i], "")); this->push_back (Triple (argv[i], "?", ""));
} }
categorize (); categorize ();
@ -176,10 +176,10 @@ void Arguments::capture (const std::string& arg)
{ {
std::vector <std::string>::iterator part; std::vector <std::string>::iterator part;
for (part = parts.begin (); part != parts.end (); ++part) for (part = parts.begin (); part != parts.end (); ++part)
this->push_back (std::make_pair (*part, "")); this->push_back (Triple (*part, "?", ""));
} }
else else
this->push_back (std::make_pair (arg, "")); this->push_back (Triple (arg, "?", ""));
categorize (); categorize ();
} }
@ -189,24 +189,24 @@ void Arguments::capture (const std::string& arg)
void Arguments::capture_first (const std::string& arg) void Arguments::capture_first (const std::string& arg)
{ {
// Break the new argument into parts that comprise a series. // Break the new argument into parts that comprise a series.
std::vector <std::pair <std::string, std::string> > series; std::vector <Triple> series;
std::vector <std::string> parts; std::vector <std::string> parts;
if (is_multipart (arg, parts)) if (is_multipart (arg, parts))
{ {
std::vector <std::string>::iterator part; std::vector <std::string>::iterator part;
for (part = parts.begin (); part != parts.end (); ++part) for (part = parts.begin (); part != parts.end (); ++part)
series.push_back (std::make_pair (*part, "")); series.push_back (Triple (*part, "?", ""));
} }
else else
series.push_back (std::make_pair (arg, "")); series.push_back (Triple (arg, "?", ""));
// Locate an appropriate place to insert the series. This would be // Locate an appropriate place to insert the series. This would be
// immediately after the program and command arguments. // immediately after the program and command arguments.
std::vector <std::pair <std::string, std::string> >::iterator position; std::vector <Triple>::iterator position;
for (position = this->begin (); position != this->end (); ++position) for (position = this->begin (); position != this->end (); ++position)
if (position->second != "program" && if (position->_third != "program" &&
position->second != "command") position->_third != "command")
break; break;
this->insert (position, series.begin (), series.end ()); this->insert (position, series.begin (), series.end ());
@ -238,7 +238,7 @@ void Arguments::append_stdin ()
if (arg == "--") if (arg == "--")
break; break;
this->push_back (std::make_pair (arg, "")); this->push_back (Triple (arg, "?", ""));
something_happened = true; something_happened = true;
} }
} }
@ -269,150 +269,150 @@ void Arguments::categorize ()
// Now categorize every argument. // Now categorize every argument.
std::string ignored; std::string ignored;
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (!terminated) if (!terminated)
{ {
// Nothing after -- is to be interpreted in any way. // Nothing after -- is to be interpreted in any way.
if (arg->first == "--") if (arg->_first == "--")
{ {
terminated = true; terminated = true;
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "terminator"; arg->_third = "terminator";
} }
// program // program
else if (arg == this->begin ()) else if (arg == this->begin ())
{ {
arg->second = "program"; // TODO Is this a problem for expressions that do not contain a program name? arg->_third = "program"; // TODO Is this a problem for expressions that do not contain a program name?
} }
// command // command
else if (!found_command && else if (!found_command &&
is_command (keywords, arg->first)) is_command (keywords, arg->_first))
{ {
found_command = true; found_command = true;
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "command"; arg->_third = "command";
} }
// rc:<file> // rc:<file>
// Note: This doesn't break a sequence chain. // Note: This doesn't break a sequence chain.
else if (arg->first.substr (0, 3) == "rc:") else if (arg->_first.substr (0, 3) == "rc:")
{ {
arg->second = "rc"; arg->_third = "rc";
} }
// rc.<name>:<value> // rc.<name>:<value>
// Note: This doesn't break a sequence chain. // Note: This doesn't break a sequence chain.
else if (arg->first.substr (0, 3) == "rc.") else if (arg->_first.substr (0, 3) == "rc.")
{ {
arg->second = "override"; arg->_third = "override";
} }
// <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)
{ {
found_sequence = true; found_sequence = true;
arg->second = "id"; arg->_third = "id";
} }
else else
{ {
arg->second = "word"; arg->_third = "word";
} }
} }
// <uuid>[,...] // <uuid>[,...]
else if (is_uuid (arg->first)) else if (is_uuid (arg->_first))
{ {
if (!found_something_after_sequence) if (!found_something_after_sequence)
{ {
found_sequence = true; found_sequence = true;
arg->second = "uuid"; arg->_third = "uuid";
} }
else else
{ {
arg->second = "word"; arg->_third = "word";
} }
} }
// [+-]tag // [+-]tag
else if (is_tag (arg->first)) else if (is_tag (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "tag"; arg->_third = "tag";
} }
// <name>.<modifier>:<value> // <name>.<modifier>:<value>
else if (is_attmod (arg->first)) else if (is_attmod (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "attmod"; arg->_third = "attmod";
} }
// <name>:<value> // <name>:<value>
else if (is_attr (arg->first)) else if (is_attr (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "attr"; arg->_third = "attr";
} }
// /<from>/<to>/[g] // /<from>/<to>/[g]
else if (is_subst (arg->first)) else if (is_subst (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "subst"; arg->_third = "subst";
} }
// /pattern/ // /pattern/
else if (enable_patterns && is_pattern (arg->first)) else if (enable_patterns && is_pattern (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "pattern"; arg->_third = "pattern";
} }
// <operator> // <operator>
else if (is_operator (arg->first)) else if (is_operator (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "op"; arg->_third = "op";
} }
// <expression> // <expression>
else if (enable_expressions && is_expression (arg->first)) else if (enable_expressions && is_expression (arg->_first))
{ {
found_non_sequence = true; found_non_sequence = true;
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "exp"; arg->_third = "exp";
} }
// If the type is not known, it is treated as a generic word. // If the type is not known, it is treated as a generic word.
@ -422,7 +422,7 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "word"; arg->_third = "word";
} }
} }
@ -433,7 +433,7 @@ void Arguments::categorize ()
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
arg->second = "word"; arg->_third = "word";
} }
} }
} }
@ -444,12 +444,12 @@ void Arguments::rc_override (
File& rc) File& rc)
{ {
// Is there an override for rc:<file>? // Is there an override for rc:<file>?
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (arg->second == "rc") if (arg->_third == "rc")
{ {
rc = File (arg->first.substr (3)); rc = File (arg->_first.substr (3));
home = rc; home = rc;
std::string::size_type last_slash = rc.data.rfind ("/"); std::string::size_type last_slash = rc.data.rfind ("/");
@ -474,15 +474,15 @@ void Arguments::get_data_location (std::string& data)
data = location; data = location;
// Are there any overrides for data.location? // Are there any overrides for data.location?
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (arg->second == "override") if (arg->_third == "override")
{ {
if (arg->first.substr (0, 16) == "rc.data.location" && if (arg->_first.substr (0, 16) == "rc.data.location" &&
arg->first[16] == ':') arg->_first[16] == ':')
{ {
data = arg->first.substr (17); data = arg->_first.substr (17);
context.header ("Using alternate data.location " + data); context.header ("Using alternate data.location " + data);
} }
} }
@ -497,14 +497,14 @@ void Arguments::get_data_location (std::string& data)
// leaving only the plain args. // leaving only the plain args.
void Arguments::apply_overrides () void Arguments::apply_overrides ()
{ {
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (arg->second == "override") if (arg->_third == "override")
{ {
std::string name; std::string name;
std::string value; std::string value;
Nibbler n (arg->first); Nibbler n (arg->_first);
if (n.getLiteral ("rc.") && // rc. if (n.getLiteral ("rc.") && // rc.
n.getUntil (':', name) && // xxx n.getUntil (':', name) && // xxx
n.skip (':')) // : n.skip (':')) // :
@ -515,7 +515,7 @@ void Arguments::apply_overrides ()
context.footnote ("Configuration override rc." + name + ":" + value); context.footnote ("Configuration override rc." + name + ":" + value);
} }
else else
context.footnote ("Problem with override: " + arg->first); context.footnote ("Problem with override: " + arg->_first);
} }
} }
} }
@ -528,22 +528,22 @@ void Arguments::resolve_aliases ()
std::vector <std::string> expanded; std::vector <std::string> expanded;
bool something = false; bool something = false;
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
std::map <std::string, std::string>::iterator match = std::map <std::string, std::string>::iterator match =
context.aliases.find (arg->first); context.aliases.find (arg->_first);
if (match != context.aliases.end ()) if (match != context.aliases.end ())
{ {
context.debug (std::string ("Arguments::resolve_aliases '") context.debug (std::string ("Arguments::resolve_aliases '")
+ arg->first + arg->_first
+ "' --> '" + "' --> '"
+ context.aliases[arg->first] + context.aliases[arg->_first]
+ "'"); + "'");
std::vector <std::string> words; std::vector <std::string> words;
splitq (words, context.aliases[arg->first], ' '); splitq (words, context.aliases[arg->_first], ' ');
std::vector <std::string>::iterator word; std::vector <std::string>::iterator word;
for (word = words.begin (); word != words.end (); ++word) for (word = words.begin (); word != words.end (); ++word)
@ -552,7 +552,7 @@ void Arguments::resolve_aliases ()
something = true; something = true;
} }
else else
expanded.push_back (arg->first); expanded.push_back (arg->_first);
} }
// Only overwrite if something happened. // Only overwrite if something happened.
@ -561,7 +561,7 @@ void Arguments::resolve_aliases ()
this->clear (); this->clear ();
std::vector <std::string>::iterator e; std::vector <std::string>::iterator e;
for (e = expanded.begin (); e != expanded.end (); ++e) for (e = expanded.begin (); e != expanded.end (); ++e)
this->push_back (std::make_pair (*e, "")); this->push_back (Triple (*e, "?", ""));
categorize (); categorize ();
} }
@ -574,18 +574,18 @@ void Arguments::inject_defaults ()
bool found_sequence = false; bool found_sequence = false;
bool found_other = false; bool found_other = false;
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (arg->second == "command") if (arg->_third == "command")
found_command = true; found_command = true;
else if (arg->second == "id") else if (arg->_third == "id")
found_sequence = true; found_sequence = true;
else if (arg->second != "program" && else if (arg->_third != "program" &&
arg->second != "override" && arg->_third != "override" &&
arg->second != "rc") arg->_third != "rc")
found_other = true; found_other = true;
} }
@ -611,7 +611,7 @@ void Arguments::inject_defaults ()
else if (found_sequence) else if (found_sequence)
{ {
context.header (STRING_ASSUME_INFO); context.header (STRING_ASSUME_INFO);
push_back (std::make_pair ("information", "command")); push_back (Triple ("information", "?", "command"));
} }
} }
} }
@ -620,9 +620,9 @@ void Arguments::inject_defaults ()
std::vector <std::string> Arguments::list () std::vector <std::string> Arguments::list ()
{ {
std::vector <std::string> all; std::vector <std::string> all;
std::vector <std::pair <std::string, std::string> >::iterator i; std::vector <Triple>::iterator arg;
for (i = this->begin (); i != this->end (); ++i) for (arg = this->begin (); arg != this->end (); ++arg)
all.push_back (i->first); all.push_back (arg->_first);
return all; return all;
} }
@ -642,13 +642,13 @@ std::string Arguments::combine ()
{ {
std::string combined; std::string combined;
std::vector <std::pair <std::string, std::string> >::iterator i; std::vector <Triple>::iterator arg;
for (i = this->begin (); i != this->end (); ++i) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (i != this->begin ()) if (arg != this->begin ())
combined += " "; combined += " ";
combined += i->first; combined += arg->_first;
} }
return combined; return combined;
@ -657,12 +657,12 @@ std::string Arguments::combine ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Arguments::find_command (std::string& command) bool Arguments::find_command (std::string& command)
{ {
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = this->begin (); arg != this->end (); ++arg) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
if (arg->second == "command") if (arg->_third == "command")
{ {
command = arg->first; command = arg->_first;
return true; return true;
} }
} }
@ -673,10 +673,10 @@ bool Arguments::find_command (std::string& command)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Arguments::find_limit () std::string Arguments::find_limit ()
{ {
std::vector <std::pair <std::string, std::string> >::reverse_iterator arg; std::vector <Triple>::reverse_iterator arg;
for (arg = this->rbegin (); arg != this->rend (); ++arg) for (arg = this->rbegin (); arg != this->rend (); ++arg)
if (arg->first.find ("limit:") != std::string::npos) if (arg->_first.find ("limit:") != std::string::npos)
return arg->first.substr (6); return arg->_first.substr (6);
return ""; return "";
} }
@ -1222,8 +1222,8 @@ bool Arguments::extract_pattern (const std::string& input, std::string& pattern)
// //
// The sequence is "1 2". // The sequence is "1 2".
// //
// The first number found in the command line is assumed to be a sequence. If // The _first number found in the command line is assumed to be a sequence. If
// there are two sequences, only the first is recognized, for example: // there are two sequences, only the _first is recognized, for example:
// //
// 1,2 three 4,5 // 1,2 three 4,5
// //
@ -1340,39 +1340,39 @@ Arguments Arguments::extract_read_only_filter ()
{ {
Arguments filter; Arguments filter;
std::vector <std::pair <std::string, std::string> >::iterator i; std::vector <Triple>::iterator arg;
for (i = this->begin (); i != this->end (); ++i) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
// Excluded. // Excluded.
if (i->second == "program" || if (arg->_third == "program" ||
i->second == "command" || arg->_third == "command" ||
i->second == "rc" || arg->_third == "rc" ||
i->second == "override") arg->_third == "override")
{ {
; ;
} }
// Included. // Included.
else if (i->second == "tag" || else if (arg->_third == "tag" ||
i->second == "pattern" || arg->_third == "pattern" ||
i->second == "attr" || arg->_third == "attr" ||
i->second == "attmod" || arg->_third == "attmod" ||
i->second == "id" || arg->_third == "id" ||
i->second == "uuid" || arg->_third == "uuid" ||
i->second == "op" || arg->_third == "op" ||
i->second == "exp" || arg->_third == "exp" ||
i->second == "word") arg->_third == "word")
{ {
// "limit" is special - it is recognized but not included in filters. // "limit" is special - it is recognized but not included in filters.
if (i->first.find ("limit:") == std::string::npos) if (arg->_first.find ("limit:") == std::string::npos)
filter.push_back (*i); filter.push_back (*arg);
} }
// Error. // Error.
else else
{ {
// substitution // substitution
throw std::string ("A substitution '") + i->first + "' is not allowed " throw std::string ("A substitution '") + arg->_first + "' is not allowed "
"in a read-only command filter."; "in a read-only command filter.";
} }
} }
@ -1385,35 +1385,35 @@ Arguments Arguments::extract_write_filter ()
{ {
Arguments filter; Arguments filter;
std::vector <std::pair <std::string, std::string> >::iterator i; std::vector <Triple>::iterator arg;
for (i = this->begin (); i != this->end (); ++i) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
// Only use args prior to command. // Only use args prior to command.
if (i->second == "command") if (arg->_third == "command")
break; break;
// Excluded. // Excluded.
else if (i->second == "program" || else if (arg->_third == "program" ||
i->second == "rc" || arg->_third == "rc" ||
i->second == "override") arg->_third == "override")
{ {
; ;
} }
// Included. // Included.
else if (i->second == "tag" || else if (arg->_third == "tag" ||
i->second == "pattern" || arg->_third == "pattern" ||
i->second == "attr" || arg->_third == "attr" ||
i->second == "attmod" || arg->_third == "attmod" ||
i->second == "id" || arg->_third == "id" ||
i->second == "uuid" || arg->_third == "uuid" ||
i->second == "op" || arg->_third == "op" ||
i->second == "exp" || arg->_third == "exp" ||
i->second == "word") arg->_third == "word")
{ {
// "limit" is special - it is recognized but not included in filters. // "limit" is special - it is recognized but not included in filters.
if (i->first.find ("limit:") == std::string::npos) if (arg->_first.find ("limit:") == std::string::npos)
filter.push_back (*i); filter.push_back (*arg);
} }
// Error. // Error.
@ -1421,7 +1421,7 @@ Arguments Arguments::extract_write_filter ()
{ {
// substitution // substitution
throw std::string ("A substitutions '") throw std::string ("A substitutions '")
+ i->first + arg->_first
+ "' is not allowed in a read-only command filter."; + "' is not allowed in a read-only command filter.";
} }
} }
@ -1435,11 +1435,11 @@ Arguments Arguments::extract_modifications ()
Arguments modifications; Arguments modifications;
bool seen_command = false; bool seen_command = false;
std::vector <std::pair <std::string, std::string> >::iterator i; std::vector <Triple>::iterator arg;
for (i = this->begin (); i != this->end (); ++i) for (arg = this->begin (); arg != this->end (); ++arg)
{ {
// Only use args after command. // Only use args after command.
if (i->second == "command") if (arg->_third == "command")
{ {
seen_command = true; seen_command = true;
} }
@ -1447,46 +1447,46 @@ Arguments Arguments::extract_modifications ()
else if (seen_command) else if (seen_command)
{ {
// Excluded. // Excluded.
if (i->second == "program" || if (arg->_third == "program" ||
i->second == "rc" || arg->_third == "rc" ||
i->second == "override") arg->_third == "override")
{ {
} }
// Included. // Included.
else if (i->second == "tag" || else if (arg->_third == "tag" ||
i->second == "attr" || arg->_third == "attr" ||
i->second == "subst" || arg->_third == "subst" ||
i->second == "op" || arg->_third == "op" ||
i->second == "word") arg->_third == "word")
{ {
// "limit" is special - it is recognized but not included in filters. // "limit" is special - it is recognized but not included in filters.
if (i->first.find ("limit:") == std::string::npos) if (arg->_first.find ("limit:") == std::string::npos)
modifications.push_back (*i); modifications.push_back (*arg);
} }
// Error. // Error.
else else
{ {
if (i->second == "pattern") if (arg->_third == "pattern")
throw std::string ("A pattern '") throw std::string ("A pattern '")
+ i->first + arg->_first
+ "' is not allowed when modifiying a task."; + "' is not allowed when modifiying a task.";
else if (i->second == "attmod") else if (arg->_third == "attmod")
throw std::string ("An attribute modifier '") throw std::string ("An attribute modifier '")
+ i->first + arg->_first
+ "' is not allowed when modifiying a task."; + "' is not allowed when modifiying a task.";
else if (i->second == "exp") else if (arg->_third == "exp")
throw std::string ("An expression '") throw std::string ("An expression '")
+ i->first + arg->_first
+ "' is not allowed when modifiying a task."; + "' is not allowed when modifiying a task.";
else if (i->second == "id") else if (arg->_third == "id")
throw std::string ("A task id cannot be modified."); throw std::string ("A task id cannot be modified.");
else if (i->second == "uuid") else if (arg->_third == "uuid")
throw std::string ("A task uuid cannot be modified."); throw std::string ("A task uuid cannot be modified.");
} }
} }
@ -1545,11 +1545,13 @@ void Arguments::dump (const std::string& label)
view.addRow (); view.addRow ();
view.addRow (); view.addRow ();
view.addRow ();
for (unsigned int i = 0; i < this->size (); ++i) for (unsigned int i = 0; i < this->size (); ++i)
{ {
std::string arg = (*this)[i].first; std::string arg = (*this)[i]._first;
std::string category = (*this)[i].second; std::string expanded = (*this)[i]._second;
std::string category = (*this)[i]._third;
Color c; Color c;
if (color_map[category].nontrivial ()) if (color_map[category].nontrivial ())
@ -1558,7 +1560,8 @@ void Arguments::dump (const std::string& label)
c = color_map["none"]; c = color_map["none"];
view.set (0, i, arg, c); view.set (0, i, arg, c);
view.set (1, i, category, c); view.set (1, i, expanded, c);
view.set (2, i, category, c);
} }
out << view.render (); out << view.render ();

View file

@ -34,7 +34,53 @@
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000 #define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
class Arguments : public std::vector <std::pair <std::string, std::string> > class Triple
{
public:
Triple (
const std::string& one,
const std::string& two,
const std::string& three)
: _first (one)
, _second (two)
, _third (three)
{
}
Triple (const Triple& other)
{
_first = other._first;
_second = other._second;
_third = other._third;
}
Triple& operator= (const Triple& other)
{
if (this != &other)
{
_first = other._first;
_second = other._second;
_third = other._third;
}
return *this;
}
bool operator== (const Triple& other) const
{
return _first == other._first &&
_second == other._second &&
_third == other._third;
}
public:
std::string _first;
std::string _second;
std::string _third;
};
//class Arguments : public std::vector <std::pair <std::string, std::string> >
class Arguments : public std::vector <Triple>
{ {
public: public:
Arguments (); Arguments ();

View file

@ -98,7 +98,7 @@ const std::string DOM::get (const std::string& name)
name.substr (0, 8) == "context.") name.substr (0, 8) == "context.")
{ {
if (name == "context.program") if (name == "context.program")
return /*_cache[name] =*/ context.args[0].first; return /*_cache[name] =*/ context.args[0]._first;
else if (name == "context.args") else if (name == "context.args")
{ {

View file

@ -81,15 +81,15 @@ bool Expression::eval (Task& task)
// TODO Build an on-demand regex cache. // TODO Build an on-demand regex cache.
std::vector <std::pair <std::string, std::string> >::const_iterator arg; std::vector <Triple>::const_iterator arg;
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
{ {
if (arg->second == "op") if (arg->_third == "op")
{ {
// std::cout << "# operator " << arg->first << "\n"; // std::cout << "# operator " << arg->_first << "\n";
// Handle the unary operator first. // Handle the unary operator first.
if (arg->first == "!") if (arg->_first == "!")
{ {
// Are there sufficient arguments? // Are there sufficient arguments?
if (value_stack.size () < 1) if (value_stack.size () < 1)
@ -119,7 +119,7 @@ bool Expression::eval (Task& task)
// Are there sufficient arguments? // Are there sufficient arguments?
if (value_stack.size () < 2) if (value_stack.size () < 2)
throw std::string ("Error: Insufficient operands for '") + arg->first + "' operator."; throw std::string ("Error: Insufficient operands for '") + arg->_first + "' operator.";
// rvalue (string, rx, int, number, dom ...). // rvalue (string, rx, int, number, dom ...).
Variant right (value_stack.back ()); Variant right (value_stack.back ());
@ -144,7 +144,7 @@ bool Expression::eval (Task& task)
// std::cout << "# left raw=" << left._raw << " type=" << left._type << " value=" << left._string << "\n"; // std::cout << "# left raw=" << left._raw << " type=" << left._type << " value=" << left._string << "\n";
// Now the binary operators. // Now the binary operators.
if (arg->first == "and") if (arg->_first == "and")
{ {
// std::cout << "# " << left.dump () << " and " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " and " << right.dump () << "\n";
bool result = (left && right); bool result = (left && right);
@ -155,7 +155,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "xor") else if (arg->_first == "xor")
{ {
// std::cout << "# " << left.dump () << " xor " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " xor " << right.dump () << "\n";
bool left_bool = left.boolean (); bool left_bool = left.boolean ();
@ -168,7 +168,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "or") else if (arg->_first == "or")
{ {
// std::cout << "# " << left.dump () << " or " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " or " << right.dump () << "\n";
bool result = (left || right); bool result = (left || right);
@ -179,7 +179,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "<=") else if (arg->_first == "<=")
{ {
// std::cout << "# " << left.dump () << " <= " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " <= " << right.dump () << "\n";
bool result = false; bool result = false;
@ -202,7 +202,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == ">=") else if (arg->_first == ">=")
{ {
// std::cout << "# " << left.dump () << " >= " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " >= " << right.dump () << "\n";
bool result = false; bool result = false;
@ -225,7 +225,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "!~") else if (arg->_first == "!~")
{ {
// std::cout << "# " << left.dump () << " !~ " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " !~ " << right.dump () << "\n";
bool case_sensitive = context.config.getBoolean ("search.case.sensitive"); bool case_sensitive = context.config.getBoolean ("search.case.sensitive");
@ -246,7 +246,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "!=") else if (arg->_first == "!=")
{ {
// std::cout << "# " << left.dump () << " != " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " != " << right.dump () << "\n";
bool result = (left != right); bool result = (left != right);
@ -257,7 +257,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "=") else if (arg->_first == "=")
{ {
// std::cout << "# " << left.dump () << " = " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " = " << right.dump () << "\n";
bool result = false; bool result = false;
@ -280,7 +280,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == ">") else if (arg->_first == ">")
{ {
// std::cout << "# " << left.dump () << " > " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " > " << right.dump () << "\n";
bool result = false; bool result = false;
@ -302,7 +302,7 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "~") else if (arg->_first == "~")
{ {
// std::cout << "# " << left.dump () << " ~ " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " ~ " << right.dump () << "\n";
bool case_sensitive = context.config.getBoolean ("search.case.sensitive"); bool case_sensitive = context.config.getBoolean ("search.case.sensitive");
@ -323,31 +323,31 @@ bool Expression::eval (Task& task)
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "*") else if (arg->_first == "*")
{ {
left = left * right; left = left * right;
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "/") else if (arg->_first == "/")
{ {
left = left / right; left = left / right;
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "+") else if (arg->_first == "+")
{ {
left = left + right; left = left + right;
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "-") else if (arg->_first == "-")
{ {
left = left - right; left = left - right;
value_stack.push_back (left); value_stack.push_back (left);
} }
else if (arg->first == "<") else if (arg->_first == "<")
{ {
// std::cout << "# " << left.dump () << " < " << right.dump () << "\n"; // std::cout << "# " << left.dump () << " < " << right.dump () << "\n";
bool result = false; bool result = false;
@ -370,14 +370,14 @@ bool Expression::eval (Task& task)
} }
else else
throw std::string ("Unsupported operator '") + arg->first + "'."; throw std::string ("Unsupported operator '") + arg->_first + "'.";
} }
// It's not an operator, it's either and lvalue or some form of rvalue. // It's not an operator, it's either and lvalue or some form of rvalue.
else else
{ {
Variant operand; Variant operand;
create_variant (operand, arg->first, arg->second); create_variant (operand, arg->_first, arg->_third);
value_stack.push_back (operand); value_stack.push_back (operand);
} }
} }
@ -464,14 +464,14 @@ void Expression::expand_sequence ()
// Extract all the components of a sequence. // Extract all the components of a sequence.
std::vector <int> ids; std::vector <int> ids;
std::vector <std::string> uuids; std::vector <std::string> uuids;
std::vector <std::pair <std::string, std::string> >::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->second == "id") if (arg->_third == "id")
Arguments::extract_id (arg->first, ids); Arguments::extract_id (arg->_first, ids);
else if (arg->second == "uuid") else if (arg->_third == "uuid")
Arguments::extract_uuid (arg->first, uuids); Arguments::extract_uuid (arg->_first, uuids);
} }
// If there is no sequence, we're done. // If there is no sequence, we're done.
@ -508,20 +508,20 @@ void Expression::expand_sequence ()
// Copy everything up to the first id/uuid. // Copy everything up to the first id/uuid.
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
{ {
if (arg->second == "id" || arg->second == "uuid") if (arg->_third == "id" || arg->_third == "uuid")
break; break;
temp.push_back (*arg); temp.push_back (*arg);
} }
// Now insert the new sequence expression. // Now insert the new sequence expression.
temp.push_back (std::make_pair (sequence.str (), "exp")); temp.push_back (Triple (sequence.str (), "?", "exp"));
// Now copy everything after the last id/uuid. // Now copy everything after the last id/uuid.
bool found_id = false; bool found_id = false;
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
{ {
if (arg->second == "id" || arg->second == "uuid") if (arg->_third == "id" || arg->_third == "uuid")
found_id = true; found_id = true;
else if (found_id) else if (found_id)
@ -553,47 +553,47 @@ void Expression::expand_tokens ()
time_t t; time_t t;
// Look at all args. // Look at all args.
std::vector <std::pair <std::string, std::string> >::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->second == "exp") if (arg->_third == "exp")
{ {
// Nibble each arg token by token. // Nibble each arg token by token.
Nibbler n (arg->first); Nibbler n (arg->_first);
while (! n.depleted ()) while (! n.depleted ())
{ {
if (n.getQuoted ('"', s, true) || if (n.getQuoted ('"', s, true) ||
n.getQuoted ('\'', s, true)) n.getQuoted ('\'', s, true))
temp.push_back (std::make_pair (s, "string")); temp.push_back (Triple (s, "?", "string"));
else if (n.getQuoted ('/', s, true)) else if (n.getQuoted ('/', s, true))
temp.push_back (std::make_pair (s, "pattern")); temp.push_back (Triple (s, "?", "pattern"));
else if (n.getOneOf (operators, s)) else if (n.getOneOf (operators, s))
temp.push_back (std::make_pair (s, "op")); temp.push_back (Triple (s, "?", "op"));
else if (n.getDOM (s)) else if (n.getDOM (s))
temp.push_back (std::make_pair (s, "lvalue")); temp.push_back (Triple (s, "?", "lvalue"));
else if (n.getNumber (d)) else if (n.getNumber (d))
temp.push_back (std::make_pair (format (d), "number")); temp.push_back (Triple (format (d), "?", "number"));
else if (n.getInt (i)) else if (n.getInt (i))
temp.push_back (std::make_pair (format (i), "int")); temp.push_back (Triple (format (i), "?", "int"));
else if (n.getDateISO (t)) else if (n.getDateISO (t))
temp.push_back (std::make_pair (Date (t).toISO (), "date")); temp.push_back (Triple (Date (t).toISO (), "?", "date"));
else if (n.getDate (date_format, t)) else if (n.getDate (date_format, t))
temp.push_back (std::make_pair (Date (t).toString (date_format), "date")); temp.push_back (Triple (Date (t).toString (date_format), "?", "date"));
else else
{ {
if (! n.getUntilWS (s)) if (! n.getUntilWS (s))
n.getUntilEOS (s); n.getUntilEOS (s);
temp.push_back (std::make_pair (s, "?")); temp.push_back (Triple (s, "?", "?"));
} }
n.skipWS (); n.skipWS ();
@ -622,20 +622,20 @@ void Expression::implicit_and ()
bool delta = false; bool delta = false;
std::string previous = "op"; std::string previous = "op";
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
{ {
// Old-style filters need 'and' conjunctions. // Old-style filters need 'and' conjunctions.
if (previous != "op" && if (previous != "op" &&
arg->second != "op") arg->_third != "op")
{ {
temp.push_back (std::make_pair ("and", "op")); temp.push_back (Triple ("and", "?", "op"));
delta = true; delta = true;
} }
// Now insert the adjacent non-operator. // Now insert the adjacent non-operator.
temp.push_back (*arg); temp.push_back (*arg);
previous = arg->second; previous = arg->_third;
} }
if (delta) if (delta)
@ -654,18 +654,18 @@ void Expression::expand_tag ()
Arguments temp; Arguments temp;
bool delta = false; bool delta = false;
std::vector <std::pair <std::string, std::string> >::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->second == "tag") if (arg->_third == "tag")
{ {
char type; char type;
std::string value; std::string value;
Arguments::extract_tag (arg->first, type, value); Arguments::extract_tag (arg->_first, type, value);
temp.push_back (std::make_pair ("tags", "lvalue")); temp.push_back (Triple ("tags", "?", "lvalue"));
temp.push_back (std::make_pair (type == '+' ? "~" : "!~", "op")); temp.push_back (Triple (type == '+' ? "~" : "!~", "?", "op"));
temp.push_back (std::make_pair (value, "string")); temp.push_back (Triple (value, "?", "string"));
delta = true; delta = true;
} }
else else
@ -687,17 +687,17 @@ void Expression::expand_pattern ()
Arguments temp; Arguments temp;
bool delta = false; bool delta = false;
std::vector <std::pair <std::string, std::string> >::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->second == "pattern") if (arg->_third == "pattern")
{ {
std::string value; std::string value;
Arguments::extract_pattern (arg->first, value); Arguments::extract_pattern (arg->_first, value);
temp.push_back (std::make_pair ("description", "lvalue")); temp.push_back (Triple ("description", "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair (value, "rx")); temp.push_back (Triple (value, "?", "rx"));
delta = true; delta = true;
} }
else else
@ -719,24 +719,24 @@ void Expression::expand_attr ()
Arguments temp; Arguments temp;
bool delta = false; bool delta = false;
std::vector <std::pair <std::string, std::string> >::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->second == "attr") if (arg->_third == "attr")
{ {
// TODO Canonicalize 'name'. // TODO Canonicalize 'name'.
std::string name; std::string name;
std::string value; std::string value;
Arguments::extract_attr (arg->first, name, value); Arguments::extract_attr (arg->_first, name, value);
Arguments::is_attribute (name, name); Arguments::is_attribute (name, name);
// Always quote the value, so that empty values, or values containing spaces // Always quote the value, so that empty values, or values containing spaces
// are preserved. // are preserved.
value = "\"" + value + "\""; value = "\"" + value + "\"";
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("=", "op")); temp.push_back (Triple ("=", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
delta = true; delta = true;
} }
else else
@ -758,16 +758,16 @@ void Expression::expand_attmod ()
Arguments temp; Arguments temp;
bool delta = false; bool delta = false;
std::vector <std::pair <std::string, std::string> >::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->second == "attmod") if (arg->_third == "attmod")
{ {
std::string name; std::string name;
std::string mod; std::string mod;
std::string value; std::string value;
std::string sense; std::string sense;
Arguments::extract_attmod (arg->first, name, mod, value, sense); Arguments::extract_attmod (arg->_first, name, mod, value, sense);
Arguments::is_attribute (name, name); Arguments::is_attribute (name, name);
Arguments::is_modifier (mod); Arguments::is_modifier (mod);
@ -778,75 +778,75 @@ void Expression::expand_attmod ()
if (mod == "before" || mod == "under" || mod == "below") if (mod == "before" || mod == "under" || mod == "below")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("<", "op")); temp.push_back (Triple ("<", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "after" || mod == "over" || mod == "above") else if (mod == "after" || mod == "over" || mod == "above")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair (">", "op")); temp.push_back (Triple (">", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "none") else if (mod == "none")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("==", "op")); temp.push_back (Triple ("==", "?", "op"));
temp.push_back (std::make_pair ("\"\"", "string")); temp.push_back (Triple ("\"\"", "?", "string"));
} }
else if (mod == "any") else if (mod == "any")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("!=", "op")); temp.push_back (Triple ("!=", "?", "op"));
temp.push_back (std::make_pair ("\"\"", "string")); temp.push_back (Triple ("\"\"", "?", "string"));
} }
else if (mod == "is" || mod == "equals") else if (mod == "is" || mod == "equals")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("=", "op")); temp.push_back (Triple ("=", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "isnt" || mod == "not") else if (mod == "isnt" || mod == "not")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("!=", "op")); temp.push_back (Triple ("!=", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "has" || mod == "contains") else if (mod == "has" || mod == "contains")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "hasnt") else if (mod == "hasnt")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("!~", "op")); temp.push_back (Triple ("!~", "?", "op"));
temp.push_back (std::make_pair (value, "rvalue")); temp.push_back (Triple (value, "?", "rvalue"));
} }
else if (mod == "startswith" || mod == "left") else if (mod == "startswith" || mod == "left")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair ("^" + raw_value, "rx")); temp.push_back (Triple ("^" + raw_value, "?", "rx"));
} }
else if (mod == "endswith" || mod == "right") else if (mod == "endswith" || mod == "right")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair (raw_value + "$", "rx")); temp.push_back (Triple (raw_value + "$", "?", "rx"));
} }
else if (mod == "word") else if (mod == "word")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair ("\\b" + raw_value + "\\b", "rx")); temp.push_back (Triple ("\\b" + raw_value + "\\b", "?", "rx"));
} }
else if (mod == "noword") else if (mod == "noword")
{ {
temp.push_back (std::make_pair (name, "lvalue")); temp.push_back (Triple (name, "?", "lvalue"));
temp.push_back (std::make_pair ("!~", "op")); temp.push_back (Triple ("!~", "?", "op"));
temp.push_back (std::make_pair ("\\b" + raw_value + "\\b", "rx")); temp.push_back (Triple ("\\b" + raw_value + "\\b", "?", "rx"));
} }
else else
throw std::string ("Error: unrecognized attribute modifier '") + mod + "'."; throw std::string ("Error: unrecognized attribute modifier '") + mod + "'.";
@ -872,14 +872,14 @@ void Expression::expand_word ()
Arguments temp; Arguments temp;
bool delta = false; bool delta = false;
std::vector <std::pair <std::string, std::string> >::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->second == "word") if (arg->_third == "word")
{ {
temp.push_back (std::make_pair ("description", "lvalue")); temp.push_back (Triple ("description", "?", "lvalue"));
temp.push_back (std::make_pair ("~", "op")); temp.push_back (Triple ("~", "?", "op"));
temp.push_back (std::make_pair ("\"" + arg->first + "\"", "rvalue")); temp.push_back (Triple ("\"" + arg->_first + "\"", "?", "rvalue"));
delta = true; delta = true;
} }
@ -936,17 +936,17 @@ void Expression::postfix ()
int precedence; int precedence;
char associativity; char associativity;
std::vector <std::pair <std::string, std::string> >::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->first == "(") if (arg->_first == "(")
{ {
op_stack.push_back (*arg); op_stack.push_back (*arg);
} }
else if (arg->first == ")") else if (arg->_first == ")")
{ {
while (op_stack.size () > 0 && while (op_stack.size () > 0 &&
op_stack.back ().first != "(") op_stack.back ()._first != "(")
{ {
temp.push_back (op_stack.back ()); temp.push_back (op_stack.back ());
op_stack.pop_back (); op_stack.pop_back ();
@ -961,13 +961,13 @@ void Expression::postfix ()
throw std::string ("Mismatched parentheses in expression"); throw std::string ("Mismatched parentheses in expression");
} }
} }
else if (Arguments::is_operator (arg->first, type, precedence, associativity)) else if (Arguments::is_operator (arg->_first, type, precedence, associativity))
{ {
char type2; char type2;
int precedence2; int precedence2;
char associativity2; char associativity2;
while (op_stack.size () > 0 && while (op_stack.size () > 0 &&
Arguments::is_operator (op_stack.back ().first, type2, precedence2, associativity2) && Arguments::is_operator (op_stack.back ()._first, type2, precedence2, associativity2) &&
((associativity == 'l' && precedence <= precedence2) || ((associativity == 'l' && precedence <= precedence2) ||
(associativity == 'r' && precedence < precedence2))) (associativity == 'r' && precedence < precedence2)))
{ {
@ -985,8 +985,8 @@ void Expression::postfix ()
while (op_stack.size () != 0) while (op_stack.size () != 0)
{ {
if (op_stack.back ().first == "(" || if (op_stack.back ()._first == "(" ||
op_stack.back ().first == ")") op_stack.back ()._first == ")")
throw std::string ("Mismatched parentheses in expression"); throw std::string ("Mismatched parentheses in expression");
temp.push_back (op_stack.back ()); temp.push_back (op_stack.back ());
@ -1007,9 +1007,9 @@ void Expression::postfix ()
// //
bool Expression::is_new_style () bool Expression::is_new_style ()
{ {
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = _args.begin (); arg != _args.end (); ++arg) for (arg = _args.begin (); arg != _args.end (); ++arg)
if (Arguments::is_symbol_operator (arg->first)) if (Arguments::is_symbol_operator (arg->_first))
return true; return true;
return false; return false;

View file

@ -48,12 +48,12 @@ CmdExec::CmdExec ()
int CmdExec::execute (std::string& output) int CmdExec::execute (std::string& output)
{ {
std::string command_line; std::string command_line;
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = context.args.begin (); arg != context.args.end (); ++arg) for (arg = context.args.begin (); arg != context.args.end (); ++arg)
{ {
if (arg != context.args.begin () && if (arg != context.args.begin () &&
arg->first != "execute") arg->_first != "execute")
command_line += arg->first; command_line += arg->_first;
} }
return system (command_line.c_str ()); return system (command_line.c_str ());

View file

@ -284,16 +284,16 @@ void Command::modify_task (Task& task, Arguments& arguments)
{ {
std::string description; std::string description;
std::vector <std::pair <std::string, std::string> >::iterator arg; std::vector <Triple>::iterator arg;
for (arg = arguments.begin (); arg != arguments.end (); ++arg) for (arg = arguments.begin (); arg != 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->second == "attr") if (arg->_third == "attr")
{ {
std::string name; std::string name;
std::string value; std::string value;
Arguments::extract_attr (arg->first, name, value); Arguments::extract_attr (arg->_first, name, value);
// TODO All 'value's must be eval'd first. // TODO All 'value's must be eval'd first.
@ -324,11 +324,11 @@ void Command::modify_task (Task& task, Arguments& arguments)
// 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->second == "tag") else if (arg->_third == "tag")
{ {
char type; char type;
std::string value; std::string value;
Arguments::extract_tag (arg->first, type, value); Arguments::extract_tag (arg->_first, type, value);
if (type == '+') if (type == '+')
task.addTag (value); task.addTag (value);
@ -337,29 +337,29 @@ void Command::modify_task (Task& task, Arguments& arguments)
} }
// Words and operators are aggregated into a description. // Words and operators are aggregated into a description.
else if (arg->second == "word" || else if (arg->_third == "word" ||
arg->second == "op") arg->_third == "op")
{ {
if (description.length ()) if (description.length ())
description += " "; description += " ";
description += arg->first; description += arg->_first;
} }
// Substitutions. // Substitutions.
else if (arg->second == "subst") else if (arg->_third == "subst")
{ {
std::string from; std::string from;
std::string to; std::string to;
bool global; bool global;
Arguments::extract_subst (arg->first, from, to, global); Arguments::extract_subst (arg->_first, from, to, global);
task.substitute (from, to, global); task.substitute (from, to, global);
} }
// Any additional argument types are indicative of a failure in // Any additional argument types are indicative of a failure in
// Arguments::extract_modifications. // Arguments::extract_modifications.
else else
throw format (STRING_CMD_MOD_UNEXPECTED, arg->first); throw format (STRING_CMD_MOD_UNEXPECTED, arg->_first);
} }
// Only update description if one was specified. // Only update description if one was specified.