* Allow inlining functions in commands with parantheses, e.g:

print = (convert.time,(system.time))
  schedule2 = test_print_2,2,2,((print,"current ",((convert.time,((system.time))))))

  Multiple parantheses need to be used in schedule to ensure the command doesn't get evaluated at the time of calling schedule.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1191 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2011-02-12 12:20:09 +00:00
parent 5691233bf1
commit 7b2fae35d5
12 changed files with 198 additions and 24 deletions
+37
View File
@@ -181,6 +181,43 @@ parse_object(const char* first, const char* last, torrent::Object* dest, bool (*
return ++first;
} else if (*first == '(') {
int32_t depth = 1;
while (first + 1 != last && *(first + 1) == '(') {
first++;
depth++;
}
if (depth > 3)
throw torrent::input_error("Max 3 parantheses per object allowed.");
*dest = torrent::Object::create_dict_key();
dest->set_flags(torrent::Object::flag_function << (depth - 1));
first = parse_string(first + 1, last, &dest->as_dict_key(), &parse_is_delim_func);
first = parse_skip_wspace(first, last);
if (first == last || !parse_is_delim_func(*first))
throw torrent::input_error("Could not find closing ')'.");
if (*first == ',') {
// This will always create a list even for single argument functions...
dest->as_dict_obj() = torrent::Object::create_list();
first = parse_list(first + 1, last, &dest->as_dict_obj(), &parse_is_delim_func);
first = parse_skip_wspace(first, last);
}
while (depth != 0 && first != last && *first == ')') {
first++;
depth--;
}
if (depth != 0)
throw torrent::input_error("Parantheses mismatch.");
return first;
} else {
*dest = std::string();