blob: 9d2944ac161bcc61bfe0e04012e3160be893616c [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001/**
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 */
21intconstant ([0-9]+)
22identifier ([a-zA-Z_][a-zA-Z_0-9]*)
23whitespace ([ \t\r\n]*)
24multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
25comment ("//"[^\n]*)
Mark Sleee8540632006-05-30 09:24:40 +000026symbol ([\,\{\}\(\)\=<>])
Mark Slee31985722006-05-24 21:45:31 +000027
28%%
29
30{whitespace} { /* do nothing */ }
31{multicomm} { /* do nothing */ }
32{comment} { /* do nothing */ }
33
34{symbol} { return yytext[0]; }
35
Mark Slee52f643d2006-08-09 00:03:43 +000036"void" { return tok_void; }
Mark Slee31985722006-05-24 21:45:31 +000037"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 Slee31985722006-05-24 21:45:31 +000048"async" { return tok_async; }
49
50"typedef" { return tok_typedef; }
51"struct" { return tok_struct; }
Mark Slee31985722006-05-24 21:45:31 +000052"service" { return tok_service; }
53"enum" { return tok_enum; }
54
Mark Slee52f643d2006-08-09 00:03:43 +000055
Mark Slee31985722006-05-24 21:45:31 +000056{intconstant} { yylval.iconst = atoi(yytext) ; return tok_int_constant; }
57{identifier} { yylval.id = strdup(yytext); return tok_identifier; }
58
59%%