about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/002main.cc30
-rw-r--r--cpp/002main.test.cc2
2 files changed, 31 insertions, 1 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc
index c2baea50..cb0ed411 100644
--- a/cpp/002main.cc
+++ b/cpp/002main.cc
@@ -142,6 +142,36 @@ void setup_types() {
 }
 
 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 next_word(istream& in) {
+  ostringstream out;
+  skip_whitespace(in);
+  slurp_word(in, out);
+//?   cout << out.str() << '\n'; //? 1
+  return out.str();
+}
+
+void slurp_word(istream& in, ostream& out) {
+  char c;
+  while (in >> c) {
+//?     cout << c << '\n'; //? 1
+    if (isspace(c)) {
+//?       cout << "  space\n"; //? 1
+      in.putback(c);
+      break;
+    }
+    out << c;
+  }
+}
+
+void skip_whitespace(istream& in) {
+  while (isspace(in.peek()) && in.peek() != '\n')
+    in.get();
 }
 
 
diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc
index b622828b..1f77ab39 100644
--- a/cpp/002main.test.cc
+++ b/cpp/002main.test.cc
@@ -1,5 +1,5 @@
 void test_literal() {
-  compile("function main [\n"
+  compile("recipe main [\n"
           "  1:integer <- copy 23:literal\n"
           "]\n");
   run("main");
30 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169