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]+) |
| 22 | identifier ([a-zA-Z_][a-zA-Z_0-9]*) |
| 23 | whitespace ([ \t\r\n]*) |
| 24 | multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") |
| 25 | comment ("//"[^\n]*) |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 26 | symbol ([\,\{\}\(\)\=<>]) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 27 | |
| 28 | %% |
| 29 | |
| 30 | {whitespace} { /* do nothing */ } |
| 31 | {multicomm} { /* do nothing */ } |
| 32 | {comment} { /* do nothing */ } |
| 33 | |
| 34 | {symbol} { return yytext[0]; } |
| 35 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame^] | 36 | "void" { return tok_void; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 37 | "byte" { return tok_byte; } |
| 38 | "string" { return tok_string; } |
| 39 | "i32" { return tok_i32; } |
| 40 | "u32" { return tok_u32; } |
| 41 | "i64" { return tok_i64; } |
| 42 | "u64" { return tok_u64; } |
| 43 | |
| 44 | "map" { return tok_map; } |
| 45 | "list" { return tok_list; } |
| 46 | "set" { return tok_set; } |
| 47 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 48 | "async" { return tok_async; } |
| 49 | |
| 50 | "typedef" { return tok_typedef; } |
| 51 | "struct" { return tok_struct; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 52 | "service" { return tok_service; } |
| 53 | "enum" { return tok_enum; } |
| 54 | |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame^] | 55 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 56 | {intconstant} { yylval.iconst = atoi(yytext) ; return tok_int_constant; } |
| 57 | {identifier} { yylval.id = strdup(yytext); return tok_identifier; } |
| 58 | |
| 59 | %% |