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