about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-27 12:10:54 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-27 12:10:54 -0700
commit536a22c1b83500d4efaa7a1eae0e84ac8743b768 (patch)
treedb838699310176b800be5d1dc928b786e987b999
parent8619c61840d02568de7b5c79ee4dee660345fccc (diff)
downloadmu-536a22c1b83500d4efaa7a1eae0e84ac8743b768.tar.gz
2287 - new lexing rules
Now we always consider words to be terminated at () and {}.
We also always skip commas.
-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;