about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-09 01:30:02 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-09 01:31:05 -0800
commit4135fcd978395bb688cc7582224d676b4b16ff8f (patch)
tree4e1f95a3ba709ba4b4ce78570bcb3362a18e49f6
parent0c0bc3aebb9f20113fc6b15180f94ed0073e96cc (diff)
downloadmu-4135fcd978395bb688cc7582224d676b4b16ff8f.tar.gz
2407 - bugfix: parsing recipe headers
-rw-r--r--011load.cc4
-rw-r--r--056recipe_header.cc28
2 files changed, 29 insertions, 3 deletions
diff --git a/011load.cc b/011load.cc
index e1f31413..b318e88a 100644
--- a/011load.cc
+++ b/011load.cc
@@ -43,6 +43,7 @@ vector<recipe_ordinal> load(istream& in) {
 long long int slurp_recipe(istream& in) {
   recipe result;
   result.name = next_word(in);
+  skip_whitespace_and_comments(in);
   // End recipe Refinements
   if (result.name.empty())
     raise_error << "empty result.name\n" << end();
@@ -66,7 +67,7 @@ long long int slurp_recipe(istream& in) {
 
 void slurp_body(istream& in, recipe& result) {
   in >> std::noskipws;
-  skip_whitespace(in);
+  skip_whitespace_and_comments(in);
   if (in.get() != '[')
     raise_error << "recipe body must begin with '['\n" << end();
   skip_whitespace_and_comments(in);
@@ -199,6 +200,7 @@ void skip_whitespace_and_comments(istream& in) {
   while (true) {
     if (in.eof()) break;
     if (isspace(in.peek())) in.get();
+    else if (in.peek() == ',') in.get();
     else if (in.peek() == '#') skip_comment(in);
     else break;
   }
diff --git a/056recipe_header.cc b/056recipe_header.cc
index 66e5217b..e6a83383 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -37,17 +37,41 @@ void load_recipe_header(istream& in, recipe& result) {
     if (s == "->") break;
     result.ingredients.push_back(reagent(s));
     trace(9999, "parse") << "header ingredient: " << result.ingredients.back().original_string << end();
-    skip_whitespace(in);
+    skip_whitespace_and_comments(in);
   }
   while (in.peek() != '[') {
     string s = next_word(in);
     result.products.push_back(reagent(s));
     trace(9999, "parse") << "header product: " << result.products.back().original_string << end();
-    skip_whitespace(in);
+    skip_whitespace_and_comments(in);
   }
   // End Load Recipe Header(result)
 }
 
+:(scenario recipe_handles_stray_comma)
+recipe main [
+  1:number/raw <- add2 3, 5
+]
+recipe add2 x:number, y:number -> z:number, [
+  local-scope
+  load-ingredients
+  z:number <- add x, y
+  reply z
+]
++mem: storing 8 in location 1
+
+:(scenario recipe_handles_stray_comma_2)
+recipe main [
+  foo
+]
+recipe foo, [
+  1:number/raw <- add 2, 2
+]
+recipe bar [
+  1:number/raw <- add 2, 3
+]
++mem: storing 4 in location 1
+
 //: If a recipe never mentions any ingredients or products, assume it has a header.
 
 :(scenario recipe_without_ingredients_or_products_has_header)