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 |
| 46 | #endif |
Roger Meier | 3b771a1 | 2010-11-17 22:11:26 +0000 | [diff] [blame] | 47 | |
Jens Geyer | 8cd3efe | 2013-09-16 22:17:52 +0200 | [diff] [blame] | 48 | #include <cassert> |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 49 | #include <string> |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 50 | #include <errno.h> |
Roger Meier | 9212e79 | 2012-06-12 21:01:06 +0000 | [diff] [blame] | 51 | #include <stdlib.h> |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 52 | |
Ben Craig | e957675 | 2013-10-11 08:19:16 -0500 | [diff] [blame] | 53 | #ifdef _MSC_VER |
| 54 | #include "windows/config.h" |
| 55 | #endif |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 56 | #include "main.h" |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 57 | #include "globals.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 58 | #include "parse/t_program.h" |
| 59 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Must be included AFTER parse/t_program.h, but I can't remember why anymore |
| 62 | * because I wrote this a while ago. |
| 63 | */ |
jfarrell | 92f24b2 | 2013-08-17 15:47:13 -0400 | [diff] [blame] | 64 | #include "thrifty.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 65 | |
Mark Slee | f12865a | 2007-01-12 00:23:26 +0000 | [diff] [blame] | 66 | void thrift_reserved_keyword(char* keyword) { |
| 67 | yyerror("Cannot use reserved language keyword: \"%s\"\n", keyword); |
| 68 | exit(1); |
| 69 | } |
| 70 | |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 71 | void integer_overflow(char* text) { |
| 72 | yyerror("This integer is too big: \"%s\"\n", text); |
| 73 | exit(1); |
| 74 | } |
| 75 | |
Bryan Duxbury | 235f8b5 | 2011-08-19 18:27:47 +0000 | [diff] [blame] | 76 | void unexpected_token(char* text) { |
| 77 | yyerror("Unexpected token in input: \"%s\"\n", text); |
| 78 | exit(1); |
| 79 | } |
| 80 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 81 | %} |
| 82 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 83 | /** |
| 84 | * Provides the yylineno global, useful for debugging output |
| 85 | */ |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 86 | %option lex-compat |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 87 | |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame] | 88 | /** |
David Reiss | 4563acd | 2010-08-31 16:51:29 +0000 | [diff] [blame] | 89 | * Our inputs are all single files, so no need for yywrap |
| 90 | */ |
| 91 | %option noyywrap |
| 92 | |
| 93 | /** |
Christian Lavoie | 77215d8 | 2010-11-07 19:42:48 +0000 | [diff] [blame] | 94 | * We don't use it, and it fires up warnings at -Wall |
| 95 | */ |
| 96 | %option nounput |
| 97 | |
| 98 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 99 | * Helper definitions, comments, constants, and whatnot |
| 100 | */ |
| 101 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 102 | intconstant ([+-]?[0-9]+) |
| 103 | hexconstant ("0x"[0-9A-Fa-f]+) |
| 104 | dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?) |
Carl Yeksigian | de07408 | 2013-06-04 04:28:31 -0400 | [diff] [blame] | 105 | 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] | 106 | whitespace ([ \t\r\n]*) |
| 107 | sillycomm ("/*""*"*"*/") |
| 108 | multicomm ("/*"[^*]"/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") |
| 109 | doctext ("/**"([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") |
| 110 | comment ("//"[^\n]*) |
| 111 | unixcomment ("#"[^\n]*) |
| 112 | symbol ([:;\,\{\}\(\)\=<>\[\]]) |
Carl Yeksigian | de07408 | 2013-06-04 04:28:31 -0400 | [diff] [blame] | 113 | st_identifier ([a-zA-Z-](\.[a-zA-Z_0-9-]|[a-zA-Z_0-9-])*) |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 114 | literal_begin (['\"]) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 115 | |
| 116 | %% |
| 117 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 118 | {whitespace} { /* do nothing */ } |
| 119 | {sillycomm} { /* do nothing */ } |
| 120 | {multicomm} { /* do nothing */ } |
| 121 | {comment} { /* do nothing */ } |
| 122 | {unixcomment} { /* do nothing */ } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 123 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 124 | {symbol} { return yytext[0]; } |
Roger Meier | 0c3c895 | 2011-08-22 21:38:16 +0000 | [diff] [blame] | 125 | "*" { return yytext[0]; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 126 | |
Bryan Duxbury | 6c928f3 | 2011-10-13 21:32:52 +0000 | [diff] [blame] | 127 | "false" { yylval.iconst=0; return tok_int_constant; } |
| 128 | "true" { yylval.iconst=1; return tok_int_constant; } |
| 129 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 130 | "namespace" { return tok_namespace; } |
| 131 | "cpp_namespace" { return tok_cpp_namespace; } |
| 132 | "cpp_include" { return tok_cpp_include; } |
| 133 | "cpp_type" { return tok_cpp_type; } |
| 134 | "java_package" { return tok_java_package; } |
| 135 | "cocoa_prefix" { return tok_cocoa_prefix; } |
David Reiss | 7f42bcf | 2008-01-11 20:59:12 +0000 | [diff] [blame] | 136 | "csharp_namespace" { return tok_csharp_namespace; } |
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 137 | "delphi_namespace" { return tok_delphi_namespace; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 138 | "php_namespace" { return tok_php_namespace; } |
| 139 | "py_module" { return tok_py_module; } |
| 140 | "perl_package" { return tok_perl_package; } |
| 141 | "ruby_namespace" { return tok_ruby_namespace; } |
| 142 | "smalltalk_category" { return tok_smalltalk_category; } |
David Reiss | 15457c9 | 2007-12-14 07:03:03 +0000 | [diff] [blame] | 143 | "smalltalk_prefix" { return tok_smalltalk_prefix; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 144 | "xsd_all" { return tok_xsd_all; } |
| 145 | "xsd_optional" { return tok_xsd_optional; } |
| 146 | "xsd_nillable" { return tok_xsd_nillable; } |
| 147 | "xsd_namespace" { return tok_xsd_namespace; } |
| 148 | "xsd_attrs" { return tok_xsd_attrs; } |
| 149 | "include" { return tok_include; } |
| 150 | "void" { return tok_void; } |
| 151 | "bool" { return tok_bool; } |
| 152 | "byte" { return tok_byte; } |
| 153 | "i16" { return tok_i16; } |
| 154 | "i32" { return tok_i32; } |
| 155 | "i64" { return tok_i64; } |
| 156 | "double" { return tok_double; } |
| 157 | "string" { return tok_string; } |
| 158 | "binary" { return tok_binary; } |
Jens Geyer | 0ca234f | 2013-06-04 22:01:47 +0200 | [diff] [blame] | 159 | "slist" { |
| 160 | pwarning(0, "\"slist\" is deprecated and will be removed in a future compiler version. This type should be replaced with \"string\".\n"); |
| 161 | return tok_slist; |
| 162 | } |
Carl Yeksigian | c317852 | 2013-06-07 12:31:13 -0400 | [diff] [blame] | 163 | "senum" { |
| 164 | pwarning(0, "\"senum\" is deprecated and will be removed in a future compiler version. This type should be replaced with \"string\".\n"); |
| 165 | return tok_senum; |
| 166 | } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 167 | "map" { return tok_map; } |
| 168 | "list" { return tok_list; } |
| 169 | "set" { return tok_set; } |
David Reiss | cecbed8 | 2009-03-24 20:02:22 +0000 | [diff] [blame] | 170 | "oneway" { return tok_oneway; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 171 | "typedef" { return tok_typedef; } |
| 172 | "struct" { return tok_struct; } |
Bryan Duxbury | ab3666e | 2009-09-01 23:03:47 +0000 | [diff] [blame] | 173 | "union" { return tok_union; } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 174 | "exception" { return tok_xception; } |
| 175 | "extends" { return tok_extends; } |
| 176 | "throws" { return tok_throws; } |
| 177 | "service" { return tok_service; } |
| 178 | "enum" { return tok_enum; } |
| 179 | "const" { return tok_const; } |
| 180 | "required" { return tok_required; } |
| 181 | "optional" { return tok_optional; } |
David Reiss | cecbed8 | 2009-03-24 20:02:22 +0000 | [diff] [blame] | 182 | "async" { |
| 183 | pwarning(0, "\"async\" is deprecated. It is called \"oneway\" now.\n"); |
| 184 | return tok_oneway; |
| 185 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 186 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 187 | |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 188 | "BEGIN" { thrift_reserved_keyword(yytext); } |
| 189 | "END" { thrift_reserved_keyword(yytext); } |
| 190 | "__CLASS__" { thrift_reserved_keyword(yytext); } |
| 191 | "__DIR__" { thrift_reserved_keyword(yytext); } |
| 192 | "__FILE__" { thrift_reserved_keyword(yytext); } |
| 193 | "__FUNCTION__" { thrift_reserved_keyword(yytext); } |
| 194 | "__LINE__" { thrift_reserved_keyword(yytext); } |
| 195 | "__METHOD__" { thrift_reserved_keyword(yytext); } |
| 196 | "__NAMESPACE__" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 197 | "abstract" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 198 | "alias" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 199 | "and" { thrift_reserved_keyword(yytext); } |
Mark Slee | c27fc31 | 2007-12-21 23:52:19 +0000 | [diff] [blame] | 200 | "args" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 201 | "as" { thrift_reserved_keyword(yytext); } |
| 202 | "assert" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 203 | "begin" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 204 | "break" { thrift_reserved_keyword(yytext); } |
| 205 | "case" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 206 | "catch" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 207 | "class" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 208 | "clone" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 209 | "continue" { thrift_reserved_keyword(yytext); } |
| 210 | "declare" { thrift_reserved_keyword(yytext); } |
| 211 | "def" { thrift_reserved_keyword(yytext); } |
| 212 | "default" { thrift_reserved_keyword(yytext); } |
| 213 | "del" { thrift_reserved_keyword(yytext); } |
| 214 | "delete" { thrift_reserved_keyword(yytext); } |
| 215 | "do" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 216 | "dynamic" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 217 | "elif" { thrift_reserved_keyword(yytext); } |
| 218 | "else" { thrift_reserved_keyword(yytext); } |
| 219 | "elseif" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 220 | "elsif" { thrift_reserved_keyword(yytext); } |
| 221 | "end" { thrift_reserved_keyword(yytext); } |
| 222 | "enddeclare" { thrift_reserved_keyword(yytext); } |
| 223 | "endfor" { thrift_reserved_keyword(yytext); } |
| 224 | "endforeach" { thrift_reserved_keyword(yytext); } |
| 225 | "endif" { thrift_reserved_keyword(yytext); } |
| 226 | "endswitch" { thrift_reserved_keyword(yytext); } |
| 227 | "endwhile" { thrift_reserved_keyword(yytext); } |
| 228 | "ensure" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 229 | "except" { thrift_reserved_keyword(yytext); } |
| 230 | "exec" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 231 | "finally" { thrift_reserved_keyword(yytext); } |
| 232 | "float" { thrift_reserved_keyword(yytext); } |
| 233 | "for" { thrift_reserved_keyword(yytext); } |
| 234 | "foreach" { thrift_reserved_keyword(yytext); } |
| 235 | "function" { thrift_reserved_keyword(yytext); } |
| 236 | "global" { thrift_reserved_keyword(yytext); } |
| 237 | "goto" { thrift_reserved_keyword(yytext); } |
| 238 | "if" { thrift_reserved_keyword(yytext); } |
| 239 | "implements" { thrift_reserved_keyword(yytext); } |
| 240 | "import" { thrift_reserved_keyword(yytext); } |
| 241 | "in" { thrift_reserved_keyword(yytext); } |
| 242 | "inline" { thrift_reserved_keyword(yytext); } |
| 243 | "instanceof" { thrift_reserved_keyword(yytext); } |
| 244 | "interface" { thrift_reserved_keyword(yytext); } |
| 245 | "is" { thrift_reserved_keyword(yytext); } |
| 246 | "lambda" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 247 | "module" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 248 | "native" { thrift_reserved_keyword(yytext); } |
| 249 | "new" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 250 | "next" { thrift_reserved_keyword(yytext); } |
| 251 | "nil" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 252 | "not" { thrift_reserved_keyword(yytext); } |
| 253 | "or" { thrift_reserved_keyword(yytext); } |
| 254 | "pass" { thrift_reserved_keyword(yytext); } |
| 255 | "public" { thrift_reserved_keyword(yytext); } |
| 256 | "print" { thrift_reserved_keyword(yytext); } |
| 257 | "private" { thrift_reserved_keyword(yytext); } |
| 258 | "protected" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 259 | "public" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 260 | "raise" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 261 | "redo" { thrift_reserved_keyword(yytext); } |
| 262 | "rescue" { thrift_reserved_keyword(yytext); } |
| 263 | "retry" { thrift_reserved_keyword(yytext); } |
Mark Slee | f5a0b3d | 2009-08-13 19:21:40 +0000 | [diff] [blame] | 264 | "register" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 265 | "return" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 266 | "self" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 267 | "sizeof" { thrift_reserved_keyword(yytext); } |
| 268 | "static" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 269 | "super" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 270 | "switch" { thrift_reserved_keyword(yytext); } |
| 271 | "synchronized" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 272 | "then" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 273 | "this" { thrift_reserved_keyword(yytext); } |
| 274 | "throw" { thrift_reserved_keyword(yytext); } |
| 275 | "transient" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 276 | "try" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 277 | "undef" { thrift_reserved_keyword(yytext); } |
| 278 | "union" { thrift_reserved_keyword(yytext); } |
| 279 | "unless" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 280 | "unsigned" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 281 | "until" { thrift_reserved_keyword(yytext); } |
| 282 | "use" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 283 | "var" { thrift_reserved_keyword(yytext); } |
| 284 | "virtual" { thrift_reserved_keyword(yytext); } |
| 285 | "volatile" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 286 | "when" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 287 | "while" { thrift_reserved_keyword(yytext); } |
| 288 | "with" { thrift_reserved_keyword(yytext); } |
Bryan Duxbury | 7f3285e | 2010-08-05 23:28:14 +0000 | [diff] [blame] | 289 | "xor" { thrift_reserved_keyword(yytext); } |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 290 | "yield" { thrift_reserved_keyword(yytext); } |
Mark Slee | f12865a | 2007-01-12 00:23:26 +0000 | [diff] [blame] | 291 | |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 292 | {intconstant} { |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 293 | errno = 0; |
| 294 | yylval.iconst = strtoll(yytext, NULL, 10); |
| 295 | if (errno == ERANGE) { |
| 296 | integer_overflow(yytext); |
| 297 | } |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 298 | return tok_int_constant; |
| 299 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 300 | |
Mark Slee | 600cdb3 | 2006-11-29 22:06:42 +0000 | [diff] [blame] | 301 | {hexconstant} { |
David Reiss | f145416 | 2008-06-30 20:45:47 +0000 | [diff] [blame] | 302 | errno = 0; |
| 303 | yylval.iconst = strtoll(yytext+2, NULL, 16); |
| 304 | if (errno == ERANGE) { |
| 305 | integer_overflow(yytext); |
| 306 | } |
Mark Slee | 600cdb3 | 2006-11-29 22:06:42 +0000 | [diff] [blame] | 307 | return tok_int_constant; |
| 308 | } |
| 309 | |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 310 | {dubconstant} { |
| 311 | yylval.dconst = atof(yytext); |
| 312 | return tok_dub_constant; |
| 313 | } |
| 314 | |
Mark Slee | 4f8da1d | 2006-10-12 02:47:27 +0000 | [diff] [blame] | 315 | {identifier} { |
| 316 | yylval.id = strdup(yytext); |
| 317 | return tok_identifier; |
| 318 | } |
| 319 | |
Mark Slee | bd58822 | 2007-11-21 08:43:35 +0000 | [diff] [blame] | 320 | {st_identifier} { |
| 321 | yylval.id = strdup(yytext); |
| 322 | return tok_st_identifier; |
| 323 | } |
| 324 | |
David Reiss | 82e6fc0 | 2009-03-26 23:32:36 +0000 | [diff] [blame] | 325 | {literal_begin} { |
| 326 | char mark = yytext[0]; |
| 327 | std::string result; |
| 328 | for(;;) |
| 329 | { |
| 330 | int ch = yyinput(); |
| 331 | switch (ch) { |
| 332 | case EOF: |
| 333 | yyerror("End of file while read string at %d\n", yylineno); |
| 334 | exit(1); |
| 335 | case '\n': |
| 336 | yyerror("End of line while read string at %d\n", yylineno - 1); |
| 337 | exit(1); |
| 338 | case '\\': |
| 339 | ch = yyinput(); |
| 340 | switch (ch) { |
| 341 | case 'r': |
| 342 | result.push_back('\r'); |
| 343 | continue; |
| 344 | case 'n': |
| 345 | result.push_back('\n'); |
| 346 | continue; |
| 347 | case 't': |
| 348 | result.push_back('\t'); |
| 349 | continue; |
| 350 | case '"': |
| 351 | result.push_back('"'); |
| 352 | continue; |
| 353 | case '\'': |
| 354 | result.push_back('\''); |
| 355 | continue; |
| 356 | case '\\': |
| 357 | result.push_back('\\'); |
| 358 | continue; |
| 359 | default: |
| 360 | yyerror("Bad escape character\n"); |
| 361 | return -1; |
| 362 | } |
| 363 | break; |
| 364 | default: |
| 365 | if (ch == mark) { |
| 366 | yylval.id = strdup(result.c_str()); |
| 367 | return tok_literal; |
| 368 | } else { |
| 369 | result.push_back(ch); |
| 370 | } |
| 371 | } |
| 372 | } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 375 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 376 | {doctext} { |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 377 | /* This does not show up in the parse tree. */ |
| 378 | /* Rather, the parser will grab it out of the global. */ |
| 379 | if (g_parse_mode == PROGRAM) { |
| 380 | clear_doctext(); |
| 381 | g_doctext = strdup(yytext + 3); |
Jens Geyer | 8cd3efe | 2013-09-16 22:17:52 +0200 | [diff] [blame] | 382 | assert(strlen(g_doctext) >= 2); |
| 383 | g_doctext[strlen(g_doctext) - 2] = ' '; |
| 384 | g_doctext[strlen(g_doctext) - 1] = '\0'; |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 385 | g_doctext = clean_up_doctext(g_doctext); |
| 386 | g_doctext_lineno = yylineno; |
| 387 | } |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Bryan Duxbury | 235f8b5 | 2011-08-19 18:27:47 +0000 | [diff] [blame] | 390 | . { |
| 391 | unexpected_token(yytext); |
| 392 | } |
| 393 | |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame] | 394 | |
David Reiss | fb790d7 | 2010-09-02 16:41:45 +0000 | [diff] [blame] | 395 | . { |
| 396 | /* Catch-all to let us catch "*" in the parser. */ |
| 397 | return (int) yytext[0]; |
| 398 | } |
| 399 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 400 | %% |
David Reiss | 4a05434 | 2009-03-26 23:32:27 +0000 | [diff] [blame] | 401 | |
| 402 | /* vim: filetype=lex |
| 403 | */ |