about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--011load.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/011load.cc b/011load.cc
index fceaff83..47829b04 100644
--- a/011load.cc
+++ b/011load.cc
@@ -122,7 +122,6 @@ bool next_instruction(istream& in, instruction* curr) {
   vector<string>::iterator p = words.begin();
   if (find(words.begin(), words.end(), "<-") != words.end()) {
     for (; *p != "<-"; ++p) {
-      if (*p == ",") continue;
       curr->products.push_back(reagent(*p));
     }
     ++p;  // skip <-
@@ -143,7 +142,6 @@ bool next_instruction(istream& in, instruction* curr) {
   curr->operation = Recipe_ordinal[*p];  ++p;
 
   for (; p != words.end(); ++p) {
-    if (*p == ",") continue;
     curr->ingredients.push_back(reagent(*p));
   }
 
@@ -163,6 +161,7 @@ bool next_instruction(istream& in, instruction* curr) {
 
 string next_word(istream& in) {
   skip_whitespace(in);
+  skip_ignored_characters(in);
   // End next_word Special-cases
   ostringstream out;
   slurp_word(in, out);
@@ -171,16 +170,20 @@ string next_word(istream& in) {
   return out.str();
 }
 
+:(before "End Globals")
+// word boundaries
+string Terminators("(){}");
+string Ignore(",");  // meaningless except within [] strings
+:(code)
 void slurp_word(istream& in, ostream& out) {
-  static string terminators(",()[]{}");
   char c;
-  if (!in.eof() && terminators.find(in.peek()) != string::npos) {
+  if (!in.eof() && Terminators.find(in.peek()) != string::npos) {
     in >> c;
     out << c;
     return;
   }
   while (in >> c) {
-    if (isspace(c) || terminators.find(c) != string::npos) {
+    if (isspace(c) || Terminators.find(c) != string::npos || Ignore.find(c) != string::npos) {
       in.putback(c);
       break;
     }
@@ -188,6 +191,12 @@ void slurp_word(istream& in, ostream& out) {
   }
 }
 
+void skip_ignored_characters(istream& in) {
+  while (isspace(in.peek()) || Ignore.find(in.peek()) != string::npos) {
+    in.get();
+  }
+}
+
 void skip_whitespace_and_comments(istream& in) {
   while (true) {
     if (in.eof()) break;