diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-10-28 18:19:41 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-10-28 18:26:05 -0700 |
commit | 70f70118f468b51ac14b7e992b0ec941c3a50d4d (patch) | |
tree | 07749a54af09d9bfbeb93b7b52dc4a175ed6a886 /011load.cc | |
parent | b69daf785df8dee56f851ce9d6dd38d7779a04ca (diff) | |
download | mu-70f70118f468b51ac14b7e992b0ec941c3a50d4d.tar.gz |
2306 - recipe headers
Once a student has gotten used to recipes and ingredients using the staged 'next-ingredient' approach there's no reason to avoid conventional function headers. As an added bonus we can now: a) check that all 'reply' instructions in a recipe are consistent b) deduce what to reply without needing to say so everytime c) start thinking about type parameters for recipes (generic functions!)
Diffstat (limited to '011load.cc')
-rw-r--r-- | 011load.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/011load.cc b/011load.cc index 7c7bded0..3e1766f9 100644 --- a/011load.cc +++ b/011load.cc @@ -52,27 +52,26 @@ long long int slurp_recipe(istream& in) { raise << "redefining recipe " << Recipe[Recipe_ordinal[recipe_name]].name << "\n" << end(); Recipe.erase(Recipe_ordinal[recipe_name]); } - // todo: save user-defined recipes to mu's memory - Recipe[Recipe_ordinal[recipe_name]] = slurp_body(in); - Recipe[Recipe_ordinal[recipe_name]].name = recipe_name; + recipe& result = Recipe[Recipe_ordinal[recipe_name]]; + result.name = recipe_name; + slurp_body(in, result); // track added recipes because we may need to undo them in tests; see below recently_added_recipes.push_back(Recipe_ordinal[recipe_name]); return Recipe_ordinal[recipe_name]; } -recipe slurp_body(istream& in) { +void slurp_body(istream& in, recipe& result) { in >> std::noskipws; - recipe result; skip_whitespace(in); if (in.get() != '[') raise_error << "recipe body must begin with '['\n" << end(); skip_whitespace_and_comments(in); instruction curr; while (next_instruction(in, &curr)) { - // End Rewrite Instruction(curr) - result.steps.push_back(curr); + // End Rewrite Instruction(curr, recipe result) + if (!curr.is_clear()) + result.steps.push_back(curr); } - return result; } bool next_instruction(istream& in, instruction* curr) { |