diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-10-26 01:19:27 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-10-26 01:19:27 -0700 |
commit | 7bba6e7bb7fd7bfdfc71626a34a08cb96a084b74 (patch) | |
tree | 2e053b799990e3f561a178f2a3340e9a131617ad | |
parent | 9cc389ce771636c1350c269ef042c47c427ecd28 (diff) | |
download | mu-7bba6e7bb7fd7bfdfc71626a34a08cb96a084b74.tar.gz |
2282
Switch format for tracing reagents in preparation for trees rather than arrays of properties.
-rw-r--r-- | 010vm.cc | 20 | ||||
-rw-r--r-- | 011load.cc | 56 | ||||
-rw-r--r-- | 013literal_string.cc | 28 | ||||
-rw-r--r-- | 014literal_noninteger.cc | 2 | ||||
-rw-r--r-- | 054dilated_reagent.cc | 6 |
5 files changed, 59 insertions, 53 deletions
diff --git a/010vm.cc b/010vm.cc index 8e3bab59..d0a5fee5 100644 --- a/010vm.cc +++ b/010vm.cc @@ -286,20 +286,28 @@ reagent::reagent() :value(0), initialized(false), type(NULL) { string reagent::to_string() const { ostringstream out; - out << "{name: \"" << name << "\""; if (!properties.empty()) { - out << ", properties: ["; + out << "{"; for (long long int i = 0; i < SIZE(properties); ++i) { + if (i > 0) out << ", "; out << "\"" << properties.at(i).first << "\": "; + if (properties.at(i).second.empty()) { + out << "\"\""; + continue; + } + if (SIZE(properties.at(i).second) == 1) { + out << "\"" << properties.at(i).second.at(0) << "\""; + continue; + } + out << "<"; for (long long int j = 0; j < SIZE(properties.at(i).second); ++j) { - if (j > 0) out << ':'; + if (j > 0) out << " : "; out << "\"" << properties.at(i).second.at(j) << "\""; } - if (i < SIZE(properties)-1) out << ", "; - else out << "]"; + out << ">"; } + out << "}"; } - out << "}"; return out.str(); } diff --git a/011load.cc b/011load.cc index 44d906a3..19756fc1 100644 --- a/011load.cc +++ b/011load.cc @@ -6,8 +6,8 @@ recipe main [ 1:number <- copy 23 ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} :(code) vector<recipe_ordinal> load(string form) { @@ -254,8 +254,8 @@ recipe main [ 1:number <- copy 23 ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} :(scenario parse_comment_amongst_instruction) recipe main [ @@ -263,8 +263,8 @@ recipe main [ 1:number <- copy 23 ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} :(scenario parse_comment_amongst_instruction_2) recipe main [ @@ -273,8 +273,8 @@ recipe main [ # comment ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} :(scenario parse_comment_amongst_instruction_3) recipe main [ @@ -283,19 +283,19 @@ recipe main [ 2:number <- copy 23 ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "2", properties: ["2": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"2": "number"} :(scenario parse_comment_after_instruction) recipe main [ 1:number <- copy 23 # comment ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} :(scenario parse_label) recipe main [ @@ -314,43 +314,43 @@ recipe main [ 1:number <- copy 23/foo:bar:baz ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal", "foo": "bar":"baz"]} -+parse: product: {name: "1", properties: ["1": "number"]} ++parse: ingredient: {"23": "literal", "foo": <"bar" : "baz">} ++parse: product: {"1": "number"} :(scenario parse_multiple_products) recipe main [ 1:number, 2:number <- copy 23 ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: product: {name: "1", properties: ["1": "number"]} -+parse: product: {name: "2", properties: ["2": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: product: {"1": "number"} ++parse: product: {"2": "number"} :(scenario parse_multiple_ingredients) recipe main [ 1:number, 2:number <- copy 23, 4:number ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: ingredient: {name: "4", properties: ["4": "number"]} -+parse: product: {name: "1", properties: ["1": "number"]} -+parse: product: {name: "2", properties: ["2": "number"]} ++parse: ingredient: {"23": "literal"} ++parse: ingredient: {"4": "number"} ++parse: product: {"1": "number"} ++parse: product: {"2": "number"} :(scenario parse_multiple_types) recipe main [ 1:number, 2:address:number <- copy 23, 4:number ] +parse: instruction: copy -+parse: ingredient: {name: "23", properties: ["23": "literal"]} -+parse: ingredient: {name: "4", properties: ["4": "number"]} -+parse: product: {name: "1", properties: ["1": "number"]} -+parse: product: {name: "2", properties: ["2": "address":"number"]} ++parse: ingredient: {"23": "literal"} ++parse: ingredient: {"4": "number"} ++parse: product: {"1": "number"} ++parse: product: {"2": <"address" : "number">} :(scenario parse_properties) recipe main [ 1:number:address/lookup <- copy 23 ] -+parse: product: {name: "1", properties: ["1": "number":"address", "lookup": ]} ++parse: product: {"1": <"number" : "address">, "lookup": ""} //: this test we can't represent with a scenario :(code) diff --git a/013literal_string.cc b/013literal_string.cc index 569c8613..9f5d003e 100644 --- a/013literal_string.cc +++ b/013literal_string.cc @@ -10,13 +10,13 @@ recipe main [ 1:address:array:character <- copy [abc def] # copy can't really take a string ] -+parse: ingredient: {name: "abc def", properties: [_: "literal-string"]} ++parse: ingredient: {"abc def": "literal-string"} :(scenario string_literal_with_colons) recipe main [ 1:address:array:character <- copy [abc:def/ghi] ] -+parse: ingredient: {name: "abc:def/ghi", properties: [_: "literal-string"]} ++parse: ingredient: {"abc:def/ghi": "literal-string"} :(before "End Mu Types Initialization") Type_ordinal["literal-string"] = 0; @@ -117,10 +117,8 @@ if (s.at(0) == '[') { return; } -//: Two tweaks to printing literal strings compared to other reagents: -//: a) Don't print the string twice in the representation, just put '_' in -//: the property list. -//: b) Escape newlines in the string to make it more friendly to trace(). +//: Unlike other reagents, escape newlines in literal strings to make them +//: more friendly to trace(). :(after "string reagent::to_string()") if (is_literal_string(*this)) @@ -135,7 +133,7 @@ string emit_literal_string(string name) { size_t pos = 0; while (pos != string::npos) pos = replace(name, "\n", "\\n", pos); - return "{name: \""+name+"\", properties: [_: \"literal-string\"]}"; + return "{\""+name+"\": \"literal-string\"}"; } size_t replace(string& str, const string& from, const string& to, size_t n) { @@ -153,28 +151,28 @@ void strip_last(string& s) { recipe main [ 1:address:array:character <- copy [abc [def]] ] -+parse: ingredient: {name: "abc [def]", properties: [_: "literal-string"]} ++parse: ingredient: {"abc [def]": "literal-string"} :(scenario string_literal_escaped) recipe main [ 1:address:array:character <- copy [abc \[def] ] -+parse: ingredient: {name: "abc [def", properties: [_: "literal-string"]} ++parse: ingredient: {"abc [def": "literal-string"} :(scenario string_literal_escaped_comment_aware) recipe main [ 1:address:array:character <- copy [ abc \\\[def] ] -+parse: ingredient: {name: "\nabc \[def", properties: [_: "literal-string"]} ++parse: ingredient: {"\nabc \[def": "literal-string"} :(scenario string_literal_and_comment) recipe main [ 1:address:array:character <- copy [abc] # comment ] +parse: instruction: copy -+parse: ingredient: {name: "abc", properties: [_: "literal-string"]} -+parse: product: {name: "1", properties: ["1": "address":"array":"character"]} ++parse: ingredient: {"abc": "literal-string"} ++parse: product: {"1": <"address" : "array" : "character">} # no other ingredients $parse: 3 @@ -183,7 +181,7 @@ recipe main [ copy [abc def] ] -+parse: ingredient: {name: "abc\ndef", properties: [_: "literal-string"]} ++parse: ingredient: {"abc\ndef": "literal-string"} :(scenario string_literal_can_skip_past_comments) recipe main [ @@ -192,10 +190,10 @@ recipe main [ bar ] ] -+parse: ingredient: {name: "\n # ']' inside comment\n bar\n ", properties: [_: "literal-string"]} ++parse: ingredient: {"\n # ']' inside comment\n bar\n ": "literal-string"} :(scenario string_literal_empty) recipe main [ copy [] ] -+parse: ingredient: {name: "", properties: [_: "literal-string"]} ++parse: ingredient: {"": "literal-string"} diff --git a/014literal_noninteger.cc b/014literal_noninteger.cc index 19966d9a..17a3e895 100644 --- a/014literal_noninteger.cc +++ b/014literal_noninteger.cc @@ -5,7 +5,7 @@ recipe main [ 1:number <- copy 3.14159 ] -+parse: ingredient: {name: "3.14159", properties: ["3.14159": "literal-number"]} ++parse: ingredient: {"3.14159": "literal-number"} :(after "Parsing reagent(string s)") if (is_noninteger(s)) { diff --git a/054dilated_reagent.cc b/054dilated_reagent.cc index a8cd6226..af7e5820 100644 --- a/054dilated_reagent.cc +++ b/054dilated_reagent.cc @@ -6,7 +6,7 @@ recipe main [ {1: number, foo: bar} <- copy 34 ] -+parse: product: {name: "1", properties: ["1": "number", "foo": "bar"]} ++parse: product: {"1": "number", "foo": "bar"} //: First augment next_word to group balanced brackets together. @@ -114,8 +114,8 @@ string next_dilated_word(istream& in) { return result; } -:(scenario dilated_reagent_with_s_expression) +:(scenario dilated_reagent_with_nested_brackets) recipe main [ {1: number, foo: (bar (baz quux))} <- copy 34 ] -+parse: product: {name: "1", properties: ["1": "number", "foo": "(bar (baz quux))"]} ++parse: product: {"1": "number", "foo": "(bar (baz quux))"} |