blob: 839060e94c84b011e3ceb83462486313e2ba2c30 [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 Sleef0712dc2006-10-25 19:03:57 +000036symbol ([:\,\{\}\(\)\=<>\[\]])
37literal ("\""[^"]*"\"")
Mark Slee31985722006-05-24 21:45:31 +000038
39%%
40
41{whitespace} { /* do nothing */ }
42{multicomm} { /* do nothing */ }
43{comment} { /* do nothing */ }
Mark Sleec98d0502006-09-06 02:42:25 +000044{unixcomment} { /* do nothing */ }
Mark Slee31985722006-05-24 21:45:31 +000045
Mark Slee9cb7c612006-09-01 22:17:45 +000046{symbol} { return yytext[0]; }
47
Mark Sleef0712dc2006-10-25 19:03:57 +000048"namespace" { return tok_namespace; }
49"cpp_namespace" { return tok_cpp_namespace; }
50"cpp_include" { return tok_cpp_include; }
51"cpp_type" { return tok_cpp_type; }
52"java_package" { return tok_java_package; }
53"include" { return tok_include; }
54
55"void" { return tok_void; }
56"bool" { return tok_bool; }
57"byte" { return tok_byte; }
58"i16" { return tok_i16; }
59"i32" { return tok_i32; }
60"i64" { return tok_i64; }
61"double" { return tok_double; }
62"string" { return tok_string; }
63"map" { return tok_map; }
64"list" { return tok_list; }
65"set" { return tok_set; }
66"async" { return tok_async; }
67"typedef" { return tok_typedef; }
68"struct" { return tok_struct; }
69"exception" { return tok_xception; }
70"extends" { return tok_extends; }
71"throws" { return tok_throws; }
72"service" { return tok_service; }
73"enum" { return tok_enum; }
Mark Slee52f643d2006-08-09 00:03:43 +000074
Mark Slee4f8da1d2006-10-12 02:47:27 +000075{intconstant} {
76 yylval.iconst = atoi(yytext);
77 return tok_int_constant;
78}
Mark Sleef5377b32006-10-10 01:42:59 +000079
Mark Slee4f8da1d2006-10-12 02:47:27 +000080{identifier} {
81 yylval.id = strdup(yytext);
82 return tok_identifier;
83}
84
Mark Sleef0712dc2006-10-25 19:03:57 +000085{literal} {
86 yylval.id = strdup(yytext+1);
87 yylval.id[strlen(yylval.id)-1] = '\0';
88 return tok_literal;
89}
Mark Slee31985722006-05-24 21:45:31 +000090
91%%