about summary refs log tree commit diff stats
path: root/cpp/002main.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-16 17:08:49 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-16 17:08:49 -0800
commitf1e1cac414c34449113ca7196ceb82cbcbb2517f (patch)
tree1b5faad9841e501fee69d991497929b26c59cc15 /cpp/002main.cc
parent5963dacdb07100af6662a5b0366b3fca18e4c2fb (diff)
downloadmu-f1e1cac414c34449113ca7196ceb82cbcbb2517f.tar.gz
768
Diffstat (limited to 'cpp/002main.cc')
-rw-r--r--cpp/002main.cc28
1 files changed, 24 insertions, 4 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc
index f042dbd5..1476150c 100644
--- a/cpp/002main.cc
+++ b/cpp/002main.cc
@@ -154,13 +154,28 @@ void compile(string form) {
   istringstream in(form);
   in >> std::noskipws;
 
-  if (next_word(in) != "recipe")
-    raise << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'";
+  string _recipe = next_word(in);
+//?   cout << _recipe << '\n'; //? 1
+  if (_recipe != "recipe")
+    raise << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'\n";
 
   string recipe_name = next_word(in);
+//?   cout << '^' << recipe_name << "$\n"; //? 1
   if (recipe_name.empty())
     raise << "empty recipe name in " << form << '\n';
   int r = Recipe_number[recipe_name] = Next_recipe_number++;
+
+//?   string foo = next_word(in); //? 1
+//?   cout << '^' << foo << "$ (" << foo.size() << ")\n"; //? 1
+  if (next_word(in) != "[")
+    raise << "recipe body must begin with '['\n";
+
+  skip_newlines(in);
+
+  instruction curr;
+//?   while (next_instruction(in, &curr)) { //? 1
+//?     Recipe[r].step.push_back(curr); //? 1
+//?   } //? 1
 }
 
 bool next_instruction(istream& in, instruction* curr) {
@@ -171,8 +186,11 @@ bool next_instruction(istream& in, instruction* curr) {
 
 string next_word(istream& in) {
   ostringstream out;
+//?   cout << "1: " << (int)in.peek() << '\n'; //? 1
   skip_whitespace(in);
+//?   cout << "2: " << (int)in.peek() << '\n'; //? 1
   slurp_word(in, out);
+//?   cout << "3: " << (int)in.peek() << '\n'; //? 1
 //?   cout << out.str() << '\n'; //? 1
   return out.str();
 }
@@ -181,7 +199,7 @@ void slurp_word(istream& in, ostream& out) {
   char c;
   while (in >> c) {
 //?     cout << c << '\n'; //? 1
-    if (isspace(c) && c != '\n' && c != ',') {
+    if (isspace(c) || c == ',') {
 //?       cout << "  space\n"; //? 1
       in.putback(c);
       break;
@@ -191,8 +209,10 @@ void slurp_word(istream& in, ostream& out) {
 }
 
 void skip_whitespace(istream& in) {
-  while (isspace(in.peek()) && in.peek() != '\n')
+  while (isspace(in.peek()) && in.peek() != '\n') {
+//?     cout << "skip\n"; //? 1
     in.get();
+  }
 }
 
 void skip_newlines(istream& in) {