about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-09-05 09:51:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-09-05 09:53:40 -0700
commit142743726e68b74caf7d7e6454256e798ffc86c9 (patch)
tree166f594c38d499da4cc15a7591a39e55bb983dca
parent2d909c712b014539009d9910cc245ecc9aa4ab93 (diff)
downloadmu-142743726e68b74caf7d7e6454256e798ffc86c9.tar.gz
2150 - recipe! to explicitly redefine
This will let me create separate 'main' recipes at each layer so people
can interact with less featureful versions.
-rw-r--r--011load.cc62
1 files changed, 46 insertions, 16 deletions
diff --git a/011load.cc b/011load.cc
index 61d81ce0..d3455217 100644
--- a/011load.cc
+++ b/011load.cc
@@ -25,22 +25,12 @@ vector<recipe_ordinal> load(istream& in) {
     string command = next_word(in);
     // Command Handlers
     if (command == "recipe") {
-      string recipe_name = next_word(in);
-      if (recipe_name.empty())
-        raise << "empty recipe name\n" << end();
-      if (Recipe_ordinal.find(recipe_name) == Recipe_ordinal.end()) {
-        Recipe_ordinal[recipe_name] = Next_recipe_ordinal++;
-      }
-      if (warn_on_redefine(recipe_name)
-          && Recipe.find(Recipe_ordinal[recipe_name]) != Recipe.end()) {
-        raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end();
-      }
-      // todo: save user-defined recipes to mu's memory
-      Recipe[Recipe_ordinal[recipe_name]] = slurp_body(in);
-      Recipe[Recipe_ordinal[recipe_name]].name = recipe_name;
-      // track added recipes because we may need to undo them in tests; see below
-      recently_added_recipes.push_back(Recipe_ordinal[recipe_name]);
-      result.push_back(Recipe_ordinal[recipe_name]);
+      result.push_back(slurp_recipe(in));
+    }
+    else if (command == "recipe!") {
+      Disable_redefine_warnings = true;
+      result.push_back(slurp_recipe(in));
+      Disable_redefine_warnings = false;
     }
     // End Command Handlers
     else {
@@ -51,6 +41,25 @@ vector<recipe_ordinal> load(istream& in) {
   return result;
 }
 
+long long int slurp_recipe(istream& in) {
+  string recipe_name = next_word(in);
+  if (recipe_name.empty())
+    raise << "empty recipe name\n" << end();
+  if (Recipe_ordinal.find(recipe_name) == Recipe_ordinal.end()) {
+    Recipe_ordinal[recipe_name] = Next_recipe_ordinal++;
+  }
+  if (warn_on_redefine(recipe_name)
+      && Recipe.find(Recipe_ordinal[recipe_name]) != Recipe.end()) {
+    raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end();
+  }
+  // todo: save user-defined recipes to mu's memory
+  Recipe[Recipe_ordinal[recipe_name]] = slurp_body(in);
+  Recipe[Recipe_ordinal[recipe_name]].name = recipe_name;
+  // track added recipes because we may need to undo them in tests; see below
+  recently_added_recipes.push_back(Recipe_ordinal[recipe_name]);
+  return Recipe_ordinal[recipe_name];
+}
+
 recipe slurp_body(istream& in) {
   recipe result;
   skip_whitespace(in);
@@ -362,3 +371,24 @@ void test_parse_comment_terminated_by_eof() {
        "# abc");  // no newline after comment
   cerr << ".";  // termination = success
 }
+
+:(scenario warn_on_redefine)
+% Hide_warnings = true;
+recipe main [
+  1:number <- copy 23
+]
+recipe main [
+  1:number <- copy 24
+]
++warn: redefining recipe main
+
+:(scenario redefine_without_warning)
+% Hide_warnings = true;
+recipe main [
+  1:number <- copy 23
+]
+recipe! main [
+  1:number <- copy 24
+]
+-warn: redefining recipe main
+$warn: 0