From fe263c523acdc48c3232afbdf8c2adb41cd4f337 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 6 Apr 2015 10:20:54 -0700 Subject: 1021 - extensible top-level command handler loop --- cpp/011load | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cpp/011load b/cpp/011load index 6479b667..cffcc551 100644 --- a/cpp/011load +++ b/cpp/011load @@ -13,18 +13,20 @@ vector add_recipes(string form) { istringstream in(form); in >> std::noskipws; vector result; - while (!in.eof()) - result.push_back(add_recipe(in)); + while (!in.eof()) { + skip_comments_and_newlines(in); + if (in.eof()) break; + string command = next_word(in); + // Command Handlers + if (command == "recipe") + result.push_back(add_recipe(in)); + // End Command Handlers + } return result; } recipe_number add_recipe(istream& in) { skip_comments_and_newlines(in); - string _recipe = next_word(in); -//? cout << _recipe; //? 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: ^" << recipe_name << "$\n"; //? 1 if (recipe_name.empty()) -- cgit 1.4.1-2-gfad0