blob: 484e43b1a6cd66e547eb23dcce3048db06fb3f8a [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]+)
Mark Slee9cb7c612006-09-01 22:17:45 +000022identifier ([a-zA-Z_][\.a-zA-Z_0-9]*)
Mark Slee31985722006-05-24 21:45:31 +000023whitespace ([ \t\r\n]*)
24multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
25comment ("//"[^\n]*)
Mark Sleec98d0502006-09-06 02:42:25 +000026unixcomment ("#"[^\n]*)
Mark Sleee8540632006-05-30 09:24:40 +000027symbol ([\,\{\}\(\)\=<>])
Mark Slee31985722006-05-24 21:45:31 +000028
29%%
30
31{whitespace} { /* do nothing */ }
32{multicomm} { /* do nothing */ }
33{comment} { /* do nothing */ }
Mark Sleec98d0502006-09-06 02:42:25 +000034{unixcomment} { /* do nothing */ }
Mark Slee31985722006-05-24 21:45:31 +000035
Mark Slee9cb7c612006-09-01 22:17:45 +000036{symbol} { return yytext[0]; }
37
38"namespace" { return tok_namespace; }
Mark Slee31985722006-05-24 21:45:31 +000039
Mark Slee52f643d2006-08-09 00:03:43 +000040"void" { return tok_void; }
Mark Slee78f58e22006-09-02 04:17:07 +000041"bool" { return tok_bool; }
Mark Slee31985722006-05-24 21:45:31 +000042"byte" { return tok_byte; }
Mark Slee9cb7c612006-09-01 22:17:45 +000043"i16" { return tok_i16; }
Mark Slee31985722006-05-24 21:45:31 +000044"i32" { return tok_i32; }
Mark Slee31985722006-05-24 21:45:31 +000045"i64" { return tok_i64; }
Mark Slee9cb7c612006-09-01 22:17:45 +000046"double" { return tok_double; }
47"string" { return tok_string; }
Mark Slee31985722006-05-24 21:45:31 +000048
49"map" { return tok_map; }
50"list" { return tok_list; }
51"set" { return tok_set; }
52
Mark Slee31985722006-05-24 21:45:31 +000053"async" { return tok_async; }
54
55"typedef" { return tok_typedef; }
56"struct" { return tok_struct; }
Mark Slee9cb7c612006-09-01 22:17:45 +000057"exception" { return tok_xception; }
58"throws" { return tok_throws; }
Mark Slee31985722006-05-24 21:45:31 +000059"service" { return tok_service; }
60"enum" { return tok_enum; }
61
Mark Slee52f643d2006-08-09 00:03:43 +000062
Mark Slee9cb7c612006-09-01 22:17:45 +000063{intconstant} { yylval.iconst = atoi(yytext); return tok_int_constant; }
Mark Slee31985722006-05-24 21:45:31 +000064{identifier} { yylval.id = strdup(yytext); return tok_identifier; }
65
66%%