about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-28 22:45:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-28 22:55:04 -0700
commitc51043abdf83243f81685858d8f76793faed042b (patch)
tree362afefaa547dc1f8dd490947056a558d5fe3b17
parente3fa6cc7af792a6c0d83d9004859d6e9452c5fdb (diff)
downloadmu-c51043abdf83243f81685858d8f76793faed042b.tar.gz
1217 - string literals weren't handling later comments
-rw-r--r--cpp/.traces/string_literal7
-rw-r--r--cpp/.traces/string_literal_and_comment3
-rw-r--r--cpp/013literal_string.cc16
-rw-r--r--cpp/031address.cc25
-rw-r--r--cpp/041name.cc7
-rw-r--r--cpp/054closure_name.cc8
-rw-r--r--cpp/tangle/030tangle.cc15
-rw-r--r--cpp/tangle/030tangle.test.cc11
8 files changed, 65 insertions, 27 deletions
diff --git a/cpp/.traces/string_literal b/cpp/.traces/string_literal
index 333fb20d..9b5d14b4 100644
--- a/cpp/.traces/string_literal
+++ b/cpp/.traces/string_literal
@@ -1,10 +1,3 @@
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "abc def", value: 0, type: 0, properties: ["abc def": "literal-string"]}
-parse/0:   ingredient: {name: "#", value: 0, type: , properties: ["#": ]}
-parse/0:   ingredient: {name: "copy", value: 0, type: , properties: ["copy": ]}
-parse/0:   ingredient: {name: "can't", value: 0, type: , properties: ["can't": ]}
-parse/0:   ingredient: {name: "really", value: 0, type: , properties: ["really": ]}
-parse/0:   ingredient: {name: "take", value: 0, type: , properties: ["take": ]}
-parse/0:   ingredient: {name: "a", value: 0, type: , properties: ["a": ]}
-parse/0:   ingredient: {name: "string", value: 0, type: , properties: ["string": ]}
 parse/0:   product: {name: "1", value: 0, type: 2-5-4, properties: ["1": "address":"array":"character"]}
