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-12-02 17:11:58 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-12-02 17:11:58 -0800
commit1f7e3c056ce0ea71e1337579b24e8fd1ad26abac (patch)
treecebdec305552bdf180f3f0db5518a69c2a086857 /056recipe_header.cc
parentf8997ec06c0cdda1a16c5d99f96c447ce6809185 (diff)
downloadmu-1f7e3c056ce0ea71e1337579b24e8fd1ad26abac.tar.gz
2614 - still fixing bugs with missing '['
When skipping past some text (usually whitespace, but also commas and
comments) I need to always be aware of whether it's ok to switch to the
next line or not.
Diffstat (limited to '056recipe_header.cc')
-rw-r--r--056recipe_header.cc27
1 files changed, 24 insertions, 3 deletions
diff --git a/056recipe_header.cc b/056recipe_header.cc
index f0d448b2..2ca02af7 100644
--- a/056recipe_header.cc
+++ b/056recipe_header.cc
@@ -23,7 +23,6 @@ vector<reagent> products;
 has_header = false;
 
 :(before "End recipe Refinements")
-skip_whitespace(in);
 if (in.peek() != '[') {
   trace(9999, "parse") << "recipe has a header; parsing" << end();
   load_recipe_header(in, result);
@@ -37,17 +36,28 @@ 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_and_comments(in);
+    skip_whitespace_and_comments_but_not_newline(in);
   }
   while (has_data(in) && in.peek() != '[' && in.peek() != '\n') {
     string s = next_word(in);
     result.products.push_back(reagent(s));
     trace(9999, "parse") << "header product: " << result.products.back().original_string << end();
-    skip_whitespace_and_comments(in);
+    skip_whitespace_and_comments_but_not_newline(in);
   }
   // End Load Recipe Header(result)
 }
 
+void skip_whitespace_and_comments_but_not_newline(istream& in) {
+  while (true) {
+    if (!has_data(in)) break;
+    if (in.peek() == '\n') break;
+    if (isspace(in.peek())) in.get();
+    else if (Ignore.find(in.peek()) != string::npos) in.get();
+    else if (in.peek() == '#') skip_comment(in);
+    else break;
+  }
+}
+
 :(scenario recipe_handles_stray_comma)
 recipe main [
   1:number/raw <- add2 3, 5
@@ -78,6 +88,17 @@ recipe main
 ]
 +error: recipe body must begin with '['
 
+:(scenario recipe_handles_missing_bracket_2)
+% Hide_errors = true;
+recipe main
+  local-scope
+  {
+  }
+]
+# doesn't overflow line when reading header
+-parse: header ingredient: local-scope
++error: recipe body must begin with '['
+
 :(after "Begin debug_string(recipe x)")
 out << "ingredients:\n";
 for (long long int i = 0; i < SIZE(x.ingredients); ++i)