blob: 0c113cbd66c0db913be0a2fc60c01d6b9a4daeaa [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 Slee30152872006-11-28 01:24:07 +000030intconstant ([+-]?[0-9]+)
31dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
Mark Slee9cb7c612006-09-01 22:17:45 +000032identifier ([a-zA-Z_][\.a-zA-Z_0-9]*)
Mark Slee31985722006-05-24 21:45:31 +000033whitespace ([ \t\r\n]*)
34multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
35comment ("//"[^\n]*)
Mark Sleec98d0502006-09-06 02:42:25 +000036unixcomment ("#"[^\n]*)
Mark Sleeae2bc3c2006-11-08 23:44:59 +000037symbol ([:;\,\{\}\(\)\=<>\[\]])
Mark Slee30152872006-11-28 01:24:07 +000038dliteral ("\""[^"]*"\"")
39sliteral ("'"[^']*"'")
Mark Slee31985722006-05-24 21:45:31 +000040
41%%
42
43{whitespace} { /* do nothing */ }
44{multicomm} { /* do nothing */ }
45{comment} { /* do nothing */ }
Mark Sleec98d0502006-09-06 02:42:25 +000046{unixcomment} { /* do nothing */ }
Mark Slee31985722006-05-24 21:45:31 +000047
Mark Slee9cb7c612006-09-01 22:17:45 +000048{symbol} { return yytext[0]; }
49
Mark Sleef0712dc2006-10-25 19:03:57 +000050"namespace" { return tok_namespace; }
51"cpp_namespace" { return tok_cpp_namespace; }
52"cpp_include" { return tok_cpp_include; }
53"cpp_type" { return tok_cpp_type; }
54"java_package" { return tok_java_package; }
55"include" { return tok_include; }
56
57"void" { return tok_void; }
58"bool" { return tok_bool; }
59"byte" { return tok_byte; }
60"i16" { return tok_i16; }
61"i32" { return tok_i32; }
62"i64" { return tok_i64; }
63"double" { return tok_double; }
64"string" { return tok_string; }
65"map" { return tok_map; }
66"list" { return tok_list; }
67"set" { return tok_set; }
68"async" { return tok_async; }
69"typedef" { return tok_typedef; }
70"struct" { return tok_struct; }
71"exception" { return tok_xception; }
72"extends" { return tok_extends; }
73"throws" { return tok_throws; }
74"service" { return tok_service; }
75"enum" { return tok_enum; }
Mark Slee30152872006-11-28 01:24:07 +000076"const" { return tok_const; }
Mark Slee52f643d2006-08-09 00:03:43 +000077
Mark Slee4f8da1d2006-10-12 02:47:27 +000078{intconstant} {
79 yylval.iconst = atoi(yytext);
80 return tok_int_constant;
81}
Mark Sleef5377b32006-10-10 01:42:59 +000082
Mark Slee30152872006-11-28 01:24:07 +000083{dubconstant} {
84 yylval.dconst = atof(yytext);
85 return tok_dub_constant;
86}
87
Mark Slee4f8da1d2006-10-12 02:47:27 +000088{identifier} {
89 yylval.id = strdup(yytext);
90 return tok_identifier;
91}
92
Mark Slee30152872006-11-28 01:24:07 +000093{dliteral} {
94 yylval.id = strdup(yytext+1);
95 yylval.id[strlen(yylval.id)-1] = '\0';
96 return tok_literal;
97}
98
99{sliteral} {
Mark Sleef0712dc2006-10-25 19:03:57 +0000100 yylval.id = strdup(yytext+1);
101 yylval.id[strlen(yylval.id)-1] = '\0';
102 return tok_literal;
103}
Mark Slee31985722006-05-24 21:45:31 +0000104
105%%