about summary refs log tree commit diff stats
path: root/056recipe_header.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-31 21:56:17 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-31 21:56:17 -0700
commit5683823abe7c156c2e520531da9acf6e3283d41c (patch)
treed8cf8e2a8367d658d8cdcc0c750d8820e6d57d16 /056recipe_header.cc
parentb7cd91a6b407b4ab4f1365cff0cb56e48db4cb6b (diff)
downloadmu-5683823abe7c156c2e520531da9acf6e3283d41c.tar.gz
2334
Diffstat (limited to '056recipe_header.cc')
-rw-r--r--056recipe_header.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 79284ce5..477fafcd 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -48,6 +48,32 @@ void load_recipe_header(istream& in, recipe& result) {
   // End Load Recipe Header(result)
 }
 
+//: If a recipe never mentions any ingredients or products, assume it has a header.
+
+:(scenario recipe_without_ingredients_or_products_has_header)
+recipe test [
+  1:number <- copy 34
+]
++parse: recipe test has a header
+
+:(before "End recipe Body(result)")
+if (!result.has_header) {
+  result.has_header = true;
+  for (long long int i = 0; i < SIZE(result.steps); ++i) {
+    const instruction& inst = result.steps.at(i);
+    if ((inst.name == "reply" && !inst.ingredients.empty())
+        || inst.name == "next-ingredient"
+        || inst.name == "ingredient"
+        || inst.name == "rewind-ingredients") {
+      result.has_header = false;
+      break;
+    }
+  }
+}
+if (result.has_header) {
+  trace(9999, "parse") << "recipe " << result.name << " has a header" << end();
+}
+
 //: Now rewrite 'load-ingredients' to instructions to create all reagents in
 //: the header.