Thrift supports the "senum" type now

Summary: Enumerated lists of strings, enforced only in XSD

Reviewed By: xsd


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664987 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index 19f1ba8..519f20d 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -33,6 +33,7 @@
   double         dconst;
   bool           tbool;
   t_type*        ttype;
+  t_base_type*   tbase;
   t_typedef*     ttypedef;
   t_enum*        tenum;
   t_enum_value*  tenumv;
@@ -82,6 +83,7 @@
 %token tok_byte
 %token tok_string
 %token tok_slist
+%token tok_senum
 %token tok_i16
 %token tok_i32
 %token tok_i64
@@ -136,6 +138,10 @@
 %type<tenum>     EnumDefList
 %type<tenumv>    EnumDef
 
+%type<ttypedef>  Senum
+%type<tbase>     SenumDefList
+%type<id>        SenumDef
+
 %type<tconst>    Const
 %type<tconstv>   ConstValue
 %type<tconstv>   ConstList
@@ -304,6 +310,13 @@
         g_program->add_enum($1);
       }
     }
+| Senum
+    {
+      pdebug("TypeDefinition -> Senum");
+      if (g_parse_mode == PROGRAM) {
+        g_program->add_typedef($1);
+      }
+    }
 | Struct
     {
       pdebug("TypeDefinition -> Struct");
@@ -341,6 +354,13 @@
       $$ = NULL; 
     }
     
+CommaOrSemicolonOptional:
+  ','
+    {}
+| ';'
+    {}
+|
+    {}
 
 Enum:
   DocTextOptional tok_enum tok_identifier '{' EnumDefList '}'
@@ -353,14 +373,6 @@
       }
     }
 
-CommaOrSemicolonOptional:
-  ','
-    {}
-| ';'
-    {}
-|
-    {}
-
 EnumDefList:
   EnumDefList EnumDef
     {
@@ -396,6 +408,37 @@
       }
     }
 
+Senum:
+  DocTextOptional tok_senum tok_identifier '{' SenumDefList '}'
+    {
+      pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
+      $$ = new t_typedef(g_program, $5, $3);
+      if ($1 != NULL) {
+        $$->set_doc($1);
+      }
+    }
+
+SenumDefList:
+  SenumDefList SenumDef
+    {
+      pdebug("SenumDefList -> SenumDefList SenumDef");
+      $$ = $1;
+      $$->add_string_enum_val($2);
+    }
+|
+    {
+      pdebug("SenumDefList -> ");
+      $$ = new t_base_type("string", t_base_type::TYPE_STRING);
+      $$->set_string_enum(true);
+    }
+
+SenumDef:
+  tok_literal CommaOrSemicolonOptional
+    {
+      pdebug("SenumDef -> tok_literal");
+      $$ = $1;
+    }
+
 Const:
   tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
     {