blob: 64a2bf8d0ffe24c684d022c2d98eccea140500f6 [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 */
Mark Sleef5377b32006-10-10 01:42:59 +00007
Mark Slee31985722006-05-24 21:45:31 +00008%{
9
10#include "main.h"
11#include "parse/t_program.h"
12
Mark Sleef5377b32006-10-10 01:42:59 +000013/**
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 Slee31985722006-05-24 21:45:31 +000017#include "thrift.tab.hh"
18
19%}
20
Mark Sleef5377b32006-10-10 01:42:59 +000021/**
22 * Provides the yylineno global, useful for debugging output
23 */
Mark Slee31985722006-05-24 21:45:31 +000024%option lex-compat
25
Mark Sleef5377b32006-10-10 01:42:59 +000026/**
27 * Helper definitions, comments, constants, and whatnot
28 */
29
Mark Slee31985722006-05-24 21:45:31 +000030intconstant ([0-9]+)
Mark Slee9cb7c612006-09-01 22:17:45 +000031identifier ([a-zA-Z_][\.a-zA-Z_0-9]*)
Mark Slee31985722006-05-24 21:45:31 +000032whitespace ([ \t\r\n]*)
33multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
34comment ("//"[^\n]*)
Mark Sleec98d0502006-09-06 02:42:25 +000035unixcomment ("#"[^\n]*)
Mark Sleee8540632006-05-30 09:24:40 +000036symbol ([\,\{\}\(\)\=<>])
Mark Slee31985722006-05-24 21:45:31 +000037
38%%
39
40{whitespace} { /* do nothing */ }
41{multicomm} { /* do nothing */ }
42{comment} { /* do nothing */ }
Mark Sleec98d0502006-09-06 02:42:25 +000043{unixcomment} { /* do nothing */ }
Mark Slee31985722006-05-24 21:45:31 +000044
Mark Slee9cb7c612006-09-01 22:17:45 +000045{symbol} { return yytext[0]; }
46
47"namespace" { return tok_namespace; }
Mark Sleef5377b32006-10-10 01:42:59 +000048"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 Slee52f643d2006-08-09 00:03:43 +000066
Mark Slee9cb7c612006-09-01 22:17:45 +000067{intconstant} { yylval.iconst = atoi(yytext); return tok_int_constant; }
Mark Sleef5377b32006-10-10 01:42:59 +000068
Mark Slee31985722006-05-24 21:45:31 +000069{identifier} { yylval.id = strdup(yytext); return tok_identifier; }
70
71%%