|  | /** | 
|  | * Thrift scanner. | 
|  | * | 
|  | * Tokenizes a thrift definition file. | 
|  | * @author Mark Slee <mcslee@facebook.com> | 
|  | */ | 
|  | %{ | 
|  |  | 
|  | #include "main.h" | 
|  | #include "parse/t_program.h" | 
|  |  | 
|  | /** Must be included AFTER parse/t_program.h */ | 
|  | #include "thrift.tab.hh" | 
|  |  | 
|  | %} | 
|  |  | 
|  | /** Provides yylineno global */ | 
|  | %option lex-compat | 
|  |  | 
|  | /** Helper definitions */ | 
|  | intconstant  ([0-9]+) | 
|  | identifier   ([a-zA-Z_][a-zA-Z_0-9]*) | 
|  | whitespace   ([ \t\r\n]*) | 
|  | multicomm    ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/") | 
|  | comment      ("//"[^\n]*) | 
|  | symbol       ([\,\{\}\(\)\=<>]) | 
|  |  | 
|  | %% | 
|  |  | 
|  | {whitespace}  { /* do nothing */ } | 
|  | {multicomm}   { /* do nothing */ } | 
|  | {comment}     { /* do nothing */ } | 
|  |  | 
|  | {symbol}      { return yytext[0];   } | 
|  |  | 
|  | "void"        { return tok_void;     } | 
|  | "byte"        { return tok_byte;     } | 
|  | "string"      { return tok_string;   } | 
|  | "i32"         { return tok_i32;      } | 
|  | "u32"         { return tok_u32;      } | 
|  | "i64"         { return tok_i64;      } | 
|  | "u64"         { return tok_u64;      } | 
|  |  | 
|  | "map"         { return tok_map;      } | 
|  | "list"        { return tok_list;     } | 
|  | "set"         { return tok_set;      } | 
|  |  | 
|  | "async"       { return tok_async;    } | 
|  |  | 
|  | "typedef"     { return tok_typedef;  } | 
|  | "struct"      { return tok_struct;   } | 
|  | "service"     { return tok_service;  } | 
|  | "enum"        { return tok_enum;     } | 
|  |  | 
|  |  | 
|  | {intconstant} { yylval.iconst = atoi(yytext) ; return tok_int_constant; } | 
|  | {identifier}  { yylval.id = strdup(yytext); return tok_identifier; } | 
|  |  | 
|  | %% |