Disallow keywords in Thrift files

Summary: Or else you are bound to get shitty errors in some generated languages.. They're not all covered here, but a lot of them are.

Reviewed By: dougb, bobby


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664907 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/thrift.l b/compiler/cpp/src/thrift.l
index 14a9e4b..44927fa 100644
--- a/compiler/cpp/src/thrift.l
+++ b/compiler/cpp/src/thrift.l
@@ -16,6 +16,11 @@
  */
 #include "thrift.tab.hh"
 
+void thrift_reserved_keyword(char* keyword) {
+  yyerror("Cannot use reserved language keyword: \"%s\"\n", keyword);
+  exit(1);
+}
+
 %}
 
 /**
@@ -76,6 +81,72 @@
 "enum"          { return tok_enum;          }
 "const"         { return tok_const;         }
 
+"abstract" { thrift_reserved_keyword(yytext); }
+"and" { thrift_reserved_keyword(yytext); }
+"as" { thrift_reserved_keyword(yytext); }
+"assert" { thrift_reserved_keyword(yytext); }
+"break" { thrift_reserved_keyword(yytext); }
+"case" { thrift_reserved_keyword(yytext); }
+"class" { thrift_reserved_keyword(yytext); }
+"continue" { thrift_reserved_keyword(yytext); }
+"declare" { thrift_reserved_keyword(yytext); }
+"def" { thrift_reserved_keyword(yytext); }
+"default" { thrift_reserved_keyword(yytext); }
+"del" { thrift_reserved_keyword(yytext); }
+"delete" { thrift_reserved_keyword(yytext); }
+"do" { thrift_reserved_keyword(yytext); }
+"elif" { thrift_reserved_keyword(yytext); }
+"else" { thrift_reserved_keyword(yytext); }
+"elseif" { thrift_reserved_keyword(yytext); }
+"except" { thrift_reserved_keyword(yytext); }
+"exec" { thrift_reserved_keyword(yytext); }
+"false" { thrift_reserved_keyword(yytext); }
+"final" { thrift_reserved_keyword(yytext); }
+"finally" { thrift_reserved_keyword(yytext); }
+"float" { thrift_reserved_keyword(yytext); }
+"for" { thrift_reserved_keyword(yytext); }
+"foreach" { thrift_reserved_keyword(yytext); }
+"function" { thrift_reserved_keyword(yytext); }
+"global" { thrift_reserved_keyword(yytext); }
+"goto" { thrift_reserved_keyword(yytext); }
+"if" { thrift_reserved_keyword(yytext); }
+"implements" { thrift_reserved_keyword(yytext); }
+"import" { thrift_reserved_keyword(yytext); }
+"in" { thrift_reserved_keyword(yytext); }
+"inline" { thrift_reserved_keyword(yytext); }
+"instanceof" { thrift_reserved_keyword(yytext); }
+"interface" { thrift_reserved_keyword(yytext); }
+"is" { thrift_reserved_keyword(yytext); }
+"lambda" { thrift_reserved_keyword(yytext); }
+"native" { thrift_reserved_keyword(yytext); }
+"new" { thrift_reserved_keyword(yytext); }
+"not" { thrift_reserved_keyword(yytext); }
+"or" { thrift_reserved_keyword(yytext); }
+"pass" { thrift_reserved_keyword(yytext); }
+"public" { thrift_reserved_keyword(yytext); }
+"print" { thrift_reserved_keyword(yytext); }
+"private" { thrift_reserved_keyword(yytext); }
+"protected" { thrift_reserved_keyword(yytext); }
+"raise" { thrift_reserved_keyword(yytext); }
+"return" { thrift_reserved_keyword(yytext); }
+"sizeof" { thrift_reserved_keyword(yytext); }
+"static" { thrift_reserved_keyword(yytext); }
+"switch" { thrift_reserved_keyword(yytext); }
+"synchronized" { thrift_reserved_keyword(yytext); }
+"this" { thrift_reserved_keyword(yytext); }
+"throw" { thrift_reserved_keyword(yytext); }
+"transient" { thrift_reserved_keyword(yytext); }
+"true" { thrift_reserved_keyword(yytext); }
+"try" { thrift_reserved_keyword(yytext); }
+"unsigned" { thrift_reserved_keyword(yytext); }
+"var" { thrift_reserved_keyword(yytext); }
+"virtual" { thrift_reserved_keyword(yytext); }
+"volatile" { thrift_reserved_keyword(yytext); }
+"while" { thrift_reserved_keyword(yytext); }
+"with" { thrift_reserved_keyword(yytext); }
+"union" { thrift_reserved_keyword(yytext); }
+"yield" { thrift_reserved_keyword(yytext); }
+
 {intconstant} {
   yylval.iconst = atoi(yytext);
   return tok_int_constant;