[18250] | 1 | /*************************************************************************** |
---|
| 2 | |
---|
| 3 | lexer.l (IDL lex scanner) |
---|
| 4 | |
---|
| 5 | Copyright (C) 1998, 1999 Andrew T. Veliath |
---|
| 6 | |
---|
| 7 | This library is free software; you can redistribute it and/or |
---|
| 8 | modify it under the terms of the GNU Library General Public |
---|
| 9 | License as published by the Free Software Foundation; either |
---|
| 10 | version 2 of the License, or (at your option) any later version. |
---|
| 11 | |
---|
| 12 | This library is distributed in the hope that it will be useful, |
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | Library General Public License for more details. |
---|
| 16 | |
---|
| 17 | You should have received a copy of the GNU Library General Public |
---|
| 18 | License along with this library; if not, write to the Free |
---|
| 19 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 20 | |
---|
[20747] | 21 | $Id: lexer.l,v 1.1.1.2 2004-09-22 23:38:49 ghudson Exp $ |
---|
[18250] | 22 | |
---|
| 23 | ***************************************************************************/ |
---|
| 24 | %{ |
---|
| 25 | #include <assert.h> |
---|
| 26 | #include <stdio.h> |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | #include <ctype.h> |
---|
| 29 | #include <string.h> |
---|
| 30 | #include "rename.h" |
---|
| 31 | #include "util.h" |
---|
| 32 | #include "parser.h" |
---|
| 33 | |
---|
| 34 | #ifdef XP_MAC |
---|
| 35 | # include <unix.h> |
---|
| 36 | # define YY_NEVER_INTERACTIVE 1 |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /* Eliminate warning */ |
---|
| 40 | #define YY_NO_UNPUT 1 |
---|
| 41 | |
---|
| 42 | #define YY_INPUT(buf,result,the_max_size) do { \ |
---|
| 43 | if (__IDL_inputcb == NULL) { \ |
---|
| 44 | if ((result = fread (buf, 1, the_max_size, yyin)) == YY_NULL && \ |
---|
| 45 | ferror (yyin)) \ |
---|
| 46 | YY_FATAL_ERROR ("input in scanner failed"); \ |
---|
| 47 | } else { \ |
---|
| 48 | union IDL_input_data data; \ |
---|
| 49 | \ |
---|
| 50 | data.fill.buffer = buf; \ |
---|
| 51 | data.fill.max_size = the_max_size; \ |
---|
| 52 | result = (*__IDL_inputcb) (IDL_INPUT_REASON_FILL, &data, \ |
---|
| 53 | __IDL_inputcb_user_data); \ |
---|
| 54 | if (result < 0) \ |
---|
| 55 | YY_FATAL_ERROR ("input callback returned failure"); \ |
---|
| 56 | } \ |
---|
| 57 | } while (0) |
---|
| 58 | |
---|
| 59 | #define tokreturn(token) do { \ |
---|
| 60 | __IDL_prev_token_line = __IDL_cur_token_line; \ |
---|
| 61 | __IDL_cur_token_line = __IDL_cur_line; \ |
---|
| 62 | return token; \ |
---|
| 63 | } while (0) |
---|
| 64 | |
---|
| 65 | #define SELECT_START \ |
---|
| 66 | /* Parser driven start conditions */ \ |
---|
| 67 | if (__IDL_flagsi & IDLFP_PROPERTIES) \ |
---|
| 68 | BEGIN (PROP); \ |
---|
| 69 | else if (__IDL_flagsi & IDLFP_NATIVE) \ |
---|
| 70 | BEGIN (NATIVE); \ |
---|
| 71 | /* Global syntax start conditions */ \ |
---|
| 72 | else if (__IDL_flags & IDLF_XPIDL) \ |
---|
| 73 | BEGIN (XP); \ |
---|
| 74 | else if (__IDL_flags & IDLF_CODEFRAGS) \ |
---|
| 75 | BEGIN (CFRG); |
---|
| 76 | |
---|
| 77 | #define SELECT_RESTART \ |
---|
| 78 | SELECT_START \ |
---|
| 79 | else \ |
---|
| 80 | BEGIN (INITIAL); |
---|
| 81 | |
---|
| 82 | static int count_nl (const char *s); |
---|
| 83 | |
---|
| 84 | #ifdef YYDEBUG |
---|
| 85 | extern int yydebug; |
---|
| 86 | #endif |
---|
| 87 | int __IDL_prev_token_line; |
---|
| 88 | int __IDL_cur_token_line; |
---|
| 89 | static int warn_underscores; |
---|
| 90 | static char * codefrag_desc; |
---|
| 91 | static GSList * codefrag_list; |
---|
| 92 | static GSList * codefrag_list_tail; |
---|
| 93 | %} |
---|
| 94 | |
---|
| 95 | whitespace [ \t\v\f\r]* |
---|
| 96 | whitespacenl [ \t\v\f\r\n]* |
---|
| 97 | newline \n |
---|
| 98 | cpp_pragma ^{whitespace}#{whitespace}pragma{whitespace}.* |
---|
| 99 | cpp_status ^{whitespace}#{whitespace}[0-9][0-9]*.* |
---|
| 100 | cpp_other ^{whitespace}#.* |
---|
| 101 | b8_int 0[0-9]* |
---|
| 102 | b10_uint [1-9][0-9]* |
---|
| 103 | b16_int 0[xX][0-9A-Fa-f]+ |
---|
| 104 | float_lit [0-9]*\.[0-9]+([eE]-?[0-9]+)?|[0-9]+\.?([eE]-?[0-9]+)? |
---|
| 105 | fixed_lit ([0-9]*\.[0-9]+|-?[0-9]+\.?[0-9]*)[dD] |
---|
| 106 | declspec __declspec{whitespacenl}\({whitespacenl}[A-Za-z]*{whitespacenl}\) |
---|
| 107 | happy_ident [A-Za-z][A-Za-z0-9]* |
---|
[20747] | 108 | escaped_ident _[A-Za-z0-9_]+ |
---|
[18250] | 109 | warn1_ident [A-Za-z][A-Za-z0-9_]* |
---|
| 110 | prop_key [A-Za-z][A-Za-z0-9_]* |
---|
| 111 | prop_value \([^\)]+\) |
---|
| 112 | native_type [^\)]+\) |
---|
| 113 | sqstring \'[^\'\n]*[\'\n] |
---|
| 114 | dqstring \"[^\"\n]*[\"\n] |
---|
| 115 | |
---|
| 116 | %p 5000 |
---|
| 117 | |
---|
| 118 | %s XP |
---|
| 119 | |
---|
| 120 | %x PROP |
---|
| 121 | %x NATIVE |
---|
| 122 | |
---|
| 123 | %s CFRG |
---|
| 124 | %x CFRGX |
---|
| 125 | |
---|
| 126 | %% |
---|
| 127 | |
---|
| 128 | SELECT_START; |
---|
| 129 | |
---|
| 130 | <INITIAL,XP,CFRG>^%\{.* { |
---|
| 131 | char *s = yytext + 2; |
---|
| 132 | |
---|
| 133 | while (g_ascii_isspace (*s)) ++s; |
---|
| 134 | codefrag_desc = g_strdup (s); |
---|
| 135 | codefrag_list = codefrag_list_tail = NULL; |
---|
| 136 | |
---|
| 137 | if (!(__IDL_flags & IDLF_XPIDL || __IDL_flags & IDLF_CODEFRAGS)) |
---|
| 138 | yyerror ("Code fragment syntax not enabled"); |
---|
| 139 | else |
---|
| 140 | BEGIN (CFRGX); |
---|
| 141 | } |
---|
| 142 | <CFRGX>^%\}.* { |
---|
| 143 | yylval.tree = IDL_codefrag_new (codefrag_desc, codefrag_list); |
---|
| 144 | tokreturn (TOK_CODEFRAG); |
---|
| 145 | } |
---|
| 146 | <CFRGX>.* { |
---|
| 147 | char *s; |
---|
| 148 | GSList *slist; |
---|
| 149 | |
---|
| 150 | s = g_strdup (yytext); |
---|
| 151 | slist = g_slist_alloc (); |
---|
| 152 | slist->data = s; |
---|
| 153 | |
---|
| 154 | if (codefrag_list == NULL) { |
---|
| 155 | codefrag_list = slist; |
---|
| 156 | codefrag_list_tail = slist; |
---|
| 157 | } else { |
---|
| 158 | codefrag_list_tail->next = slist; |
---|
| 159 | codefrag_list_tail = slist; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | <*>{cpp_pragma} { |
---|
| 163 | int n; |
---|
| 164 | char *p = yytext; |
---|
| 165 | char *s, *t; |
---|
| 166 | |
---|
| 167 | while (g_ascii_isspace (*p) || *p == '#') ++p; |
---|
| 168 | s = p; |
---|
| 169 | sscanf (p, "%*6s%n", &n); s += n; |
---|
| 170 | while (g_ascii_isspace (*s)) ++s; |
---|
| 171 | |
---|
| 172 | t = s + strlen(s) - 1; |
---|
| 173 | while(g_ascii_isspace(*t) && t > s) *(t--) = '\0'; /* Chomp trailing spaces */ |
---|
| 174 | |
---|
| 175 | __IDL_do_pragma (s); |
---|
| 176 | } |
---|
| 177 | <*>{cpp_status} { |
---|
| 178 | gchar *mytext = yytext; |
---|
| 179 | gint line; |
---|
| 180 | |
---|
| 181 | while (g_ascii_isspace (*mytext)) |
---|
| 182 | mytext++; |
---|
| 183 | |
---|
| 184 | g_assert (mytext [0] == '#' && mytext [1] == ' '); |
---|
| 185 | |
---|
| 186 | mytext += 2; |
---|
| 187 | |
---|
| 188 | line = atoi (mytext); |
---|
| 189 | |
---|
| 190 | while (g_ascii_isdigit (*mytext)) |
---|
| 191 | mytext++; |
---|
| 192 | |
---|
| 193 | if (g_ascii_isspace (*mytext)) { |
---|
| 194 | mytext++; |
---|
| 195 | |
---|
| 196 | if (mytext [0] == '"') { |
---|
| 197 | gchar *p = ++mytext; |
---|
| 198 | |
---|
| 199 | while (*p && *p != '"') p++; |
---|
| 200 | |
---|
| 201 | *p = '\0'; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | if (mytext [0] == '<' && |
---|
| 205 | (!strcmp (mytext, "<builtin>") || |
---|
| 206 | !strcmp (mytext, "<built-in>") || |
---|
| 207 | !strcmp (mytext, "<stdin>") || |
---|
| 208 | !strcmp (mytext, "<command line>"))) |
---|
| 209 | |
---|
| 210 | yylval.tree = IDL_file_set ("", line); |
---|
| 211 | else { |
---|
| 212 | gchar *filename = g_strdup (mytext); |
---|
| 213 | |
---|
| 214 | yylval.tree = IDL_file_set (filename, line); |
---|
| 215 | |
---|
| 216 | g_free (filename); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | else |
---|
| 220 | yylval.tree = IDL_file_set ("", line); |
---|
| 221 | |
---|
| 222 | if (yylval.tree) |
---|
| 223 | tokreturn (TOK_SRCFILE); |
---|
| 224 | } |
---|
| 225 | <*>{cpp_other} ; |
---|
| 226 | <*>{whitespace} ; |
---|
| 227 | {b8_int} { |
---|
| 228 | yylval.integer = 0; |
---|
| 229 | sscanf (yytext, "%" IDL_LL "o", &yylval.integer); |
---|
| 230 | tokreturn (TOK_INTEGER); |
---|
| 231 | } |
---|
| 232 | {b10_uint} { |
---|
| 233 | yylval.integer = 0; |
---|
| 234 | sscanf (yytext, "%" IDL_LL "u", &yylval.integer); |
---|
| 235 | tokreturn (TOK_INTEGER); |
---|
| 236 | } |
---|
| 237 | {b16_int} { |
---|
| 238 | yylval.integer = 0; |
---|
| 239 | sscanf (yytext + 2, "%" IDL_LL "x", &yylval.integer); |
---|
| 240 | tokreturn (TOK_INTEGER); |
---|
| 241 | } |
---|
| 242 | {fixed_lit} { |
---|
| 243 | yylval.str = g_strdup (yytext); |
---|
| 244 | tokreturn (TOK_FIXEDP); |
---|
| 245 | } |
---|
| 246 | {float_lit} { |
---|
| 247 | yylval.floatp = atof (yytext); |
---|
| 248 | tokreturn (TOK_FLOATP); |
---|
| 249 | } |
---|
| 250 | FALSE tokreturn (TOK_FALSE); |
---|
| 251 | TRUE tokreturn (TOK_TRUE); |
---|
| 252 | any tokreturn (TOK_ANY); |
---|
| 253 | attribute tokreturn (TOK_ATTRIBUTE); |
---|
| 254 | boolean tokreturn (TOK_BOOLEAN); |
---|
| 255 | case tokreturn (TOK_CASE); |
---|
| 256 | char tokreturn (TOK_CHAR); |
---|
| 257 | const tokreturn (TOK_CONST); |
---|
| 258 | context tokreturn (TOK_CONTEXT); |
---|
| 259 | default tokreturn (TOK_DEFAULT); |
---|
| 260 | double tokreturn (TOK_DOUBLE); |
---|
| 261 | enum tokreturn (TOK_ENUM); |
---|
| 262 | exception tokreturn (TOK_EXCEPTION); |
---|
| 263 | fixed tokreturn (TOK_FIXED); |
---|
| 264 | float tokreturn (TOK_FLOAT); |
---|
| 265 | in tokreturn (TOK_IN); |
---|
| 266 | inout tokreturn (TOK_INOUT); |
---|
| 267 | interface tokreturn (TOK_INTERFACE); |
---|
| 268 | long tokreturn (TOK_LONG); |
---|
| 269 | module tokreturn (TOK_MODULE); |
---|
| 270 | native tokreturn (TOK_NATIVE); |
---|
| 271 | octet tokreturn (TOK_OCTET); |
---|
| 272 | oneway tokreturn (TOK_ONEWAY); |
---|
| 273 | out tokreturn (TOK_OUT); |
---|
| 274 | raises tokreturn (TOK_RAISES); |
---|
| 275 | readonly tokreturn (TOK_READONLY); |
---|
| 276 | sequence tokreturn (TOK_SEQUENCE); |
---|
| 277 | short tokreturn (TOK_SHORT); |
---|
| 278 | string tokreturn (TOK_STRING); |
---|
| 279 | struct tokreturn (TOK_STRUCT); |
---|
| 280 | switch tokreturn (TOK_SWITCH); |
---|
| 281 | typedef tokreturn (TOK_TYPEDEF); |
---|
| 282 | union tokreturn (TOK_UNION); |
---|
| 283 | unsigned tokreturn (TOK_UNSIGNED); |
---|
| 284 | <XP>\.\.\. tokreturn (TOK_VARARGS); |
---|
| 285 | void tokreturn (TOK_VOID); |
---|
| 286 | wchar tokreturn (TOK_WCHAR); |
---|
| 287 | wstring tokreturn (TOK_WSTRING); |
---|
| 288 | :: tokreturn (TOK_OP_SCOPE); |
---|
| 289 | \>\> tokreturn (TOK_OP_SHR); |
---|
| 290 | \<\< tokreturn (TOK_OP_SHL); |
---|
| 291 | {declspec} { |
---|
| 292 | char *s = g_strdup (yytext); |
---|
| 293 | |
---|
| 294 | /* Get the parenthesized expression (ignoring whitespace) */ |
---|
| 295 | sscanf (yytext, "__declspec %*[(] %[A-Za-z_] %*[)]", s); |
---|
| 296 | yylval.str = s; |
---|
| 297 | __IDL_cur_line += count_nl (yytext); |
---|
| 298 | tokreturn (TOK_DECLSPEC); |
---|
| 299 | } |
---|
| 300 | {happy_ident} { |
---|
| 301 | #if 0 |
---|
| 302 | if ((__IDL_flags & IDLF_TYPECODES) && strcmp (yytext, "TypeCode") == 0) |
---|
| 303 | tokreturn (TOK_TYPECODE); |
---|
| 304 | #endif |
---|
| 305 | if (__IDL_typecodes_as_tok>0 && strcmp (yytext, "TypeCode") == 0) |
---|
| 306 | tokreturn (TOK_TYPECODE); |
---|
| 307 | if ( (__IDL_pidl <= 0) && strcmp(yytext, "Object")==0 ) |
---|
| 308 | tokreturn (TOK_OBJECT); |
---|
| 309 | yylval.str = g_strdup (yytext); |
---|
| 310 | tokreturn (TOK_IDENT); |
---|
| 311 | } |
---|
[20747] | 312 | {escaped_ident} { |
---|
| 313 | yylval.str = g_strdup (&yytext[1]); |
---|
[18250] | 314 | tokreturn (TOK_IDENT); |
---|
| 315 | } |
---|
| 316 | {warn1_ident} { |
---|
| 317 | if (!warn_underscores) { |
---|
| 318 | yywarningv (IDL_WARNING2, |
---|
| 319 | "`%s' underscores within identifiers are discouraged for use " |
---|
| 320 | "with C-language IDL mappings", yytext); |
---|
| 321 | warn_underscores = 1; |
---|
| 322 | } |
---|
| 323 | yylval.str = g_strdup (yytext); |
---|
| 324 | tokreturn (TOK_IDENT); |
---|
| 325 | } |
---|
| 326 | <PROP>] { |
---|
| 327 | __IDL_flagsi &= ~IDLFP_PROPERTIES; |
---|
| 328 | SELECT_RESTART; |
---|
| 329 | tokreturn (yytext[0]); |
---|
| 330 | } |
---|
| 331 | <PROP>{prop_key} { |
---|
| 332 | yylval.str = g_strdup (yytext); |
---|
| 333 | tokreturn (TOK_PROP_KEY); |
---|
| 334 | } |
---|
| 335 | <PROP>{prop_value} { |
---|
| 336 | yylval.str = g_strdup (yytext + 1); |
---|
| 337 | yylval.str[strlen (yylval.str) - 1] = 0; |
---|
| 338 | tokreturn (TOK_PROP_VALUE); |
---|
| 339 | } |
---|
| 340 | <NATIVE>{native_type} { |
---|
| 341 | __IDL_flagsi &= ~IDLFP_NATIVE; |
---|
| 342 | yylval.str = g_strdup (yytext); |
---|
| 343 | yylval.str[strlen (yylval.str) - 1] = 0; |
---|
| 344 | tokreturn (TOK_NATIVE_TYPE); |
---|
| 345 | } |
---|
| 346 | {sqstring} { |
---|
| 347 | yylval.str = g_strdup (yytext + 1); |
---|
| 348 | yylval.str[strlen (yytext) - 2] = 0; |
---|
| 349 | tokreturn (TOK_SQSTRING); |
---|
| 350 | } |
---|
| 351 | {dqstring} { |
---|
| 352 | yylval.str = g_strdup (yytext + 1); |
---|
| 353 | yylval.str[strlen (yytext) - 2] = 0; |
---|
| 354 | tokreturn (TOK_DQSTRING); |
---|
| 355 | } |
---|
| 356 | <*>{newline} ++__IDL_cur_line; |
---|
| 357 | <*>\/\/.* ; |
---|
| 358 | <*>\/\* { |
---|
| 359 | int c; |
---|
| 360 | |
---|
| 361 | while (1) { |
---|
| 362 | while ((c = input ()) != '*' && c != EOF) |
---|
| 363 | if (c == '\n') ++__IDL_cur_line; |
---|
| 364 | if (c == '*') { |
---|
| 365 | while ((c = input ()) == '*') ; |
---|
| 366 | if (c == '/') break; |
---|
| 367 | } |
---|
| 368 | if (c == '\n') ++__IDL_cur_line; |
---|
| 369 | if (c == EOF) { |
---|
| 370 | yywarning (IDL_WARNING1, "End of file in comment"); |
---|
| 371 | break; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | <*>. tokreturn (yytext[0]); |
---|
| 376 | |
---|
| 377 | %% |
---|
| 378 | |
---|
| 379 | void __IDL_lex_init (void) |
---|
| 380 | { |
---|
| 381 | __IDL_inputcb = NULL; |
---|
| 382 | __IDL_cur_line = 1; |
---|
| 383 | __IDL_cur_token_line = 0; |
---|
| 384 | __IDL_prev_token_line = 0; |
---|
| 385 | __IDL_cur_filename = NULL; |
---|
| 386 | __IDL_cur_fileinfo = NULL; |
---|
| 387 | warn_underscores = 0; |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | void __IDL_lex_cleanup (void) |
---|
| 391 | { |
---|
| 392 | __IDL_cur_filename = NULL; |
---|
[20747] | 393 | #ifdef YY_NEW_FILE |
---|
| 394 | YY_NEW_FILE; /* obsolete with newer versions of flex */ |
---|
| 395 | #endif |
---|
[18250] | 396 | } |
---|
| 397 | |
---|
| 398 | int yywrap (void) |
---|
| 399 | { |
---|
| 400 | return 1; |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | static int count_nl (const char *s) |
---|
| 404 | { |
---|
| 405 | int i; |
---|
| 406 | |
---|
| 407 | for (i = 0; |
---|
| 408 | (s = strchr (s, '\n')) != NULL; |
---|
| 409 | ++s, ++i) ; |
---|
| 410 | |
---|
| 411 | return i; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /* |
---|
| 415 | * Local variables: |
---|
| 416 | * mode: C |
---|
| 417 | * c-basic-offset: 8 |
---|
| 418 | * tab-width: 8 |
---|
| 419 | * indent-tabs-mode: t |
---|
| 420 | * End: |
---|
| 421 | */ |
---|