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 | */ |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 7 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 8 | %{ |
| 9 | |
| 10 | #include "main.h" |
| 11 | #include "parse/t_program.h" |
| 12 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 13 | /** |
| 14 | * Must be included AFTER parse/t_program.h, but I can't remember why anymore |
| 15 | * because I wrote this a while ago. |
| 16 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 17 | #include "thrift.tab.hh" |
| 18 | |
| 19 | %} |
| 20 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 21 | /** |
| 22 | * Provides the yylineno global, useful for debugging output |
| 23 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 24 | %option lex-compat |
| 25 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 26 | /** |
| 27 | * Helper definitions, comments, constants, and whatnot |
| 28 | */ |
| 29 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 30 | intconstant ([0-9]+) |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 31 | identifier ([a-zA-Z_][\.a-zA-Z_0-9]*) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 32 | whitespace ([ \t\r\n]*) |
| 33 | multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") |
| 34 | comment ("//"[^\n]*) |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 35 | unixcomment ("#"[^\n]*) |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 36 | symbol ([\,\{\}\(\)\=<>]) |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 37 | |
| 38 | %% |
| 39 | |
| 40 | {whitespace} { /* do nothing */ } |
| 41 | {multicomm} { /* do nothing */ } |
| 42 | {comment} { /* do nothing */ } |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 43 | {unixcomment} { /* do nothing */ } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 44 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 45 | {symbol} { return yytext[0]; } |
| 46 | |
| 47 | "namespace" { return tok_namespace; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 48 | "void" { return tok_void; } |
| 49 | "bool" { return tok_bool; } |
| 50 | "byte" { return tok_byte; } |
| 51 | "i16" { return tok_i16; } |
| 52 | "i32" { return tok_i32; } |
| 53 | "i64" { return tok_i64; } |
| 54 | "double" { return tok_double; } |
| 55 | "string" { return tok_string; } |
| 56 | "map" { return tok_map; } |
| 57 | "list" { return tok_list; } |
| 58 | "set" { return tok_set; } |
| 59 | "async" { return tok_async; } |
| 60 | "typedef" { return tok_typedef; } |
| 61 | "struct" { return tok_struct; } |
| 62 | "exception" { return tok_xception; } |
| 63 | "throws" { return tok_throws; } |
| 64 | "service" { return tok_service; } |
| 65 | "enum" { return tok_enum; } |
Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 66 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 67 | {intconstant} { yylval.iconst = atoi(yytext); return tok_int_constant; } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame^] | 68 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 69 | {identifier} { yylval.id = strdup(yytext); return tok_identifier; } |
| 70 | |
| 71 | %% |