2015-10-29 01:26:09 +00:00
|
|
|
// So far instructions can only contain linear lists of properties. Now we add
|
|
|
|
// support for more complex trees of properties in dilated reagents. This will
|
|
|
|
// come in handy later for expressing complex types, like "a dictionary from
|
|
|
|
// (address to array of charaters) to (list of numbers)".
|
|
|
|
|
2015-10-27 21:38:57 +00:00
|
|
|
:(scenario dilated_reagent_with_nested_brackets)
|
2016-03-08 09:30:14 +00:00
|
|
|
def main [
|
2015-10-27 21:38:57 +00:00
|
|
|
{1: number, foo: (bar (baz quux))} <- copy 34
|
|
|
|
]
|
2016-03-21 09:25:52 +00:00
|
|
|
+parse: product: {1: "number", "foo": ("bar" ("baz" "quux"))}
|
2015-10-27 21:38:57 +00:00
|
|
|
|
|
|
|
:(before "End Parsing Reagent Property(value)")
|
|
|
|
value = parse_string_tree(value);
|
2016-02-22 04:30:02 +00:00
|
|
|
:(before "End Parsing Reagent Type Property(value)")
|
|
|
|
value = parse_string_tree(value);
|
2015-10-27 21:38:57 +00:00
|
|
|
|
|
|
|
:(code)
|
|
|
|
string_tree* parse_string_tree(string_tree* s) {
|
|
|
|
assert(!s->left && !s->right);
|
|
|
|
if (s->value.at(0) != '(') return s;
|
|
|
|
string_tree* result = parse_string_tree(s->value);
|
|
|
|
delete s;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string_tree* parse_string_tree(const string& s) {
|
|
|
|
istringstream in(s);
|
|
|
|
in >> std::noskipws;
|
|
|
|
return parse_string_tree(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_tree* parse_string_tree(istream& in) {
|
2015-12-03 01:11:58 +00:00
|
|
|
skip_whitespace_but_not_newline(in);
|
2015-11-17 09:21:00 +00:00
|
|
|
if (!has_data(in)) return NULL;
|
2015-10-27 21:38:57 +00:00
|
|
|
if (in.peek() == ')') {
|
|
|
|
in.get();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (in.peek() != '(') {
|
2015-10-27 23:34:58 +00:00
|
|
|
string_tree* result = new string_tree(next_word(in));
|
|
|
|
return result;
|
2015-10-27 21:38:57 +00:00
|
|
|
}
|
|
|
|
in.get(); // skip '('
|
2015-10-27 23:34:58 +00:00
|
|
|
string_tree* result = NULL;
|
|
|
|
string_tree** curr = &result;
|
|
|
|
while (in.peek() != ')') {
|
2015-11-17 09:21:00 +00:00
|
|
|
assert(has_data(in));
|
2015-10-27 23:34:58 +00:00
|
|
|
*curr = new string_tree("");
|
2015-12-03 01:11:58 +00:00
|
|
|
skip_whitespace_but_not_newline(in);
|
2015-10-27 23:34:58 +00:00
|
|
|
if (in.peek() == '(')
|
|
|
|
(*curr)->left = parse_string_tree(in);
|
|
|
|
else
|
|
|
|
(*curr)->value = next_word(in);
|
|
|
|
curr = &(*curr)->right;
|
2015-10-27 21:38:57 +00:00
|
|
|
}
|
2015-10-27 23:34:58 +00:00
|
|
|
in.get(); // skip ')'
|
|
|
|
return result;
|
2015-10-27 21:38:57 +00:00
|
|
|
}
|
2015-10-27 23:34:58 +00:00
|
|
|
|
|
|
|
:(scenario dilated_reagent_with_type_tree)
|
2015-11-05 07:54:14 +00:00
|
|
|
% Hide_errors = true; // 'map' isn't defined yet
|
2016-03-08 09:30:14 +00:00
|
|
|
def main [
|
2015-11-07 16:27:16 +00:00
|
|
|
{1: (foo (address array character) (bar number))} <- copy 34
|
2015-10-27 23:34:58 +00:00
|
|
|
]
|
2015-11-07 16:27:16 +00:00
|
|
|
# just to avoid errors
|
|
|
|
container foo [
|
|
|
|
]
|
|
|
|
container bar [
|
|
|
|
]
|
2016-03-21 09:25:52 +00:00
|
|
|
+parse: product: {1: ("foo" ("address" "array" "character") ("bar" "number"))}
|
2015-11-04 20:25:39 +00:00
|
|
|
|
2016-02-28 09:19:33 +00:00
|
|
|
:(scenario dilated_reagent_in_static_array)
|
2016-03-08 09:30:14 +00:00
|
|
|
def main [
|
2016-04-24 18:54:30 +00:00
|
|
|
{1: (array (address number) 3)} <- create-array
|
|
|
|
5:address:number <- new number:type
|
|
|
|
{1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number
|
|
|
|
*5:address:number <- copy 34
|
|
|
|
6:number <- copy *5:address:number
|
2016-02-28 09:19:33 +00:00
|
|
|
]
|
|
|
|
+run: creating array of size 4
|
|
|
|
+mem: storing 34 in location 6
|
|
|
|
|
2015-11-04 20:25:39 +00:00
|
|
|
//: an exception is 'new', which takes a type tree as its ingredient *value*
|
|
|
|
|
|
|
|
:(scenario dilated_reagent_with_new)
|
2016-03-08 09:30:14 +00:00
|
|
|
def main [
|
2016-04-24 18:54:30 +00:00
|
|
|
x:address:address:number <- new {(address number): type}
|
2015-11-04 20:25:39 +00:00
|
|
|
]
|
2016-02-19 22:27:01 +00:00
|
|
|
+new: size of ("address" "number") is 1
|
2015-11-04 20:25:39 +00:00
|
|
|
|
2016-01-20 02:46:39 +00:00
|
|
|
:(before "End Post-processing(expected_product) When Checking 'new'")
|
2016-02-22 04:30:02 +00:00
|
|
|
{
|
|
|
|
string_tree* tmp_type_names = parse_string_tree(expected_product.type->name);
|
|
|
|
delete expected_product.type;
|
|
|
|
expected_product.type = new_type_tree(tmp_type_names);
|
|
|
|
delete tmp_type_names;
|
|
|
|
}
|
2015-11-04 20:25:39 +00:00
|
|
|
:(before "End Post-processing(type_name) When Converting 'new'")
|
|
|
|
type_name = parse_string_tree(type_name);
|