Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Thrift scanner. |
| 3 | * |
| 4 | * Tokenizes a thrift definition file. |
| 5 | * @author Mark Slee <mcslee@facebook.com> |
| 6 | */ |
| 7 | %{ |
| 8 | |
| 9 | #include "main.h" |
| 10 | #include "parse/t_program.h" |
| 11 | |
| 12 | /** Must be included AFTER parse/t_program.h */ |
| 13 | #include "thrift.tab.hh" |
| 14 | |
| 15 | %} |
| 16 | |
| 17 | /** Provides yylineno global */ |
| 18 | %option lex-compat |
| 19 | |
| 20 | /** Helper definitions */ |
| 21 | intconstant ([0-9]+) |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 22 | identifier ([a-zA-Z_][\.a-zA-Z_0-9]*) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 23 | whitespace ([ \t\r\n]*) |
| 24 | multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") |
| 25 | comment ("//"[^\n]*) |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 26 | unixcomment ("#"[^\n]*) |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 27 | symbol ([\,\{\}\(\)\=<>]) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 28 | |
| 29 | %% |
| 30 | |
| 31 | {whitespace} { /* do nothing */ } |
| 32 | {multicomm} { /* do nothing */ } |
| 33 | {comment} { /* do nothing */ } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 34 | {unixcomment} { /* do nothing */ } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 35 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 36 | {symbol} { return yytext[0]; } |
| 37 | |
| 38 | "namespace" { return tok_namespace; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 39 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 40 | "void" { return tok_void; } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 41 | "bool" { return tok_bool; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 42 | "byte" { return tok_byte; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 43 | "i16" { return tok_i16; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 44 | "i32" { return tok_i32; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 45 | "i64" { return tok_i64; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 46 | "double" { return tok_double; } |
| 47 | "string" { return tok_string; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 48 | |
| 49 | "map" { return tok_map; } |
| 50 | "list" { return tok_list; } |
| 51 | "set" { return tok_set; } |
| 52 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 53 | "async" { return tok_async; } |
| 54 | |
| 55 | "typedef" { return tok_typedef; } |
| 56 | "struct" { return tok_struct; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 57 | "exception" { return tok_xception; } |
| 58 | "throws" { return tok_throws; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 59 | "service" { return tok_service; } |
| 60 | "enum" { return tok_enum; } |
| 61 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 62 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 63 | {intconstant} { yylval.iconst = atoi(yytext); return tok_int_constant; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 64 | {identifier} { yylval.id = strdup(yytext); return tok_identifier; } |
| 65 | |
| 66 | %% |