Allow the specification of custom container types in Thrift IDL files
Summary: If you want your map to be a hash_map instead of an stl::map, we now have a directive in Thrift to let you do that.
Instead of:
map<i32,i32>
You can do:
map[cpp:hash_map<int32_t,int32_t>]<i32,i32>
This tells the Thrift compiler to explicitly use whatever type was specified in the brackets when generating C++ code, instead of the implied Thrift type.
Reviewed By: aditya
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664828 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrift.l b/compiler/cpp/src/thrift.l
index 64a2bf8..e72565e 100644
--- a/compiler/cpp/src/thrift.l
+++ b/compiler/cpp/src/thrift.l
@@ -34,6 +34,7 @@
comment ("//"[^\n]*)
unixcomment ("#"[^\n]*)
symbol ([\,\{\}\(\)\=<>])
+cpptype ("[cpp:".*"]")
%%
@@ -64,8 +65,21 @@
"service" { return tok_service; }
"enum" { return tok_enum; }
-{intconstant} { yylval.iconst = atoi(yytext); return tok_int_constant; }
+{intconstant} {
+ yylval.iconst = atoi(yytext);
+ return tok_int_constant;
+}
-{identifier} { yylval.id = strdup(yytext); return tok_identifier; }
+{cpptype} {
+ yylval.id = strdup(yytext+5);
+ yylval.id[strlen(yylval.id)-1] = '\0';
+ return tok_cpptype;
+}
+
+{identifier} {
+ yylval.id = strdup(yytext);
+ return tok_identifier;
+}
+
%%