about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/002main.cc12
-rw-r--r--cpp/002main.test.cc15
2 files changed, 26 insertions, 1 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc
index 0eaea16a..ec03cf45 100644
--- a/cpp/002main.cc
+++ b/cpp/002main.cc
@@ -165,7 +165,9 @@ void setup_types() {
 }
 
 void setup_recipes() {
-  Recipe.clear();  Recipe_number.clear();  Next_recipe_number = 1;
+  Recipe.clear();  Recipe_number.clear();
+  Recipe_number["idle"] = 0;
+  Next_recipe_number = 1;
   Recipe_number["copy"] = Next_recipe_number++;
 //?   dbg << "AAA " << Recipe_number["copy"] << '\n'; //? 1
 }
@@ -220,6 +222,14 @@ bool next_instruction(istream& in, instruction* curr) {
 //?   cout << '\n'; //? 1
 //?   return true; //? 1
 
+  if (words.size() == 1 && *(words[0].end()-1) == ':') {
+    curr->is_label = true;
+    words[0].erase(words[0].end()-1);
+    curr->label = words[0];
+    trace("parse") << "label: " << curr->label;
+    return !in.eof();
+  }
+
   vector<string>::iterator p = words.begin();
   if (find(words.begin(), words.end(), "<-") != words.end()) {
 //?     cout << "instruction yields products\n"; //? 1
diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc
index 52db64bb..cc14762a 100644
--- a/cpp/002main.test.cc
+++ b/cpp/002main.test.cc
@@ -21,6 +21,21 @@ void test_parse() {
   CHECK_EQ(i->products[0].properties.size(), 0);
 }
 
+void test_parse_label() {
+  compile("recipe main [\n"
+          "  foo:\n"
+          "]\n");
+  cout << '\n'; DUMP("parse");
+  CHECK(Recipe_number.find("main") != Recipe_number.end());
+  recipe r = Recipe[Recipe_number["main"]];
+  vector<instruction>::iterator i = r.step.begin();
+  CHECK_EQ(i->is_label, true);
+  CHECK_EQ(i->label, string("foo"));
+  CHECK_EQ(i->operation, 0);
+  CHECK_EQ(i->ingredients.size(), 0);
+  CHECK_EQ(i->products.size(), 0);
+}
+
 void test_parse2() {
   compile("recipe main [\n"
           "  1:integer, 2:integer <- copy 23:literal\n"