about summary refs log tree commit diff stats
path: root/055shape_shifting_container.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-07-06 14:25:23 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-07-06 14:25:23 -0700
commit6b2f2ed303ceffa78a10f51bd613f19884501296 (patch)
tree9c9242dd3b37507ca1cb2f280e032e5133842404 /055shape_shifting_container.cc
parentff229aece6db9fdfcc397b7ff184e1e2b4fa1ddc (diff)
downloadmu-6b2f2ed303ceffa78a10f51bd613f19884501296.tar.gz
3104
Diffstat (limited to '055shape_shifting_container.cc')
-rw-r--r--055shape_shifting_container.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/055shape_shifting_container.cc b/055shape_shifting_container.cc
index 4c481805..ce595730 100644
--- a/055shape_shifting_container.cc
+++ b/055shape_shifting_container.cc
@@ -72,6 +72,13 @@ container foo:_b [
 ]
 +error: headers of container 'foo' must use identical type ingredients
 
+:(scenario type_ingredient_must_start_with_underscore)
+% Hide_errors = true;
+container foo:t [
+  x:number
+]
++error: foo: type ingredient 't' must begin with an underscore
+
 :(before "End Globals")
 // We'll use large type ordinals to mean "the following type of the variable".
 // For example, if we have a generic type called foo:_elem, the type
@@ -106,7 +113,7 @@ bool read_type_ingredients(string& name, const string& command) {
   istringstream in(save_name);
   name = slurp_until(in, ':');
   map<string, type_ordinal> type_ingredient_names;
-  if (!slurp_type_ingredients(in, type_ingredient_names)) {
+  if (!slurp_type_ingredients(in, type_ingredient_names, name)) {
     return false;
   }
   if (contains_key(Type_ordinal, name)
@@ -127,12 +134,20 @@ bool read_type_ingredients(string& name, const string& command) {
   return true;
 }
 
-bool slurp_type_ingredients(istream& in, map<string, type_ordinal>& out) {
+bool slurp_type_ingredients(istream& in, map<string, type_ordinal>& out, const string& container_name) {
   int next_type_ordinal = START_TYPE_INGREDIENTS;
   while (has_data(in)) {
     string curr = slurp_until(in, ':');
+    if (curr.empty()) {
+      raise << container_name << ": empty type ingredients not permitted\n" << end();
+      return false;
+    }
+    if (curr.at(0) != '_') {
+      raise << container_name << ": type ingredient '" << curr << "' must begin with an underscore\n" << end();
+      return false;
+    }
     if (out.find(curr) != out.end()) {
-      raise << "can't repeat type ingredient names in a single container definition: '" << curr << "'\n" << end();
+      raise << container_name << ": can't repeat type ingredient name'" << curr << "' in a single container definition\n" << end();
       return false;
     }
     put(out, curr, next_type_ordinal++);