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