diff --git a/cpp/.traces/string_literal_and_comment b/cpp/.traces/string_literal_and_comment
new file mode 100644
index 00000000..9ad1bff7
--- /dev/null
+++ b/cpp/.traces/string_literal_and_comment
@@ -0,0 +1,3 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "abc", value: 0, type: 0, properties: ["abc": "literal-string"]}
+parse/0:   product: {name: "1", value: 0, type: 2-5-4, properties: ["1": "address":"array":"character"]}
diff --git a/cpp/013literal_string.cc b/cpp/013literal_string.cc
index b27ede36..203859e1 100644
--- a/cpp/013literal_string.cc
+++ b/cpp/013literal_string.cc
@@ -22,7 +22,12 @@ recipe main [
 Type_number["literal-string"] = 0;
 
 :(after "string next_word(istream& in)")
-if (in.peek() == '[') return slurp_quoted(in);
+  if (in.peek() == '[') {
+    string result = slurp_quoted(in);
+    skip_whitespace(in);
+    skip_comment(in);
+    return result;
+  }
 
 :(code)
 string slurp_quoted(istream& in) {
@@ -61,3 +66,12 @@ recipe main [
   1:address:array:character <- copy [abc [def]]
 ]
 +parse:   ingredient: {name: "abc [def]", value: 0, type: 0, properties: ["abc [def]": "literal-string"]}
+
+:(scenario string_literal_and_comment)
+recipe main [
+  1:address:array:character <- copy [abc]  # comment
+]
++parse: instruction: 1
++parse:   ingredient: {name: "abc", value: 0, type: 0, properties: ["abc": "literal-string"]}
++parse:   product: {name: "1", value: 0, type: 2-5-4, properties: ["1": "address":"array":"character"]}
+$parse: 3
diff --git a/cpp/031address.cc b/cpp/031address.cc
index fd713a22..fd9037b1 100644
--- a/cpp/031address.cc
+++ b/cpp/031address.cc
@@ -41,13 +41,6 @@ reagent canonize(reagent x) {
   return r;
 }
 
-bool has_property(reagent x, string name) {
-  for (size_t i = 0; i < x.properties.size(); ++i) {
-    if (x.properties[i].first == name) return true;
-  }
-  return false;
-}
-
 reagent deref(reagent x) {
 //?   cout << "deref: " << x.to_string() << "\n"; //? 2
   static const int ADDRESS = Type_number["address"];
@@ -117,3 +110,21 @@ recipe main [
 
 :(after "reagent base = " following "case GET_ADDRESS:")
 base = canonize(base);
+
+//:: helpers
+
+:(code)
+bool has_property(reagent x, string name) {
+  for (size_t i = 0; i < x.properties.size(); ++i) {
+    if (x.properties[i].first == name) return true;
+  }
+  return false;
+}
+
+vector<string> property(const reagent& r, const string& name) {
+  for (size_t p = 0; p != r.properties.size(); ++p) {
+    if (r.properties[p].first == name)
+      return r.properties[p].second;
+  }
+  return vector<string>();
+}
diff --git a/cpp/041name.cc b/cpp/041name.cc
index 20d1222f..9336ae04 100644
--- a/cpp/041name.cc
+++ b/cpp/041name.cc
@@ -31,8 +31,8 @@ for (size_t i = 0; i < recently_added_recipes.size(); ++i) {
 void transform_names(const recipe_number r) {
   map<string, int>& names = Name[r];
   int curr_idx = 1;
-//?   cout << "Recipe " << r << '\n'; //? 2
-//?   cout << Recipe[r].steps.size(); //? 1
+//?   cout << "Recipe " << r << ": " << Recipe[r].name << '\n'; //? 3
+//?   cout << Recipe[r].steps.size() << '\n'; //? 2
   for (size_t i = 0; i < Recipe[r].steps.size(); ++i) {
 //?     cout << "instruction " << i << '\n'; //? 2
     instruction& inst = Recipe[r].steps[i];
@@ -41,7 +41,8 @@ void transform_names(const recipe_number r) {
     for (size_t in = 0; in < inst.ingredients.size(); ++in) {
 //?       cout << "ingredients\n"; //? 2
       if (is_raw(inst.ingredients[in])) continue;
-//?       cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 2
+//?       cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 3
+//?       cout << "ingredient " << inst.ingredients[in].to_string() << '\n'; //? 1
       if (inst.ingredients[in].name == "default-space")
         inst.ingredients[in].initialized = true;
       assert(!inst.ingredients[in].types.empty());
diff --git a/cpp/054closure_name.cc b/cpp/054closure_name.cc
index b6ba686a..b13b4c21 100644
--- a/cpp/054closure_name.cc
+++ b/cpp/054closure_name.cc
@@ -71,14 +71,6 @@ void collect_surrounding_spaces(const recipe_number r) {
   }
 }
 
-vector<string> property(const reagent& r, const string& name) {
-  for (size_t p = 0; p != r.properties.size(); ++p) {
-    if (r.properties[p].first == name)
-      return r.properties[p].second;
-  }
-  return vector<string>();
-}
-
 //: Once surrounding spaces are available, transform_names uses them to handle
 //: /space properties.
 
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index 872b4d9d..8a107fc0 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -267,6 +267,7 @@ list<Line>::iterator balancing_curly(list<Line>::iterator curr) {
 //  followed by a return value ('=>')
 //  followed by one or more lines expected in trace in order ('+')
 //  followed by one or more lines trace shouldn't include ('-')
+//  followed by one or more lines expressing counts of specific layers emitted in trace ('$')
 // Remember to update is_input below if you add to this format.
 void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
   Line tmp;
@@ -294,6 +295,18 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
       result.push_back(expected_not_in_trace(front(lines)));
       lines.pop_front();
     }
+    if (!lines.empty() && front(lines).contents[0] == '$') {
+      const string& in = front(lines).contents;
+      size_t pos = in.find(": ");
+      string layer = in.substr(1, pos-1);
+      string count = in.substr(pos+2);
+      Line tmp;
+      tmp.line_number = front(lines).line_number;
+      tmp.filename = front(lines).filename;
+      tmp.contents = "  CHECK_EQ(trace_count(\""+layer+"\"), "+count+");";
+      result.push_back(tmp);
+      lines.pop_front();
+    }
     if (!lines.empty() && front(lines).contents == "===") {
       Line tmp;
       tmp.line_number = front(lines).line_number;
@@ -330,7 +343,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
 
 bool is_input(const string& line) {
   if (line.empty()) return true;
-  return line != "===" && line[0] != '+' && line[0] != '-' && !starts_with(line, "=>");
+  return line != "===" && line[0] != '+' && line[0] != '-' && !starts_with(line, "=>") && line[0] != '$' && line[0] != '?';
 }
 
 Line input_lines(list<Line>& hunk) {
diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc
index d97981dc..ea1b9c2b 100644
--- a/cpp/tangle/030tangle.test.cc
+++ b/cpp/tangle/030tangle.test.cc
@@ -280,6 +280,17 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios2() {
   CHECK(lines.empty());
 }
 
+void test_tangle_can_check_for_count_in_scenario() {
+  istringstream in(":(scenario does_bar)\nabc def\n  efg\n$layer1: 2");
+  list<Line> lines;
+  tangle(in, lines);
+  CHECK_EQ(lines.front().contents, "TEST(does_bar)");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  run(\"abc def\\n  efg\\n\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_EQ(trace_count(\"layer1\"), 2);");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
+  CHECK(lines.empty());
+}
+
 
 
 void test_trim() {