blob: 06b71e126d04210c680a14d2573aedef76e5be23 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001%{
2
3/**
4 * Thrift parser.
5 *
6 * This parser is used on a thrift definition file.
7 *
8 * @author Mark Slee <mcslee@facebook.com>
9 */
10
11#include <stdio.h>
12#include "main.h"
13#include "globals.h"
14#include "parse/t_program.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000015#include "parse/t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000016
Mark Sleef5377b32006-10-10 01:42:59 +000017/**
18 * This global variable is used for automatic numbering of field indices etc.
19 * when parsing the members of a struct. Field values are automatically
20 * assigned starting from -1 and working their way down.
21 */
Mark Slee9cb7c612006-09-01 22:17:45 +000022int y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +000023
24%}
25
Mark Sleef5377b32006-10-10 01:42:59 +000026/**
27 * This structure is used by the parser to hold the data types associated with
28 * various parse nodes.
29 */
Mark Slee31985722006-05-24 21:45:31 +000030%union {
Mark Slee30152872006-11-28 01:24:07 +000031 char* id;
32 int iconst;
33 double dconst;
34 bool tbool;
35 t_type* ttype;
36 t_typedef* ttypedef;
37 t_enum* tenum;
38 t_enum_value* tenumv;
39 t_const* tconst;
40 t_const_value* tconstv;
41 t_struct* tstruct;
42 t_service* tservice;
43 t_function* tfunction;
44 t_field* tfield;
Mark Slee31985722006-05-24 21:45:31 +000045}
46
Mark Sleef5377b32006-10-10 01:42:59 +000047/**
48 * Strings identifier
49 */
Mark Slee31985722006-05-24 21:45:31 +000050%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000051%token<id> tok_literal
Mark Sleef5377b32006-10-10 01:42:59 +000052
53/**
Mark Slee30152872006-11-28 01:24:07 +000054 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000055 */
Mark Slee31985722006-05-24 21:45:31 +000056%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000057%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000058
Mark Sleef5377b32006-10-10 01:42:59 +000059/**
Mark Sleef0712dc2006-10-25 19:03:57 +000060 * Header keywoards
Mark Sleef5377b32006-10-10 01:42:59 +000061 */
Mark Sleef0712dc2006-10-25 19:03:57 +000062%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000063%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000064%token tok_cpp_namespace
65%token tok_cpp_include
66%token tok_cpp_type
67%token tok_java_package
Mark Slee9cb7c612006-09-01 22:17:45 +000068
Mark Sleef5377b32006-10-10 01:42:59 +000069/**
70 * Base datatype keywords
71 */
72%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000073%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000074%token tok_byte
75%token tok_string
Mark Slee9cb7c612006-09-01 22:17:45 +000076%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000077%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000078%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000079%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000080
Mark Sleef5377b32006-10-10 01:42:59 +000081/**
82 * Complex type keywords
83 */
Mark Slee31985722006-05-24 21:45:31 +000084%token tok_map
85%token tok_list
86%token tok_set
87
Mark Sleef5377b32006-10-10 01:42:59 +000088/**
89 * Function modifiers
90 */
Mark Slee31985722006-05-24 21:45:31 +000091%token tok_async
92
Mark Sleef5377b32006-10-10 01:42:59 +000093/**
94 * Thrift language keywords
95 */
Mark Slee31985722006-05-24 21:45:31 +000096%token tok_typedef
97%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +000098%token tok_xception
99%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000100%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000101%token tok_service
102%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000103%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000104
Mark Sleef5377b32006-10-10 01:42:59 +0000105/**
106 * Grammar nodes
107 */
108
Mark Slee31985722006-05-24 21:45:31 +0000109%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000110%type<ttype> ContainerType
111%type<ttype> MapType
112%type<ttype> SetType
113%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000114
Mark Sleef0712dc2006-10-25 19:03:57 +0000115%type<ttype> TypeDefinition
116
Mark Slee31985722006-05-24 21:45:31 +0000117%type<ttypedef> Typedef
118%type<ttype> DefinitionType
119
120%type<tfield> Field
121%type<ttype> FieldType
Mark Sleee8540632006-05-30 09:24:40 +0000122%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000123
124%type<tenum> Enum
125%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000126%type<tenumv> EnumDef
127
128%type<tconst> Const
129%type<tconstv> ConstValue
130%type<tconstv> ConstList
131%type<tconstv> ConstListContents
132%type<tconstv> ConstMap
133%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000134
135%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000136%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000137%type<tservice> Service
138
139%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000140%type<ttype> FunctionType
141%type<tservice> FunctionList
142
Mark Sleef5377b32006-10-10 01:42:59 +0000143%type<tstruct> ThrowsOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000144%type<tservice> ExtendsOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000145%type<tbool> AsyncOptional
Mark Slee4f8da1d2006-10-12 02:47:27 +0000146%type<id> CppTypeOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000147
Mark Slee31985722006-05-24 21:45:31 +0000148%%
149
Mark Sleef5377b32006-10-10 01:42:59 +0000150/**
151 * Thrift Grammar Implementation.
152 *
153 * For the most part this source file works its way top down from what you
154 * might expect to find in a typical .thrift file, i.e. type definitions and
155 * namespaces up top followed by service definitions using those types.
156 */
Mark Slee31985722006-05-24 21:45:31 +0000157
158Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000159 HeaderList DefinitionList
160 {
161 pdebug("Program -> Headers DefinitionList");
162 }
163
164HeaderList:
165 HeaderList Header
166 {
167 pdebug("HeaderList -> HeaderList Header");
168 }
169|
170 {
171 pdebug("HeaderList -> ");
172 }
173
174Header:
175 Include
176 {
177 pdebug("Header -> Include");
178 }
179| tok_namespace tok_identifier
180 {
181 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
182 if (g_parse_mode == PROGRAM) {
183 g_program->set_cpp_namespace($2);
184 g_program->set_java_package($2);
185 }
186 }
187| tok_cpp_namespace tok_identifier
188 {
189 pdebug("Header -> tok_cpp_namespace tok_identifier");
190 if (g_parse_mode == PROGRAM) {
191 g_program->set_cpp_namespace($2);
192 }
193 }
194| tok_cpp_include tok_literal
195 {
196 pdebug("Header -> tok_cpp_include tok_literal");
197 if (g_parse_mode == PROGRAM) {
198 g_program->add_cpp_include($2);
199 }
200 }
201| tok_java_package tok_identifier
202 {
203 pdebug("Header -> tok_java_package tok_identifier");
204 if (g_parse_mode == PROGRAM) {
205 g_program->set_java_package($2);
206 }
207 }
208
209Include:
210 tok_include tok_literal
211 {
212 pdebug("Include -> tok_include tok_literal");
213 if (g_parse_mode == INCLUDES) {
214 std::string path = include_file(std::string($2));
215 if (!path.empty()) {
216 g_program->add_include(path);
217 }
218 }
219 }
Mark Slee31985722006-05-24 21:45:31 +0000220
221DefinitionList:
222 DefinitionList Definition
223 {
224 pdebug("DefinitionList -> DefinitionList Definition");
225 }
226|
227 {
228 pdebug("DefinitionList -> ");
229 }
230
231Definition:
Mark Slee30152872006-11-28 01:24:07 +0000232 Const
233 {
234 pdebug("Definition -> Const");
235 if (g_parse_mode == PROGRAM) {
236 g_program->add_const($1);
237 }
238 }
239| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000240 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000241 pdebug("Definition -> TypeDefinition");
242 if (g_parse_mode == PROGRAM) {
243 g_scope->add_type($1->get_name(), $1);
244 if (g_parent_scope != NULL) {
245 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
246 }
247 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000248 }
Mark Slee31985722006-05-24 21:45:31 +0000249| Service
250 {
251 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000252 if (g_parse_mode == PROGRAM) {
253 g_scope->add_service($1->get_name(), $1);
254 if (g_parent_scope != NULL) {
255 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
256 }
257 g_program->add_service($1);
258 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000259 }
260
Mark Sleef0712dc2006-10-25 19:03:57 +0000261TypeDefinition:
262 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000263 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000264 pdebug("TypeDefinition -> Typedef");
265 if (g_parse_mode == PROGRAM) {
266 g_program->add_typedef($1);
267 }
268 }
269| Enum
270 {
271 pdebug("TypeDefinition -> Enum");
272 if (g_parse_mode == PROGRAM) {
273 g_program->add_enum($1);
274 }
275 }
276| Struct
277 {
278 pdebug("TypeDefinition -> Struct");
279 if (g_parse_mode == PROGRAM) {
280 g_program->add_struct($1);
281 }
282 }
283| Xception
284 {
285 pdebug("TypeDefinition -> Xception");
286 if (g_parse_mode == PROGRAM) {
287 g_program->add_xception($1);
288 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000289 }
Mark Slee31985722006-05-24 21:45:31 +0000290
291Typedef:
292 tok_typedef DefinitionType tok_identifier
293 {
294 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000295 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000296 $$ = td;
297 }
298
299Enum:
300 tok_enum tok_identifier '{' EnumDefList '}'
301 {
302 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
303 $$ = $4;
304 $$->set_name($2);
305 }
306
Mark Slee207cb462006-11-02 18:43:12 +0000307CommaOrSemicolonOptional:
308 ','
309 {}
310| ';'
311 {}
312|
313 {}
314
Mark Slee31985722006-05-24 21:45:31 +0000315EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000316 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000317 {
318 pdebug("EnumDefList -> EnumDefList EnumDef");
319 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000320 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000321 }
322|
323 {
324 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000325 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000326 }
327
328EnumDef:
Mark Slee207cb462006-11-02 18:43:12 +0000329 tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000330 {
Mark Slee30152872006-11-28 01:24:07 +0000331 pdebug("EnumDef -> tok_identifier = tok_int_constant");
Mark Slee31985722006-05-24 21:45:31 +0000332 if ($3 < 0) {
Mark Sleef0712dc2006-10-25 19:03:57 +0000333 pwarning(1, "Negative value supplied for enum %s.\n", $1);
Mark Slee31985722006-05-24 21:45:31 +0000334 }
Mark Slee30152872006-11-28 01:24:07 +0000335 $$ = new t_enum_value($1, $3);
Mark Slee31985722006-05-24 21:45:31 +0000336 }
337|
Mark Slee04cc6052006-11-15 21:25:34 +0000338 tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000339 {
Mark Slee30152872006-11-28 01:24:07 +0000340 pdebug("EnumDef -> tok_identifier");
341 $$ = new t_enum_value($1);
342 }
343
344Const:
345 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
346 {
347 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
348 $$ = new t_const($2, $3, $5);
349 validate_const_type($$);
350 }
351
352ConstValue:
353 tok_int_constant
354 {
355 pdebug("ConstValue => tok_int_constant");
356 $$ = new t_const_value();
357 $$->set_integer($1);
358 }
359| tok_dub_constant
360 {
361 pdebug("ConstValue => tok_dub_constant");
362 $$ = new t_const_value();
363 $$->set_double($1);
364 }
365| tok_literal
366 {
367 pdebug("ConstValue => tok_literal");
368 $$ = new t_const_value();
369 $$->set_string($1);
370 }
371| ConstList
372 {
373 pdebug("ConstValue => ConstList");
374 $$ = $1;
375 }
376| ConstMap
377 {
378 pdebug("ConstValue => ConstMap");
379 $$ = $1;
380 }
381
382ConstList:
383 '[' ConstListContents ']'
384 {
385 pdebug("ConstList => [ ConstListContents ]");
386 $$ = $2;
387 }
388
389ConstListContents:
390 ConstListContents ConstValue CommaOrSemicolonOptional
391 {
392 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
393 $$ = $1;
394 $$->add_list($2);
395 }
396|
397 {
398 pdebug("ConstListContents =>");
399 $$ = new t_const_value();
400 $$->set_list();
401 }
402
403ConstMap:
404 '{' ConstMapContents '}'
405 {
406 pdebug("ConstMap => { ConstMapContents }");
407 $$ = $2;
408 }
409
410ConstMapContents:
411 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
412 {
413 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
414 $$ = $1;
415 $$->add_map($2, $4);
416 }
417|
418 {
419 pdebug("ConstMapContents =>");
420 $$ = new t_const_value();
421 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000422 }
423
424Struct:
425 tok_struct tok_identifier '{' FieldList '}'
426 {
427 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
Mark Sleee8540632006-05-30 09:24:40 +0000428 $4->set_name($2);
429 $$ = $4;
Mark Slee9cb7c612006-09-01 22:17:45 +0000430 y_field_val = -1;
431 }
432
433Xception:
434 tok_xception tok_identifier '{' FieldList '}'
435 {
436 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
437 $4->set_name($2);
438 $4->set_xception(true);
439 $$ = $4;
440 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000441 }
442
443Service:
Mark Sleef0712dc2006-10-25 19:03:57 +0000444 tok_service tok_identifier ExtendsOptional '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000445 {
446 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Sleef0712dc2006-10-25 19:03:57 +0000447 $$ = $5;
Mark Slee31985722006-05-24 21:45:31 +0000448 $$->set_name($2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000449 $$->set_extends($3);
450 }
451
452ExtendsOptional:
453 tok_extends tok_identifier
454 {
455 pdebug("ExtendsOptional -> tok_extends tok_identifier");
456 $$ = NULL;
457 if (g_parse_mode == PROGRAM) {
458 $$ = g_scope->get_service($2);
459 if ($$ == NULL) {
460 yyerror("Service \"%s\" has not been defined.", $2);
461 exit(1);
462 }
463 }
464 }
465|
466 {
467 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000468 }
469
470FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000471 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000472 {
473 pdebug("FunctionList -> FunctionList Function");
474 $$ = $1;
475 $1->add_function($2);
476 }
477|
478 {
479 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000480 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000481 }
482
483Function:
Mark Slee207cb462006-11-02 18:43:12 +0000484 AsyncOptional FunctionType tok_identifier '(' FieldList ')' ThrowsOptional CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000485 {
Mark Sleeb15a68b2006-06-07 06:46:24 +0000486 $5->set_name(std::string($3) + "_args");
Mark Slee4e755ca2006-09-12 00:46:08 +0000487 $$ = new t_function($2, $3, $5, $7, $1);
Mark Slee9cb7c612006-09-01 22:17:45 +0000488 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000489 }
490
Mark Slee52f643d2006-08-09 00:03:43 +0000491AsyncOptional:
492 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000493 {
Mark Slee52f643d2006-08-09 00:03:43 +0000494 $$ = true;
495 }
496|
497 {
498 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000499 }
500
Mark Slee9cb7c612006-09-01 22:17:45 +0000501ThrowsOptional:
502 tok_throws '(' FieldList ')'
503 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000504 pdebug("ThrowsOptional -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000505 $$ = $3;
506 }
507|
508 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000509 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000510 }
511
Mark Slee31985722006-05-24 21:45:31 +0000512FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000513 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000514 {
515 pdebug("FieldList -> FieldList , Field");
516 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000517 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000518 }
519|
520 {
521 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000522 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000523 }
524
525Field:
Mark Slee207cb462006-11-02 18:43:12 +0000526 tok_int_constant ':' FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000527 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000528 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
529 if ($1 <= 0) {
530 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $1, $4);
531 $1 = y_field_val--;
Mark Slee31985722006-05-24 21:45:31 +0000532 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000533 $$ = new t_field($3, $4, $1);
Mark Slee31985722006-05-24 21:45:31 +0000534 }
Mark Slee2329a832006-11-09 00:23:30 +0000535| FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000536 {
Mark Sleee8540632006-05-30 09:24:40 +0000537 pdebug("Field -> FieldType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000538 pwarning(2, "No field key specified for '%s', resulting protocol may have conflicts or not be backwards compatible!\n", $2);
Mark Slee9cb7c612006-09-01 22:17:45 +0000539 $$ = new t_field($1, $2, y_field_val--);
Mark Slee31985722006-05-24 21:45:31 +0000540 }
Mark Slee2329a832006-11-09 00:23:30 +0000541| FieldType tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000542 {
Mark Slee2329a832006-11-09 00:23:30 +0000543 pwarning(1, "Trailing = id notation is deprecated. Use 'Id: Type Name' notation instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000544 pdebug("Field -> FieldType tok_identifier = tok_int_constant");
545 if ($4 <= 0) {
546 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $4, $2);
547 $4 = y_field_val--;
548 }
549 $$ = new t_field($1, $2, $4);
550 }
Mark Slee31985722006-05-24 21:45:31 +0000551
552DefinitionType:
553 BaseType
554 {
555 pdebug("DefinitionType -> BaseType");
556 $$ = $1;
557 }
Mark Sleee8540632006-05-30 09:24:40 +0000558| ContainerType
559 {
560 pdebug("DefinitionType -> ContainerType");
561 $$ = $1;
562 }
Mark Slee31985722006-05-24 21:45:31 +0000563
564FunctionType:
565 FieldType
566 {
Mark Sleee8540632006-05-30 09:24:40 +0000567 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000568 $$ = $1;
569 }
570| tok_void
571 {
Mark Sleee8540632006-05-30 09:24:40 +0000572 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000573 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000574 }
575
576FieldType:
577 tok_identifier
578 {
Mark Sleee8540632006-05-30 09:24:40 +0000579 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000580 if (g_parse_mode == INCLUDES) {
581 // Ignore identifiers in include mode
582 $$ = NULL;
583 } else {
584 // Lookup the identifier in the current scope
585 $$ = g_scope->get_type($1);
586 if ($$ == NULL) {
587 yyerror("Type \"%s\" has not been defined.", $1);
588 exit(1);
589 }
Mark Sleee8540632006-05-30 09:24:40 +0000590 }
Mark Slee31985722006-05-24 21:45:31 +0000591 }
592| BaseType
593 {
Mark Sleee8540632006-05-30 09:24:40 +0000594 pdebug("FieldType -> BaseType");
595 $$ = $1;
596 }
597| ContainerType
598 {
599 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000600 $$ = $1;
601 }
602
603BaseType:
604 tok_string
605 {
606 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000607 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000608 }
Mark Slee78f58e22006-09-02 04:17:07 +0000609| tok_bool
610 {
611 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000612 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000613 }
Mark Slee31985722006-05-24 21:45:31 +0000614| tok_byte
615 {
616 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000617 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000618 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000619| tok_i16
620 {
621 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000622 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000623 }
Mark Slee31985722006-05-24 21:45:31 +0000624| tok_i32
625 {
626 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000627 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000628 }
Mark Slee31985722006-05-24 21:45:31 +0000629| tok_i64
630 {
631 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000632 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000633 }
Mark Sleec98d0502006-09-06 02:42:25 +0000634| tok_double
635 {
636 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000637 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000638 }
Mark Slee31985722006-05-24 21:45:31 +0000639
Mark Sleee8540632006-05-30 09:24:40 +0000640ContainerType:
641 MapType
642 {
643 pdebug("ContainerType -> MapType");
644 $$ = $1;
645 }
646| SetType
647 {
648 pdebug("ContainerType -> SetType");
649 $$ = $1;
650 }
651| ListType
652 {
653 pdebug("ContainerType -> ListType");
654 $$ = $1;
655 }
656
657MapType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000658 tok_map CppTypeOptional '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000659 {
660 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000661 $$ = new t_map($4, $6);
662 if ($2 != NULL) {
663 ((t_container*)$$)->set_cpp_name(std::string($2));
664 }
Mark Sleee8540632006-05-30 09:24:40 +0000665 }
666
667SetType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000668 tok_set CppTypeOptional '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000669 {
670 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000671 $$ = new t_set($4);
672 if ($2 != NULL) {
673 ((t_container*)$$)->set_cpp_name(std::string($2));
674 }
Mark Sleee8540632006-05-30 09:24:40 +0000675 }
676
677ListType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000678 tok_list '<' FieldType '>' CppTypeOptional
Mark Sleee8540632006-05-30 09:24:40 +0000679 {
680 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000681 $$ = new t_list($3);
682 if ($5 != NULL) {
683 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000684 }
685 }
686
687CppTypeOptional:
Mark Sleef0712dc2006-10-25 19:03:57 +0000688 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000689 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000690 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000691 }
692|
693 {
694 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000695 }
696
Mark Slee31985722006-05-24 21:45:31 +0000697%%