blob: e1dd84f78df7ebcc47bd7bda2b389cd4e2105499 [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 {
31 char* id;
32 int iconst;
Mark Slee52f643d2006-08-09 00:03:43 +000033 bool tbool;
Mark Slee31985722006-05-24 21:45:31 +000034 t_type* ttype;
35 t_typedef* ttypedef;
36 t_enum* tenum;
37 t_struct* tstruct;
38 t_service* tservice;
39 t_function* tfunction;
40 t_field* tfield;
Mark Slee31985722006-05-24 21:45:31 +000041 t_constant* tconstant;
42}
43
Mark Sleef5377b32006-10-10 01:42:59 +000044/**
45 * Strings identifier
46 */
Mark Slee31985722006-05-24 21:45:31 +000047%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000048%token<id> tok_literal
Mark Sleef5377b32006-10-10 01:42:59 +000049
50/**
51 * Integer constant value
52 */
Mark Slee31985722006-05-24 21:45:31 +000053%token<iconst> tok_int_constant
54
Mark Sleef5377b32006-10-10 01:42:59 +000055/**
Mark Sleef0712dc2006-10-25 19:03:57 +000056 * Header keywoards
Mark Sleef5377b32006-10-10 01:42:59 +000057 */
Mark Sleef0712dc2006-10-25 19:03:57 +000058%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000059%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000060%token tok_cpp_namespace
61%token tok_cpp_include
62%token tok_cpp_type
63%token tok_java_package
Mark Slee9cb7c612006-09-01 22:17:45 +000064
Mark Sleef5377b32006-10-10 01:42:59 +000065/**
66 * Base datatype keywords
67 */
68%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000069%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000070%token tok_byte
71%token tok_string
Mark Slee9cb7c612006-09-01 22:17:45 +000072%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000073%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000074%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000075%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000076
Mark Sleef5377b32006-10-10 01:42:59 +000077/**
78 * Complex type keywords
79 */
Mark Slee31985722006-05-24 21:45:31 +000080%token tok_map
81%token tok_list
82%token tok_set
83
Mark Sleef5377b32006-10-10 01:42:59 +000084/**
85 * Function modifiers
86 */
Mark Slee31985722006-05-24 21:45:31 +000087%token tok_async
88
Mark Sleef5377b32006-10-10 01:42:59 +000089/**
90 * Thrift language keywords
91 */
Mark Slee31985722006-05-24 21:45:31 +000092%token tok_typedef
93%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +000094%token tok_xception
95%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +000096%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +000097%token tok_service
98%token tok_enum
99
Mark Sleef5377b32006-10-10 01:42:59 +0000100/**
101 * Grammar nodes
102 */
103
Mark Slee31985722006-05-24 21:45:31 +0000104%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000105%type<ttype> ContainerType
106%type<ttype> MapType
107%type<ttype> SetType
108%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000109
Mark Sleef0712dc2006-10-25 19:03:57 +0000110%type<ttype> TypeDefinition
111
Mark Slee31985722006-05-24 21:45:31 +0000112%type<ttypedef> Typedef
113%type<ttype> DefinitionType
114
115%type<tfield> Field
116%type<ttype> FieldType
Mark Sleee8540632006-05-30 09:24:40 +0000117%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000118
119%type<tenum> Enum
120%type<tenum> EnumDefList
121%type<tconstant> EnumDef
122
123%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000124%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000125%type<tservice> Service
126
127%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000128%type<ttype> FunctionType
129%type<tservice> FunctionList
130
Mark Sleef5377b32006-10-10 01:42:59 +0000131%type<tstruct> ThrowsOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000132%type<tservice> ExtendsOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000133%type<tbool> AsyncOptional
Mark Slee4f8da1d2006-10-12 02:47:27 +0000134%type<id> CppTypeOptional
Mark Slee52f643d2006-08-09 00:03:43 +0000135
Mark Slee31985722006-05-24 21:45:31 +0000136%%
137
Mark Sleef5377b32006-10-10 01:42:59 +0000138/**
139 * Thrift Grammar Implementation.
140 *
141 * For the most part this source file works its way top down from what you
142 * might expect to find in a typical .thrift file, i.e. type definitions and
143 * namespaces up top followed by service definitions using those types.
144 */
Mark Slee31985722006-05-24 21:45:31 +0000145
146Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000147 HeaderList DefinitionList
148 {
149 pdebug("Program -> Headers DefinitionList");
150 }
151
152HeaderList:
153 HeaderList Header
154 {
155 pdebug("HeaderList -> HeaderList Header");
156 }
157|
158 {
159 pdebug("HeaderList -> ");
160 }
161
162Header:
163 Include
164 {
165 pdebug("Header -> Include");
166 }
167| tok_namespace tok_identifier
168 {
169 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
170 if (g_parse_mode == PROGRAM) {
171 g_program->set_cpp_namespace($2);
172 g_program->set_java_package($2);
173 }
174 }
175| tok_cpp_namespace tok_identifier
176 {
177 pdebug("Header -> tok_cpp_namespace tok_identifier");
178 if (g_parse_mode == PROGRAM) {
179 g_program->set_cpp_namespace($2);
180 }
181 }
182| tok_cpp_include tok_literal
183 {
184 pdebug("Header -> tok_cpp_include tok_literal");
185 if (g_parse_mode == PROGRAM) {
186 g_program->add_cpp_include($2);
187 }
188 }
189| tok_java_package tok_identifier
190 {
191 pdebug("Header -> tok_java_package tok_identifier");
192 if (g_parse_mode == PROGRAM) {
193 g_program->set_java_package($2);
194 }
195 }
196
197Include:
198 tok_include tok_literal
199 {
200 pdebug("Include -> tok_include tok_literal");
201 if (g_parse_mode == INCLUDES) {
202 std::string path = include_file(std::string($2));
203 if (!path.empty()) {
204 g_program->add_include(path);
205 }
206 }
207 }
Mark Slee31985722006-05-24 21:45:31 +0000208
209DefinitionList:
210 DefinitionList Definition
211 {
212 pdebug("DefinitionList -> DefinitionList Definition");
213 }
214|
215 {
216 pdebug("DefinitionList -> ");
217 }
218
219Definition:
Mark Sleef0712dc2006-10-25 19:03:57 +0000220 TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000221 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000222 pdebug("Definition -> TypeDefinition");
223 if (g_parse_mode == PROGRAM) {
224 g_scope->add_type($1->get_name(), $1);
225 if (g_parent_scope != NULL) {
226 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
227 }
228 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000229 }
Mark Slee31985722006-05-24 21:45:31 +0000230| Service
231 {
232 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000233 if (g_parse_mode == PROGRAM) {
234 g_scope->add_service($1->get_name(), $1);
235 if (g_parent_scope != NULL) {
236 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
237 }
238 g_program->add_service($1);
239 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000240 }
241
Mark Sleef0712dc2006-10-25 19:03:57 +0000242TypeDefinition:
243 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000244 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000245 pdebug("TypeDefinition -> Typedef");
246 if (g_parse_mode == PROGRAM) {
247 g_program->add_typedef($1);
248 }
249 }
250| Enum
251 {
252 pdebug("TypeDefinition -> Enum");
253 if (g_parse_mode == PROGRAM) {
254 g_program->add_enum($1);
255 }
256 }
257| Struct
258 {
259 pdebug("TypeDefinition -> Struct");
260 if (g_parse_mode == PROGRAM) {
261 g_program->add_struct($1);
262 }
263 }
264| Xception
265 {
266 pdebug("TypeDefinition -> Xception");
267 if (g_parse_mode == PROGRAM) {
268 g_program->add_xception($1);
269 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000270 }
Mark Slee31985722006-05-24 21:45:31 +0000271
272Typedef:
273 tok_typedef DefinitionType tok_identifier
274 {
275 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000276 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000277 $$ = td;
278 }
279
280Enum:
281 tok_enum tok_identifier '{' EnumDefList '}'
282 {
283 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
284 $$ = $4;
285 $$->set_name($2);
286 }
287
Mark Slee207cb462006-11-02 18:43:12 +0000288CommaOrSemicolonOptional:
289 ','
290 {}
291| ';'
292 {}
293|
294 {}
295
Mark Slee31985722006-05-24 21:45:31 +0000296EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000297 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000298 {
299 pdebug("EnumDefList -> EnumDefList EnumDef");
300 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000301 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000302 }
303|
304 {
305 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000306 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000307 }
308
309EnumDef:
Mark Slee207cb462006-11-02 18:43:12 +0000310 tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000311 {
Mark Sleee8540632006-05-30 09:24:40 +0000312 pdebug("EnumDef => tok_identifier = tok_int_constant");
Mark Slee31985722006-05-24 21:45:31 +0000313 if ($3 < 0) {
Mark Sleef0712dc2006-10-25 19:03:57 +0000314 pwarning(1, "Negative value supplied for enum %s.\n", $1);
Mark Slee31985722006-05-24 21:45:31 +0000315 }
Mark Slee31985722006-05-24 21:45:31 +0000316 $$ = new t_constant($1, $3);
317 }
318|
Mark Slee04cc6052006-11-15 21:25:34 +0000319 tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000320 {
321 pdebug("EnumDef => tok_identifier");
322 $$ = new t_constant($1);
323 }
324
325Struct:
326 tok_struct tok_identifier '{' FieldList '}'
327 {
328 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
Mark Sleee8540632006-05-30 09:24:40 +0000329 $4->set_name($2);
330 $$ = $4;
Mark Slee9cb7c612006-09-01 22:17:45 +0000331 y_field_val = -1;
332 }
333
334Xception:
335 tok_xception tok_identifier '{' FieldList '}'
336 {
337 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
338 $4->set_name($2);
339 $4->set_xception(true);
340 $$ = $4;
341 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000342 }
343
344Service:
Mark Sleef0712dc2006-10-25 19:03:57 +0000345 tok_service tok_identifier ExtendsOptional '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000346 {
347 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Sleef0712dc2006-10-25 19:03:57 +0000348 $$ = $5;
Mark Slee31985722006-05-24 21:45:31 +0000349 $$->set_name($2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000350 $$->set_extends($3);
351 }
352
353ExtendsOptional:
354 tok_extends tok_identifier
355 {
356 pdebug("ExtendsOptional -> tok_extends tok_identifier");
357 $$ = NULL;
358 if (g_parse_mode == PROGRAM) {
359 $$ = g_scope->get_service($2);
360 if ($$ == NULL) {
361 yyerror("Service \"%s\" has not been defined.", $2);
362 exit(1);
363 }
364 }
365 }
366|
367 {
368 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000369 }
370
371FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000372 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000373 {
374 pdebug("FunctionList -> FunctionList Function");
375 $$ = $1;
376 $1->add_function($2);
377 }
378|
379 {
380 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000381 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000382 }
383
384Function:
Mark Slee207cb462006-11-02 18:43:12 +0000385 AsyncOptional FunctionType tok_identifier '(' FieldList ')' ThrowsOptional CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000386 {
Mark Sleeb15a68b2006-06-07 06:46:24 +0000387 $5->set_name(std::string($3) + "_args");
Mark Slee4e755ca2006-09-12 00:46:08 +0000388 $$ = new t_function($2, $3, $5, $7, $1);
Mark Slee9cb7c612006-09-01 22:17:45 +0000389 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000390 }
391
Mark Slee52f643d2006-08-09 00:03:43 +0000392AsyncOptional:
393 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000394 {
Mark Slee52f643d2006-08-09 00:03:43 +0000395 $$ = true;
396 }
397|
398 {
399 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000400 }
401
Mark Slee9cb7c612006-09-01 22:17:45 +0000402ThrowsOptional:
403 tok_throws '(' FieldList ')'
404 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000405 pdebug("ThrowsOptional -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000406 $$ = $3;
407 }
408|
409 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000410 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000411 }
412
Mark Slee31985722006-05-24 21:45:31 +0000413FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000414 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000415 {
416 pdebug("FieldList -> FieldList , Field");
417 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000418 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000419 }
420|
421 {
422 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000423 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000424 }
425
426Field:
Mark Slee207cb462006-11-02 18:43:12 +0000427 tok_int_constant ':' FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000428 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000429 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
430 if ($1 <= 0) {
431 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $1, $4);
432 $1 = y_field_val--;
Mark Slee31985722006-05-24 21:45:31 +0000433 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000434 $$ = new t_field($3, $4, $1);
Mark Slee31985722006-05-24 21:45:31 +0000435 }
Mark Slee2329a832006-11-09 00:23:30 +0000436| FieldType tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000437 {
Mark Sleee8540632006-05-30 09:24:40 +0000438 pdebug("Field -> FieldType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000439 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 +0000440 $$ = new t_field($1, $2, y_field_val--);
Mark Slee31985722006-05-24 21:45:31 +0000441 }
Mark Slee2329a832006-11-09 00:23:30 +0000442| FieldType tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000443 {
Mark Slee2329a832006-11-09 00:23:30 +0000444 pwarning(1, "Trailing = id notation is deprecated. Use 'Id: Type Name' notation instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000445 pdebug("Field -> FieldType tok_identifier = tok_int_constant");
446 if ($4 <= 0) {
447 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $4, $2);
448 $4 = y_field_val--;
449 }
450 $$ = new t_field($1, $2, $4);
451 }
Mark Slee31985722006-05-24 21:45:31 +0000452
453DefinitionType:
454 BaseType
455 {
456 pdebug("DefinitionType -> BaseType");
457 $$ = $1;
458 }
Mark Sleee8540632006-05-30 09:24:40 +0000459| ContainerType
460 {
461 pdebug("DefinitionType -> ContainerType");
462 $$ = $1;
463 }
Mark Slee31985722006-05-24 21:45:31 +0000464
465FunctionType:
466 FieldType
467 {
Mark Sleee8540632006-05-30 09:24:40 +0000468 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000469 $$ = $1;
470 }
471| tok_void
472 {
Mark Sleee8540632006-05-30 09:24:40 +0000473 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000474 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000475 }
476
477FieldType:
478 tok_identifier
479 {
Mark Sleee8540632006-05-30 09:24:40 +0000480 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000481 if (g_parse_mode == INCLUDES) {
482 // Ignore identifiers in include mode
483 $$ = NULL;
484 } else {
485 // Lookup the identifier in the current scope
486 $$ = g_scope->get_type($1);
487 if ($$ == NULL) {
488 yyerror("Type \"%s\" has not been defined.", $1);
489 exit(1);
490 }
Mark Sleee8540632006-05-30 09:24:40 +0000491 }
Mark Slee31985722006-05-24 21:45:31 +0000492 }
493| BaseType
494 {
Mark Sleee8540632006-05-30 09:24:40 +0000495 pdebug("FieldType -> BaseType");
496 $$ = $1;
497 }
498| ContainerType
499 {
500 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000501 $$ = $1;
502 }
503
504BaseType:
505 tok_string
506 {
507 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000508 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000509 }
Mark Slee78f58e22006-09-02 04:17:07 +0000510| tok_bool
511 {
512 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000513 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000514 }
Mark Slee31985722006-05-24 21:45:31 +0000515| tok_byte
516 {
517 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000518 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000519 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000520| tok_i16
521 {
522 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000523 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000524 }
Mark Slee31985722006-05-24 21:45:31 +0000525| tok_i32
526 {
527 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000528 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000529 }
Mark Slee31985722006-05-24 21:45:31 +0000530| tok_i64
531 {
532 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000533 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000534 }
Mark Sleec98d0502006-09-06 02:42:25 +0000535| tok_double
536 {
537 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000538 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000539 }
Mark Slee31985722006-05-24 21:45:31 +0000540
Mark Sleee8540632006-05-30 09:24:40 +0000541ContainerType:
542 MapType
543 {
544 pdebug("ContainerType -> MapType");
545 $$ = $1;
546 }
547| SetType
548 {
549 pdebug("ContainerType -> SetType");
550 $$ = $1;
551 }
552| ListType
553 {
554 pdebug("ContainerType -> ListType");
555 $$ = $1;
556 }
557
558MapType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000559 tok_map CppTypeOptional '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000560 {
561 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000562 $$ = new t_map($4, $6);
563 if ($2 != NULL) {
564 ((t_container*)$$)->set_cpp_name(std::string($2));
565 }
Mark Sleee8540632006-05-30 09:24:40 +0000566 }
567
568SetType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000569 tok_set CppTypeOptional '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000570 {
571 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000572 $$ = new t_set($4);
573 if ($2 != NULL) {
574 ((t_container*)$$)->set_cpp_name(std::string($2));
575 }
Mark Sleee8540632006-05-30 09:24:40 +0000576 }
577
578ListType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000579 tok_list '<' FieldType '>' CppTypeOptional
Mark Sleee8540632006-05-30 09:24:40 +0000580 {
581 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000582 $$ = new t_list($3);
583 if ($5 != NULL) {
584 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000585 }
586 }
587
588CppTypeOptional:
Mark Sleef0712dc2006-10-25 19:03:57 +0000589 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000590 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000591 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000592 }
593|
594 {
595 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000596 }
597
Mark Slee31985722006-05-24 21:45:31 +0000598%%