blob: 7d1ba1e1efee85058dd2094c8543e9a6260a16a3 [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
288EnumDefList:
289 EnumDefList ',' EnumDef
290 {
291 pdebug("EnumDefList -> EnumDefList EnumDef");
292 $$ = $1;
293 $$->append($3);
294 }
295| EnumDef
296 {
297 pdebug("EnumDefList -> EnumDef");
Mark Sleef0712dc2006-10-25 19:03:57 +0000298 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000299 $$->append($1);
300 }
301|
302 {
303 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000304 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000305 }
306
307EnumDef:
308 tok_identifier '=' tok_int_constant
309 {
Mark Sleee8540632006-05-30 09:24:40 +0000310 pdebug("EnumDef => tok_identifier = tok_int_constant");
Mark Slee31985722006-05-24 21:45:31 +0000311 if ($3 < 0) {
Mark Sleef0712dc2006-10-25 19:03:57 +0000312 pwarning(1, "Negative value supplied for enum %s.\n", $1);
Mark Slee31985722006-05-24 21:45:31 +0000313 }
Mark Slee31985722006-05-24 21:45:31 +0000314 $$ = new t_constant($1, $3);
315 }
316|
317 tok_identifier
318 {
319 pdebug("EnumDef => tok_identifier");
320 $$ = new t_constant($1);
321 }
322
323Struct:
324 tok_struct tok_identifier '{' FieldList '}'
325 {
326 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
Mark Sleee8540632006-05-30 09:24:40 +0000327 $4->set_name($2);
328 $$ = $4;
Mark Slee9cb7c612006-09-01 22:17:45 +0000329 y_field_val = -1;
330 }
331
332Xception:
333 tok_xception tok_identifier '{' FieldList '}'
334 {
335 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
336 $4->set_name($2);
337 $4->set_xception(true);
338 $$ = $4;
339 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000340 }
341
342Service:
Mark Sleef0712dc2006-10-25 19:03:57 +0000343 tok_service tok_identifier ExtendsOptional '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000344 {
345 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Sleef0712dc2006-10-25 19:03:57 +0000346 $$ = $5;
Mark Slee31985722006-05-24 21:45:31 +0000347 $$->set_name($2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000348 $$->set_extends($3);
349 }
350
351ExtendsOptional:
352 tok_extends tok_identifier
353 {
354 pdebug("ExtendsOptional -> tok_extends tok_identifier");
355 $$ = NULL;
356 if (g_parse_mode == PROGRAM) {
357 $$ = g_scope->get_service($2);
358 if ($$ == NULL) {
359 yyerror("Service \"%s\" has not been defined.", $2);
360 exit(1);
361 }
362 }
363 }
364|
365 {
366 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000367 }
368
369FunctionList:
Mark Slee9cb7c612006-09-01 22:17:45 +0000370 FunctionList Function CommaOptional
Mark Slee31985722006-05-24 21:45:31 +0000371 {
372 pdebug("FunctionList -> FunctionList Function");
373 $$ = $1;
374 $1->add_function($2);
375 }
376|
377 {
378 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000379 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000380 }
381
Mark Slee9cb7c612006-09-01 22:17:45 +0000382CommaOptional:
383 ','
384 {}
385|
386 {}
387
Mark Slee31985722006-05-24 21:45:31 +0000388Function:
Mark Slee4e755ca2006-09-12 00:46:08 +0000389 AsyncOptional FunctionType tok_identifier '(' FieldList ')' ThrowsOptional
Mark Slee31985722006-05-24 21:45:31 +0000390 {
Mark Sleeb15a68b2006-06-07 06:46:24 +0000391 $5->set_name(std::string($3) + "_args");
Mark Slee4e755ca2006-09-12 00:46:08 +0000392 $$ = new t_function($2, $3, $5, $7, $1);
Mark Slee9cb7c612006-09-01 22:17:45 +0000393 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000394 }
395
Mark Slee52f643d2006-08-09 00:03:43 +0000396AsyncOptional:
397 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000398 {
Mark Slee52f643d2006-08-09 00:03:43 +0000399 $$ = true;
400 }
401|
402 {
403 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000404 }
405
Mark Slee9cb7c612006-09-01 22:17:45 +0000406ThrowsOptional:
407 tok_throws '(' FieldList ')'
408 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000409 pdebug("ThrowsOptional -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000410 $$ = $3;
411 }
412|
413 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000414 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000415 }
416
Mark Slee31985722006-05-24 21:45:31 +0000417FieldList:
418 FieldList ',' Field
419 {
420 pdebug("FieldList -> FieldList , Field");
421 $$ = $1;
422 $$->append($3);
423 }
424| Field
425 {
426 pdebug("FieldList -> Field");
Mark Sleef0712dc2006-10-25 19:03:57 +0000427 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000428 $$->append($1);
429 }
430|
431 {
432 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000433 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000434 }
435
436Field:
Mark Sleef0712dc2006-10-25 19:03:57 +0000437 tok_int_constant ':' FieldType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000438 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000439 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
440 if ($1 <= 0) {
441 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $1, $4);
442 $1 = y_field_val--;
Mark Slee31985722006-05-24 21:45:31 +0000443 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000444 $$ = new t_field($3, $4, $1);
Mark Slee31985722006-05-24 21:45:31 +0000445 }
446| FieldType tok_identifier
447 {
Mark Sleee8540632006-05-30 09:24:40 +0000448 pdebug("Field -> FieldType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000449 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 +0000450 $$ = new t_field($1, $2, y_field_val--);
Mark Slee31985722006-05-24 21:45:31 +0000451 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000452| FieldType tok_identifier '=' tok_int_constant
453 {
454 pwarning(1, "Trailing = id notation is deprecated. Use 'Id: Type Name' notatio instead");
455 pdebug("Field -> FieldType tok_identifier = tok_int_constant");
456 if ($4 <= 0) {
457 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $4, $2);
458 $4 = y_field_val--;
459 }
460 $$ = new t_field($1, $2, $4);
461 }
Mark Slee31985722006-05-24 21:45:31 +0000462
463DefinitionType:
464 BaseType
465 {
466 pdebug("DefinitionType -> BaseType");
467 $$ = $1;
468 }
Mark Sleee8540632006-05-30 09:24:40 +0000469| ContainerType
470 {
471 pdebug("DefinitionType -> ContainerType");
472 $$ = $1;
473 }
Mark Slee31985722006-05-24 21:45:31 +0000474
475FunctionType:
476 FieldType
477 {
Mark Sleee8540632006-05-30 09:24:40 +0000478 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000479 $$ = $1;
480 }
481| tok_void
482 {
Mark Sleee8540632006-05-30 09:24:40 +0000483 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000484 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000485 }
486
487FieldType:
488 tok_identifier
489 {
Mark Sleee8540632006-05-30 09:24:40 +0000490 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000491 if (g_parse_mode == INCLUDES) {
492 // Ignore identifiers in include mode
493 $$ = NULL;
494 } else {
495 // Lookup the identifier in the current scope
496 $$ = g_scope->get_type($1);
497 if ($$ == NULL) {
498 yyerror("Type \"%s\" has not been defined.", $1);
499 exit(1);
500 }
Mark Sleee8540632006-05-30 09:24:40 +0000501 }
Mark Slee31985722006-05-24 21:45:31 +0000502 }
503| BaseType
504 {
Mark Sleee8540632006-05-30 09:24:40 +0000505 pdebug("FieldType -> BaseType");
506 $$ = $1;
507 }
508| ContainerType
509 {
510 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000511 $$ = $1;
512 }
513
514BaseType:
515 tok_string
516 {
517 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000518 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000519 }
Mark Slee78f58e22006-09-02 04:17:07 +0000520| tok_bool
521 {
522 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000523 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000524 }
Mark Slee31985722006-05-24 21:45:31 +0000525| tok_byte
526 {
527 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000528 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000529 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000530| tok_i16
531 {
532 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000533 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000534 }
Mark Slee31985722006-05-24 21:45:31 +0000535| tok_i32
536 {
537 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000538 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000539 }
Mark Slee31985722006-05-24 21:45:31 +0000540| tok_i64
541 {
542 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000543 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000544 }
Mark Sleec98d0502006-09-06 02:42:25 +0000545| tok_double
546 {
547 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000548 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000549 }
Mark Slee31985722006-05-24 21:45:31 +0000550
Mark Sleee8540632006-05-30 09:24:40 +0000551ContainerType:
552 MapType
553 {
554 pdebug("ContainerType -> MapType");
555 $$ = $1;
556 }
557| SetType
558 {
559 pdebug("ContainerType -> SetType");
560 $$ = $1;
561 }
562| ListType
563 {
564 pdebug("ContainerType -> ListType");
565 $$ = $1;
566 }
567
568MapType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000569 tok_map CppTypeOptional '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000570 {
571 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000572 $$ = new t_map($4, $6);
573 if ($2 != NULL) {
574 ((t_container*)$$)->set_cpp_name(std::string($2));
575 }
Mark Sleee8540632006-05-30 09:24:40 +0000576 }
577
578SetType:
Mark Slee4f8da1d2006-10-12 02:47:27 +0000579 tok_set CppTypeOptional '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000580 {
581 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000582 $$ = new t_set($4);
583 if ($2 != NULL) {
584 ((t_container*)$$)->set_cpp_name(std::string($2));
585 }
Mark Sleee8540632006-05-30 09:24:40 +0000586 }
587
588ListType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000589 tok_list '<' FieldType '>' CppTypeOptional
Mark Sleee8540632006-05-30 09:24:40 +0000590 {
591 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000592 $$ = new t_list($3);
593 if ($5 != NULL) {
594 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000595 }
596 }
597
598CppTypeOptional:
Mark Sleef0712dc2006-10-25 19:03:57 +0000599 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000600 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000601 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000602 }
603|
604 {
605 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000606 }
607
Mark Slee31985722006-05-24 21:45:31 +0000608%%