David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 9 | * |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /** |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 21 | * Thrift scanner. |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 22 | * |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 23 | * Tokenizes a thrift definition file. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 24 | */ |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 25 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 26 | %{ |
| 27 | |
Christian Lavoie | af65f1b | 2010-11-24 21:58:05 +0000 | [diff] [blame] | 28 | /* This is redundant with some of the flags in Makefile.am, but it works |
| 29 | * when people override CXXFLAGS without being careful. The pragmas are |
| 30 | * the 'right' way to do it, but don't work on old-enough GCC (in particular |
| 31 | * the GCC that ship on Mac OS X 10.6.5, *counter* to what the GNU docs say) |
| 32 | * |
| 33 | * We should revert the Makefile.am changes once Apple ships a reasonable |
| 34 | * GCC. |
| 35 | */ |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 36 | #ifdef __GNUC__ |
Roger Meier | 3b771a1 | 2010-11-17 22:11:26 +0000 | [diff] [blame] | 37 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 38 | #pragma GCC diagnostic ignored "-Wunused-label" |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | #ifdef _MSC_VER |
| 42 | //warning C4102: 'find_rule' : unreferenced label |
| 43 | #pragma warning(disable:4102) |
| 44 | //avoid isatty redefinition |
| 45 | #define YY_NEVER_INTERACTIVE 1 |
Roger Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 46 | |
| 47 | #define YY_NO_UNISTD_H 1 |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 48 | #endif |
Roger Meier | 3b771a1 | 2010-11-17 22:11:26 +0000 | [diff] [blame] | 49 | |
Jens Geyer | 8cd3efe | 2013-09-16 22:17:52 +0200 | [diff] [blame] | 50 | #include <cassert> |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 51 | #include <string> |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 52 | #include <errno.h> |
Roger Meier | 9212e79 | 2012-06-12 21:01:06 +0000 | [diff] [blame] | 53 | #include <stdlib.h> |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 54 | |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 55 | #ifdef _MSC_VER |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame^] | 56 | #include "thrift/windows/config.h" |
Roger Meier | 57e6de4 | 2014-07-16 10:19:59 +0200 | [diff] [blame] | 57 | #endif |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame^] | 58 | #include "thrift/main.h" |
| 59 | #include "thrift/common.h" |
| 60 | #include "thrift/globals.h" |
| 61 | #include "thrift/parse/t_program.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 62 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 63 | /** |
| 64 | * Must be included AFTER parse/t_program.h, but I can't remember why anymore |
| 65 | * because I wrote this a while ago. |
| 66 | */ |
jfarrell | 4f54d13 | 2014-07-10 09:23:43 -0400 | [diff] [blame] | 67 | #if defined(BISON_USE_PARSER_H_EXTENSION) |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame^] | 68 | #include "thrift/thrifty.h" |
jfarrell | 4f54d13 | 2014-07-10 09:23:43 -0400 | [diff] [blame] | 69 | #else |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame^] | 70 | #include "thrift/thrifty.hh" |
jfarrell | 4f54d13 | 2014-07-10 09:23:43 -0400 | [diff] [blame] | 71 | #endif |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 72 | |
Mark Slee | f12865a | 2007-01-12 00:23:26 +0000 | [diff] [blame] | 73 | void thrift_reserved_keyword(char* keyword) { |
| 74 | yyerror("Cannot use reserved language keyword: \"%s\"\n", keyword); |
| 75 | exit(1); |
| 76 | } |
| 77 | |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 78 | void integer_overflow(char* text) { |
| 79 | yyerror("This integer is too big: \"%s\"\n", text); |
| 80 | exit(1); |
| 81 | } |
| 82 | |
Bryan Duxbury | 235f8b5 | 2011-08-19 18:27:47 +0000 | [diff] [blame] | 83 | void unexpected_token(char* text) { |
| 84 | yyerror("Unexpected token in input: \"%s\"\n", text); |
| 85 | exit(1); |
| 86 | } |
| 87 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 88 | %} |
| 89 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 90 | /** |
| 91 | * Provides the yylineno global, useful for debugging output |
| 92 | */ |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 93 | %option lex-compat |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 94 | |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 95 | /** |
David Reiss | 4563acd | 2010-08-31 16:51:29 +0000 | [diff] [blame] | 96 | * Our inputs are all single files, so no need for yywrap |
| 97 | */ |
| 98 | %option noyywrap |
| 99 | |
| 100 | /** |
Christian Lavoie | 77215d8 | 2010-11-07 19:42:48 +0000 | [diff] [blame] | 101 | * We don't use it, and it fires up warnings at -Wall |
| 102 | */ |
| 103 | %option nounput |
| 104 | |
| 105 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 106 | * Helper definitions, comments, constants, and whatnot |
| 107 | */ |
| 108 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 109 | intconstant ([+-]?[0-9]+) |
Jens Geyer | 5ec2121 | 2015-04-26 15:24:59 +0200 | [diff] [blame] | 110 | hexconstant ([+-]?"0x"[0-9A-Fa-f]+) |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 111 | dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?) |
Carl Yeksigian | de07408 | 2013-06-04 04:28:31 -0400 | [diff] [blame] | 112 | identifier ([a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*) |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 113 | whitespace ([ \t\r\n]*) |
| 114 | sillycomm ("/*""*"*"*/") |
Jens Geyer | 775671a | 2016-03-06 19:02:42 +0100 | [diff] [blame] | 115 | multicm_begin ("/*") |
| 116 | doctext_begin ("/**") |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 117 | comment ("//"[^\n]*) |
| 118 | unixcomment ("#"[^\n]*) |
| 119 | symbol ([:;\,\{\}\(\)\=<>\[\]]) |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 120 | literal_begin (['\"]) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 121 | |
| 122 | %% |
| 123 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 124 | {whitespace} { /* do nothing */ } |
| 125 | {sillycomm} { /* do nothing */ } |
Jens Geyer | 775671a | 2016-03-06 19:02:42 +0100 | [diff] [blame] | 126 | |
| 127 | {doctext_begin} { |
| 128 | std::string parsed("/**"); |
| 129 | int state = 0; // 0 = normal, 1 = "*" seen, "*/" seen |
| 130 | while(state < 2) |
| 131 | { |
| 132 | int ch = yyinput(); |
| 133 | parsed.push_back(ch); |
| 134 | switch (ch) { |
| 135 | case EOF: |
| 136 | yyerror("Unexpected end of file in doc-comment at %d\n", yylineno); |
| 137 | exit(1); |
| 138 | case '*': |
| 139 | state = 1; |
| 140 | break; |
| 141 | case '/': |
| 142 | state = (state == 1) ? 2 : 0; |
| 143 | break; |
| 144 | default: |
| 145 | state = 0; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | pdebug("doctext = \"%s\"\n",parsed.c_str()); |
| 150 | |
| 151 | /* This does not show up in the parse tree. */ |
| 152 | /* Rather, the parser will grab it out of the global. */ |
| 153 | if (g_parse_mode == PROGRAM) { |
| 154 | clear_doctext(); |
| 155 | g_doctext = strdup(parsed.c_str() + 3); |
| 156 | assert(strlen(g_doctext) >= 2); |
| 157 | g_doctext[strlen(g_doctext) - 2] = ' '; |
| 158 | g_doctext[strlen(g_doctext) - 1] = '\0'; |
| 159 | g_doctext = clean_up_doctext(g_doctext); |
| 160 | g_doctext_lineno = yylineno; |
| 161 | if( (g_program_doctext_candidate == NULL) && (g_program_doctext_status == INVALID)){ |
| 162 | g_program_doctext_candidate = strdup(g_doctext); |
| 163 | g_program_doctext_lineno = g_doctext_lineno; |
| 164 | g_program_doctext_status = STILL_CANDIDATE; |
| 165 | pdebug("%s","program doctext set to STILL_CANDIDATE"); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | {multicm_begin} { /* parsed, but thrown away */ |
| 171 | std::string parsed("/*"); |
| 172 | int state = 0; // 0 = normal, 1 = "*" seen, "*/" seen |
| 173 | while(state < 2) |
| 174 | { |
| 175 | int ch = yyinput(); |
| 176 | parsed.push_back(ch); |
| 177 | switch (ch) { |
| 178 | case EOF: |
| 179 | yyerror("Unexpected end of file in multiline comment at %d\n", yylineno); |
| 180 | exit(1); |
| 181 | case '*': |
| 182 | state = 1; |
| 183 | break; |
| 184 | case '/': |
| 185 | state = (state == 1) ? 2 : 0; |
| 186 | break; |
| 187 | default: |
| 188 | state = 0; |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | pdebug("multi_comm = \"%s\"\n",parsed.c_str()); |
| 193 | } |
| 194 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 195 | {comment} { /* do nothing */ } |
| 196 | {unixcomment} { /* do nothing */ } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 197 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 198 | {symbol} { return yytext[0]; } |
Roger Meier | 0c3c895 | 2011-08-22 21:38:16 +0000 | [diff] [blame] | 199 | "*" { return yytext[0]; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 200 | |
Bryan Duxbury | 6c928f3 | 2011-10-13 21:32:52 +0000 | [diff] [blame] | 201 | "false" { yylval.iconst=0; return tok_int_constant; } |
| 202 | "true" { yylval.iconst=1; return tok_int_constant; } |
| 203 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 204 | "namespace" { return tok_namespace; } |
Jens Geyer | 7388037 | 2015-11-14 15:21:57 +0100 | [diff] [blame] | 205 | "cpp_namespace" { error_unsupported_namespace_decl("cpp"); /* do nothing */ } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 206 | "cpp_include" { return tok_cpp_include; } |
| 207 | "cpp_type" { return tok_cpp_type; } |
Jens Geyer | 7388037 | 2015-11-14 15:21:57 +0100 | [diff] [blame] | 208 | "java_package" { error_unsupported_namespace_decl("java_package", "java"); /* do nothing */ } |
| 209 | "cocoa_prefix" { error_unsupported_namespace_decl("cocoa_prefix", "cocoa"); /* do nothing */ } |
| 210 | "csharp_namespace" { error_unsupported_namespace_decl("csharp"); /* do nothing */ } |
| 211 | "delphi_namespace" { error_unsupported_namespace_decl("delphi"); /* do nothing */ } |
| 212 | "php_namespace" { error_unsupported_namespace_decl("php"); /* do nothing */ } |
| 213 | "py_module" { error_unsupported_namespace_decl("py_module", "py"); /* do nothing */ } |
| 214 | "perl_package" { error_unsupported_namespace_decl("perl_package", "perl"); /* do nothing */ } |
| 215 | "ruby_namespace" { error_unsupported_namespace_decl("ruby"); /* do nothing */ } |
| 216 | "smalltalk_category" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ } |
| 217 | "smalltalk_prefix" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 218 | "xsd_all" { return tok_xsd_all; } |
| 219 | "xsd_optional" { return tok_xsd_optional; } |
| 220 | "xsd_nillable" { return tok_xsd_nillable; } |
Jens Geyer | 7388037 | 2015-11-14 15:21:57 +0100 | [diff] [blame] | 221 | "xsd_namespace" { error_unsupported_namespace_decl("xsd"); /* do nothing */ } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 222 | "xsd_attrs" { return tok_xsd_attrs; } |
| 223 | "include" { return tok_include; } |
| 224 | "void" { return tok_void; } |
| 225 | "bool" { return tok_bool; } |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame^] | 226 | "byte" { |
Jens Geyer | 40c28d3 | 2015-10-20 23:13:02 +0200 | [diff] [blame] | 227 | emit_byte_type_warning(); |
| 228 | return tok_i8; |
| 229 | } |
| 230 | "i8" { return tok_i8; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 231 | "i16" { return tok_i16; } |
| 232 | "i32" { return tok_i32; } |
| 233 | "i64" { return tok_i64; } |
| 234 | "double" { return tok_double; } |
| 235 | "string" { return tok_string; } |
| 236 | "binary" { return tok_binary; } |
Jens Geyer | 0ca234f | 2013-06-04 22:01:47 +0200 | [diff] [blame] | 237 | "slist" { |
| 238 | pwarning(0, "\"slist\" is deprecated and will be removed in a future compiler version. This type should be replaced with \"string\".\n"); |
| 239 | return tok_slist; |
| 240 | } |
Carl Yeksigian | c317852 | 2013-06-07 12:31:13 -0400 | [diff] [blame] | 241 | "senum" { |
| 242 | pwarning(0, "\"senum\" is deprecated and will be removed in a future compiler version. This type should be replaced with \"string\".\n"); |
| 243 | return tok_senum; |
| 244 | } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 245 | "map" { return tok_map; } |
| 246 | "list" { return tok_list; } |
| 247 | "set" { return tok_set; } |
David Reiss | cecbed8 | 2009-03-24 20:02:22 +0000 | [diff] [blame] | 248 | "oneway" { return tok_oneway; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 249 | "typedef" { return tok_typedef; } |
| 250 | "struct" { return tok_struct; } |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 251 | "union" { return tok_union; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 252 | "exception" { return tok_xception; } |
| 253 | "extends" { return tok_extends; } |
| 254 | "throws" { return tok_throws; } |
| 255 | "service" { return tok_service; } |
| 256 | "enum" { return tok_enum; } |
| 257 | "const" { return tok_const; } |
| 258 | "required" { return tok_required; } |
| 259 | "optional" { return tok_optional; } |
David Reiss | cecbed8 | 2009-03-24 20:02:22 +0000 | [diff] [blame] | 260 | "async" { |
| 261 | pwarning(0, "\"async\" is deprecated. It is called \"oneway\" now.\n"); |
| 262 | return tok_oneway; |
| 263 | } |
Jens Geyer | 885c679 | 2014-05-02 21:31:55 +0200 | [diff] [blame] | 264 | "&" { return tok_reference; } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 265 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 266 | |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 267 | "BEGIN" { thrift_reserved_keyword(yytext); } |
| 268 | "END" { thrift_reserved_keyword(yytext); } |
| 269 | "__CLASS__" { thrift_reserved_keyword(yytext); } |
| 270 | "__DIR__" { thrift_reserved_keyword(yytext); } |
| 271 | "__FILE__" { thrift_reserved_keyword(yytext); } |
| 272 | "__FUNCTION__" { thrift_reserved_keyword(yytext); } |
| 273 | "__LINE__" { thrift_reserved_keyword(yytext); } |
| 274 | "__METHOD__" { thrift_reserved_keyword(yytext); } |
| 275 | "__NAMESPACE__" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 276 | "abstract" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 277 | "alias" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 278 | "and" { thrift_reserved_keyword(yytext); } |
Mark Slee | c27fc31 | 2007-12-21 23:52:19 +0000 | [diff] [blame] | 279 | "args" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 280 | "as" { thrift_reserved_keyword(yytext); } |
| 281 | "assert" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 282 | "begin" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 283 | "break" { thrift_reserved_keyword(yytext); } |
| 284 | "case" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 285 | "catch" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 286 | "class" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 287 | "clone" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 288 | "continue" { thrift_reserved_keyword(yytext); } |
| 289 | "declare" { thrift_reserved_keyword(yytext); } |
| 290 | "def" { thrift_reserved_keyword(yytext); } |
| 291 | "default" { thrift_reserved_keyword(yytext); } |
| 292 | "del" { thrift_reserved_keyword(yytext); } |
| 293 | "delete" { thrift_reserved_keyword(yytext); } |
| 294 | "do" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 295 | "dynamic" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 296 | "elif" { thrift_reserved_keyword(yytext); } |
| 297 | "else" { thrift_reserved_keyword(yytext); } |
| 298 | "elseif" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 299 | "elsif" { thrift_reserved_keyword(yytext); } |
| 300 | "end" { thrift_reserved_keyword(yytext); } |
| 301 | "enddeclare" { thrift_reserved_keyword(yytext); } |
| 302 | "endfor" { thrift_reserved_keyword(yytext); } |
| 303 | "endforeach" { thrift_reserved_keyword(yytext); } |
| 304 | "endif" { thrift_reserved_keyword(yytext); } |
| 305 | "endswitch" { thrift_reserved_keyword(yytext); } |
| 306 | "endwhile" { thrift_reserved_keyword(yytext); } |
| 307 | "ensure" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 308 | "except" { thrift_reserved_keyword(yytext); } |
| 309 | "exec" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 310 | "finally" { thrift_reserved_keyword(yytext); } |
| 311 | "float" { thrift_reserved_keyword(yytext); } |
| 312 | "for" { thrift_reserved_keyword(yytext); } |
| 313 | "foreach" { thrift_reserved_keyword(yytext); } |
jfarrell | a1ae93f | 2015-09-24 22:57:33 -0400 | [diff] [blame] | 314 | "from" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 315 | "function" { thrift_reserved_keyword(yytext); } |
| 316 | "global" { thrift_reserved_keyword(yytext); } |
| 317 | "goto" { thrift_reserved_keyword(yytext); } |
| 318 | "if" { thrift_reserved_keyword(yytext); } |
| 319 | "implements" { thrift_reserved_keyword(yytext); } |
| 320 | "import" { thrift_reserved_keyword(yytext); } |
| 321 | "in" { thrift_reserved_keyword(yytext); } |
| 322 | "inline" { thrift_reserved_keyword(yytext); } |
| 323 | "instanceof" { thrift_reserved_keyword(yytext); } |
| 324 | "interface" { thrift_reserved_keyword(yytext); } |
| 325 | "is" { thrift_reserved_keyword(yytext); } |
| 326 | "lambda" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 327 | "module" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 328 | "native" { thrift_reserved_keyword(yytext); } |
| 329 | "new" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 330 | "next" { thrift_reserved_keyword(yytext); } |
| 331 | "nil" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 332 | "not" { thrift_reserved_keyword(yytext); } |
| 333 | "or" { thrift_reserved_keyword(yytext); } |
Jens Geyer | e33d165 | 2015-07-24 02:14:43 +0200 | [diff] [blame] | 334 | "package" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 335 | "pass" { thrift_reserved_keyword(yytext); } |
| 336 | "public" { thrift_reserved_keyword(yytext); } |
| 337 | "print" { thrift_reserved_keyword(yytext); } |
| 338 | "private" { thrift_reserved_keyword(yytext); } |
| 339 | "protected" { thrift_reserved_keyword(yytext); } |
| 340 | "raise" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 341 | "redo" { thrift_reserved_keyword(yytext); } |
| 342 | "rescue" { thrift_reserved_keyword(yytext); } |
| 343 | "retry" { thrift_reserved_keyword(yytext); } |
Mark Slee | f5a0b3d | 2009-08-13 19:21:40 +0000 | [diff] [blame] | 344 | "register" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 345 | "return" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 346 | "self" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 347 | "sizeof" { thrift_reserved_keyword(yytext); } |
| 348 | "static" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 349 | "super" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 350 | "switch" { thrift_reserved_keyword(yytext); } |
| 351 | "synchronized" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 352 | "then" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 353 | "this" { thrift_reserved_keyword(yytext); } |
| 354 | "throw" { thrift_reserved_keyword(yytext); } |
| 355 | "transient" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 356 | "try" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 357 | "undef" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 358 | "unless" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 359 | "unsigned" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 360 | "until" { thrift_reserved_keyword(yytext); } |
| 361 | "use" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 362 | "var" { thrift_reserved_keyword(yytext); } |
| 363 | "virtual" { thrift_reserved_keyword(yytext); } |
| 364 | "volatile" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 365 | "when" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 366 | "while" { thrift_reserved_keyword(yytext); } |
| 367 | "with" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 368 | "xor" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 369 | "yield" { thrift_reserved_keyword(yytext); } |
Mark Slee | f12865a | 2007-01-12 00:23:26 +0000 | [diff] [blame] | 370 | |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 371 | {intconstant} { |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 372 | errno = 0; |
| 373 | yylval.iconst = strtoll(yytext, NULL, 10); |
| 374 | if (errno == ERANGE) { |
| 375 | integer_overflow(yytext); |
| 376 | } |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 377 | return tok_int_constant; |
| 378 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 379 | |
Mark Slee | 600cdb3 | 2006-11-29 22:06:42 +0000 | [diff] [blame] | 380 | {hexconstant} { |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 381 | errno = 0; |
Jens Geyer | 5ec2121 | 2015-04-26 15:24:59 +0200 | [diff] [blame] | 382 | char sign = yytext[0]; |
| 383 | int shift = sign == '0' ? 2 : 3; |
| 384 | yylval.iconst = strtoll(yytext+shift, NULL, 16); |
| 385 | if (sign == '-') { |
| 386 | yylval.iconst = -yylval.iconst; |
| 387 | } |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 388 | if (errno == ERANGE) { |
| 389 | integer_overflow(yytext); |
| 390 | } |
Mark Slee | 600cdb3 | 2006-11-29 22:06:42 +0000 | [diff] [blame] | 391 | return tok_int_constant; |
| 392 | } |
| 393 | |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 394 | {identifier} { |
| 395 | yylval.id = strdup(yytext); |
| 396 | return tok_identifier; |
| 397 | } |
| 398 | |
Jens Geyer | 5eed3a1 | 2015-12-08 01:32:12 +0100 | [diff] [blame] | 399 | {dubconstant} { |
| 400 | /* Deliberately placed after identifier, since "e10" is NOT a double literal (THRIFT-3477) */ |
| 401 | yylval.dconst = atof(yytext); |
| 402 | return tok_dub_constant; |
| 403 | } |
| 404 | |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 405 | {literal_begin} { |
| 406 | char mark = yytext[0]; |
| 407 | std::string result; |
| 408 | for(;;) |
| 409 | { |
| 410 | int ch = yyinput(); |
| 411 | switch (ch) { |
| 412 | case EOF: |
| 413 | yyerror("End of file while read string at %d\n", yylineno); |
| 414 | exit(1); |
| 415 | case '\n': |
| 416 | yyerror("End of line while read string at %d\n", yylineno - 1); |
| 417 | exit(1); |
| 418 | case '\\': |
| 419 | ch = yyinput(); |
| 420 | switch (ch) { |
| 421 | case 'r': |
| 422 | result.push_back('\r'); |
| 423 | continue; |
| 424 | case 'n': |
| 425 | result.push_back('\n'); |
| 426 | continue; |
| 427 | case 't': |
| 428 | result.push_back('\t'); |
| 429 | continue; |
| 430 | case '"': |
| 431 | result.push_back('"'); |
| 432 | continue; |
| 433 | case '\'': |
| 434 | result.push_back('\''); |
| 435 | continue; |
| 436 | case '\\': |
| 437 | result.push_back('\\'); |
| 438 | continue; |
| 439 | default: |
| 440 | yyerror("Bad escape character\n"); |
| 441 | return -1; |
| 442 | } |
| 443 | break; |
| 444 | default: |
| 445 | if (ch == mark) { |
| 446 | yylval.id = strdup(result.c_str()); |
| 447 | return tok_literal; |
| 448 | } else { |
| 449 | result.push_back(ch); |
| 450 | } |
| 451 | } |
| 452 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 455 | |
Bryan Duxbury | 235f8b5 | 2011-08-19 18:27:47 +0000 | [diff] [blame] | 456 | . { |
| 457 | unexpected_token(yytext); |
| 458 | } |
| 459 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 460 | %% |
David Reiss | 4a05434 | 2009-03-26 23:32:27 +0000 | [diff] [blame] | 461 | |
| 462 | /* vim: filetype=lex |
| 463 | */ |