blob: a90d64b327354bfd25f791f9c7d15c9dc4f9485a [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
Mark Sleee888b372007-01-12 01:06:24 +000067%token tok_php_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000068%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000069%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000070%token tok_xsd_optional
Mark Slee0d9199e2007-01-31 02:08:30 +000071%token tok_xsd_namespace
Mark Slee9cb7c612006-09-01 22:17:45 +000072
Mark Sleef5377b32006-10-10 01:42:59 +000073/**
74 * Base datatype keywords
75 */
76%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000077%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000078%token tok_byte
79%token tok_string
Mark Sleeb6200d82007-01-19 19:14:36 +000080%token tok_slist
Mark Slee9cb7c612006-09-01 22:17:45 +000081%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000082%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000083%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000084%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000085
Mark Sleef5377b32006-10-10 01:42:59 +000086/**
87 * Complex type keywords
88 */
Mark Slee31985722006-05-24 21:45:31 +000089%token tok_map
90%token tok_list
91%token tok_set
92
Mark Sleef5377b32006-10-10 01:42:59 +000093/**
94 * Function modifiers
95 */
Mark Slee31985722006-05-24 21:45:31 +000096%token tok_async
97
Mark Sleef5377b32006-10-10 01:42:59 +000098/**
99 * Thrift language keywords
100 */
Mark Slee31985722006-05-24 21:45:31 +0000101%token tok_typedef
102%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000103%token tok_xception
104%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000105%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000106%token tok_service
107%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000108%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000109
Mark Sleef5377b32006-10-10 01:42:59 +0000110/**
111 * Grammar nodes
112 */
113
Mark Slee31985722006-05-24 21:45:31 +0000114%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000115%type<ttype> ContainerType
116%type<ttype> MapType
117%type<ttype> SetType
118%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000119
Mark Sleef0712dc2006-10-25 19:03:57 +0000120%type<ttype> TypeDefinition
121
Mark Slee31985722006-05-24 21:45:31 +0000122%type<ttypedef> Typedef
123%type<ttype> DefinitionType
124
125%type<tfield> Field
126%type<ttype> FieldType
Mark Sleee8540632006-05-30 09:24:40 +0000127%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000128
129%type<tenum> Enum
130%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000131%type<tenumv> EnumDef
132
133%type<tconst> Const
134%type<tconstv> ConstValue
135%type<tconstv> ConstList
136%type<tconstv> ConstListContents
137%type<tconstv> ConstMap
138%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000139
140%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000141%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000142%type<tservice> Service
143
144%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000145%type<ttype> FunctionType
146%type<tservice> FunctionList
147
Mark Slee36bfa2e2007-01-19 20:09:51 +0000148%type<tstruct> Throws
149%type<tservice> Extends
150%type<tbool> Async
151%type<tbool> XsdAll
152%type<tbool> XsdOptional
153%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000154
Mark Slee31985722006-05-24 21:45:31 +0000155%%
156
Mark Sleef5377b32006-10-10 01:42:59 +0000157/**
158 * Thrift Grammar Implementation.
159 *
160 * For the most part this source file works its way top down from what you
161 * might expect to find in a typical .thrift file, i.e. type definitions and
162 * namespaces up top followed by service definitions using those types.
163 */
Mark Slee31985722006-05-24 21:45:31 +0000164
165Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000166 HeaderList DefinitionList
167 {
168 pdebug("Program -> Headers DefinitionList");
169 }
170
171HeaderList:
172 HeaderList Header
173 {
174 pdebug("HeaderList -> HeaderList Header");
175 }
176|
177 {
178 pdebug("HeaderList -> ");
179 }
180
181Header:
182 Include
183 {
184 pdebug("Header -> Include");
185 }
186| tok_namespace tok_identifier
187 {
188 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
189 if (g_parse_mode == PROGRAM) {
190 g_program->set_cpp_namespace($2);
191 g_program->set_java_package($2);
192 }
193 }
194| tok_cpp_namespace tok_identifier
195 {
196 pdebug("Header -> tok_cpp_namespace tok_identifier");
197 if (g_parse_mode == PROGRAM) {
198 g_program->set_cpp_namespace($2);
199 }
200 }
201| tok_cpp_include tok_literal
202 {
203 pdebug("Header -> tok_cpp_include tok_literal");
204 if (g_parse_mode == PROGRAM) {
205 g_program->add_cpp_include($2);
206 }
207 }
Mark Sleee888b372007-01-12 01:06:24 +0000208| tok_php_namespace tok_identifier
209 {
210 pdebug("Header -> tok_php_namespace tok_identifier");
211 if (g_parse_mode == PROGRAM) {
212 g_program->set_php_namespace($2);
213 }
214 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000215| tok_java_package tok_identifier
216 {
217 pdebug("Header -> tok_java_package tok_identifier");
218 if (g_parse_mode == PROGRAM) {
219 g_program->set_java_package($2);
220 }
221 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000222| tok_xsd_namespace tok_literal
223 {
224 pdebug("Header -> tok_xsd_namespace tok_literal");
225 if (g_parse_mode == PROGRAM) {
226 g_program->set_xsd_namespace($2);
227 }
228 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000229
230Include:
231 tok_include tok_literal
232 {
233 pdebug("Include -> tok_include tok_literal");
234 if (g_parse_mode == INCLUDES) {
235 std::string path = include_file(std::string($2));
236 if (!path.empty()) {
237 g_program->add_include(path);
238 }
239 }
240 }
Mark Slee31985722006-05-24 21:45:31 +0000241
242DefinitionList:
243 DefinitionList Definition
244 {
245 pdebug("DefinitionList -> DefinitionList Definition");
246 }
247|
248 {
249 pdebug("DefinitionList -> ");
250 }
251
252Definition:
Mark Slee30152872006-11-28 01:24:07 +0000253 Const
254 {
255 pdebug("Definition -> Const");
256 if (g_parse_mode == PROGRAM) {
257 g_program->add_const($1);
258 }
259 }
260| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000261 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000262 pdebug("Definition -> TypeDefinition");
263 if (g_parse_mode == PROGRAM) {
264 g_scope->add_type($1->get_name(), $1);
265 if (g_parent_scope != NULL) {
266 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
267 }
268 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000269 }
Mark Slee31985722006-05-24 21:45:31 +0000270| Service
271 {
272 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000273 if (g_parse_mode == PROGRAM) {
274 g_scope->add_service($1->get_name(), $1);
275 if (g_parent_scope != NULL) {
276 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
277 }
278 g_program->add_service($1);
279 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000280 }
281
Mark Sleef0712dc2006-10-25 19:03:57 +0000282TypeDefinition:
283 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000284 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000285 pdebug("TypeDefinition -> Typedef");
286 if (g_parse_mode == PROGRAM) {
287 g_program->add_typedef($1);
288 }
289 }
290| Enum
291 {
292 pdebug("TypeDefinition -> Enum");
293 if (g_parse_mode == PROGRAM) {
294 g_program->add_enum($1);
295 }
296 }
297| Struct
298 {
299 pdebug("TypeDefinition -> Struct");
300 if (g_parse_mode == PROGRAM) {
301 g_program->add_struct($1);
302 }
303 }
304| Xception
305 {
306 pdebug("TypeDefinition -> Xception");
307 if (g_parse_mode == PROGRAM) {
308 g_program->add_xception($1);
309 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000310 }
Mark Slee31985722006-05-24 21:45:31 +0000311
312Typedef:
313 tok_typedef DefinitionType tok_identifier
314 {
315 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000316 t_typedef *td = new t_typedef(g_program, $2, $3);
Mark Slee31985722006-05-24 21:45:31 +0000317 $$ = td;
318 }
319
320Enum:
321 tok_enum tok_identifier '{' EnumDefList '}'
322 {
323 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
324 $$ = $4;
325 $$->set_name($2);
326 }
327
Mark Slee207cb462006-11-02 18:43:12 +0000328CommaOrSemicolonOptional:
329 ','
330 {}
331| ';'
332 {}
333|
334 {}
335
Mark Slee31985722006-05-24 21:45:31 +0000336EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000337 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000338 {
339 pdebug("EnumDefList -> EnumDefList EnumDef");
340 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000341 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000342 }
343|
344 {
345 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000346 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000347 }
348
349EnumDef:
Mark Slee207cb462006-11-02 18:43:12 +0000350 tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000351 {
Mark Slee30152872006-11-28 01:24:07 +0000352 pdebug("EnumDef -> tok_identifier = tok_int_constant");
Mark Slee31985722006-05-24 21:45:31 +0000353 if ($3 < 0) {
Mark Sleef0712dc2006-10-25 19:03:57 +0000354 pwarning(1, "Negative value supplied for enum %s.\n", $1);
Mark Slee31985722006-05-24 21:45:31 +0000355 }
Mark Slee30152872006-11-28 01:24:07 +0000356 $$ = new t_enum_value($1, $3);
Mark Slee31985722006-05-24 21:45:31 +0000357 }
358|
Mark Slee04cc6052006-11-15 21:25:34 +0000359 tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000360 {
Mark Slee30152872006-11-28 01:24:07 +0000361 pdebug("EnumDef -> tok_identifier");
362 $$ = new t_enum_value($1);
363 }
364
365Const:
366 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
367 {
368 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000369 if (g_parse_mode == PROGRAM) {
370 $$ = new t_const($2, $3, $5);
371 validate_const_type($$);
372 } else {
373 $$ = NULL;
374 }
Mark Slee30152872006-11-28 01:24:07 +0000375 }
376
377ConstValue:
378 tok_int_constant
379 {
380 pdebug("ConstValue => tok_int_constant");
381 $$ = new t_const_value();
382 $$->set_integer($1);
383 }
384| tok_dub_constant
385 {
386 pdebug("ConstValue => tok_dub_constant");
387 $$ = new t_const_value();
388 $$->set_double($1);
389 }
390| tok_literal
391 {
392 pdebug("ConstValue => tok_literal");
393 $$ = new t_const_value();
394 $$->set_string($1);
395 }
Mark Slee67fc6342006-11-29 03:37:04 +0000396| tok_identifier
397 {
398 pdebug("ConstValue => tok_identifier");
399 $$ = new t_const_value();
400 $$->set_string($1);
401 }
Mark Slee30152872006-11-28 01:24:07 +0000402| ConstList
403 {
404 pdebug("ConstValue => ConstList");
405 $$ = $1;
406 }
407| ConstMap
408 {
409 pdebug("ConstValue => ConstMap");
410 $$ = $1;
411 }
412
413ConstList:
414 '[' ConstListContents ']'
415 {
416 pdebug("ConstList => [ ConstListContents ]");
417 $$ = $2;
418 }
419
420ConstListContents:
421 ConstListContents ConstValue CommaOrSemicolonOptional
422 {
423 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
424 $$ = $1;
425 $$->add_list($2);
426 }
427|
428 {
429 pdebug("ConstListContents =>");
430 $$ = new t_const_value();
431 $$->set_list();
432 }
433
434ConstMap:
435 '{' ConstMapContents '}'
436 {
437 pdebug("ConstMap => { ConstMapContents }");
438 $$ = $2;
439 }
440
441ConstMapContents:
442 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
443 {
444 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
445 $$ = $1;
446 $$->add_map($2, $4);
447 }
448|
449 {
450 pdebug("ConstMapContents =>");
451 $$ = new t_const_value();
452 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000453 }
454
455Struct:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000456 tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000457 {
458 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
Mark Slee782abbb2007-01-19 00:17:02 +0000459 $5->set_name($2);
460 $5->set_xsd_all($3);
461 $$ = $5;
Mark Slee9cb7c612006-09-01 22:17:45 +0000462 y_field_val = -1;
463 }
464
Mark Slee36bfa2e2007-01-19 20:09:51 +0000465XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000466 tok_xsd_all
467 {
468 $$ = true;
469 }
470|
471 {
472 $$ = false;
473 }
474
Mark Slee36bfa2e2007-01-19 20:09:51 +0000475XsdOptional:
476 tok_xsd_optional
477 {
478 $$ = true;
479 }
480|
481 {
482 $$ = false;
483 }
484
Mark Slee9cb7c612006-09-01 22:17:45 +0000485Xception:
486 tok_xception tok_identifier '{' FieldList '}'
487 {
488 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
489 $4->set_name($2);
490 $4->set_xception(true);
491 $$ = $4;
492 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000493 }
494
495Service:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000496 tok_service tok_identifier Extends '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000497 {
498 pdebug("Service -> tok_service tok_identifier { FunctionList }");
Mark Sleef0712dc2006-10-25 19:03:57 +0000499 $$ = $5;
Mark Slee31985722006-05-24 21:45:31 +0000500 $$->set_name($2);
Mark Sleef0712dc2006-10-25 19:03:57 +0000501 $$->set_extends($3);
502 }
503
Mark Slee36bfa2e2007-01-19 20:09:51 +0000504Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000505 tok_extends tok_identifier
506 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000507 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000508 $$ = NULL;
509 if (g_parse_mode == PROGRAM) {
510 $$ = g_scope->get_service($2);
511 if ($$ == NULL) {
512 yyerror("Service \"%s\" has not been defined.", $2);
513 exit(1);
514 }
515 }
516 }
517|
518 {
519 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000520 }
521
522FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000523 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000524 {
525 pdebug("FunctionList -> FunctionList Function");
526 $$ = $1;
527 $1->add_function($2);
528 }
529|
530 {
531 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000532 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000533 }
534
535Function:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000536 Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000537 {
Mark Sleeb15a68b2006-06-07 06:46:24 +0000538 $5->set_name(std::string($3) + "_args");
Mark Slee4e755ca2006-09-12 00:46:08 +0000539 $$ = new t_function($2, $3, $5, $7, $1);
Mark Slee9cb7c612006-09-01 22:17:45 +0000540 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000541 }
542
Mark Slee36bfa2e2007-01-19 20:09:51 +0000543Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000544 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000545 {
Mark Slee52f643d2006-08-09 00:03:43 +0000546 $$ = true;
547 }
548|
549 {
550 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000551 }
552
Mark Slee36bfa2e2007-01-19 20:09:51 +0000553Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000554 tok_throws '(' FieldList ')'
555 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000556 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000557 $$ = $3;
558 }
559|
560 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000561 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000562 }
563
Mark Slee31985722006-05-24 21:45:31 +0000564FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000565 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000566 {
567 pdebug("FieldList -> FieldList , Field");
568 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000569 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000570 }
571|
572 {
573 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000574 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000575 }
576
577Field:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000578 tok_int_constant ':' FieldType tok_identifier XsdOptional CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000579 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000580 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
581 if ($1 <= 0) {
582 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $1, $4);
583 $1 = y_field_val--;
Mark Slee31985722006-05-24 21:45:31 +0000584 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000585 $$ = new t_field($3, $4, $1);
Mark Slee36bfa2e2007-01-19 20:09:51 +0000586 $$->set_xsd_optional($5);
Mark Slee31985722006-05-24 21:45:31 +0000587 }
Mark Slee36bfa2e2007-01-19 20:09:51 +0000588| FieldType tok_identifier XsdOptional CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000589 {
Mark Sleee8540632006-05-30 09:24:40 +0000590 pdebug("Field -> FieldType tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000591 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 +0000592 $$ = new t_field($1, $2, y_field_val--);
Mark Slee36bfa2e2007-01-19 20:09:51 +0000593 $$->set_xsd_optional($3);
Mark Slee31985722006-05-24 21:45:31 +0000594 }
Mark Slee2329a832006-11-09 00:23:30 +0000595| FieldType tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Sleef0712dc2006-10-25 19:03:57 +0000596 {
Mark Slee2329a832006-11-09 00:23:30 +0000597 pwarning(1, "Trailing = id notation is deprecated. Use 'Id: Type Name' notation instead");
Mark Sleef0712dc2006-10-25 19:03:57 +0000598 pdebug("Field -> FieldType tok_identifier = tok_int_constant");
599 if ($4 <= 0) {
600 pwarning(1, "Nonpositive value (%d) not allowed as a field key for '%s'.\n", $4, $2);
601 $4 = y_field_val--;
602 }
603 $$ = new t_field($1, $2, $4);
604 }
Mark Slee31985722006-05-24 21:45:31 +0000605
606DefinitionType:
607 BaseType
608 {
609 pdebug("DefinitionType -> BaseType");
610 $$ = $1;
611 }
Mark Sleee8540632006-05-30 09:24:40 +0000612| ContainerType
613 {
614 pdebug("DefinitionType -> ContainerType");
615 $$ = $1;
616 }
Mark Slee31985722006-05-24 21:45:31 +0000617
618FunctionType:
619 FieldType
620 {
Mark Sleee8540632006-05-30 09:24:40 +0000621 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000622 $$ = $1;
623 }
624| tok_void
625 {
Mark Sleee8540632006-05-30 09:24:40 +0000626 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000627 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000628 }
629
630FieldType:
631 tok_identifier
632 {
Mark Sleee8540632006-05-30 09:24:40 +0000633 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000634 if (g_parse_mode == INCLUDES) {
635 // Ignore identifiers in include mode
636 $$ = NULL;
637 } else {
638 // Lookup the identifier in the current scope
639 $$ = g_scope->get_type($1);
640 if ($$ == NULL) {
641 yyerror("Type \"%s\" has not been defined.", $1);
642 exit(1);
643 }
Mark Sleee8540632006-05-30 09:24:40 +0000644 }
Mark Slee31985722006-05-24 21:45:31 +0000645 }
646| BaseType
647 {
Mark Sleee8540632006-05-30 09:24:40 +0000648 pdebug("FieldType -> BaseType");
649 $$ = $1;
650 }
651| ContainerType
652 {
653 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000654 $$ = $1;
655 }
656
657BaseType:
658 tok_string
659 {
660 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000661 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000662 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000663| tok_slist
664 {
665 pdebug("BaseType -> tok_slist");
666 $$ = g_type_slist;
667 }
Mark Slee78f58e22006-09-02 04:17:07 +0000668| tok_bool
669 {
670 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000671 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000672 }
Mark Slee31985722006-05-24 21:45:31 +0000673| tok_byte
674 {
675 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000676 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000677 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000678| tok_i16
679 {
680 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000681 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000682 }
Mark Slee31985722006-05-24 21:45:31 +0000683| tok_i32
684 {
685 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000686 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000687 }
Mark Slee31985722006-05-24 21:45:31 +0000688| tok_i64
689 {
690 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000691 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000692 }
Mark Sleec98d0502006-09-06 02:42:25 +0000693| tok_double
694 {
695 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000696 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000697 }
Mark Slee31985722006-05-24 21:45:31 +0000698
Mark Sleee8540632006-05-30 09:24:40 +0000699ContainerType:
700 MapType
701 {
702 pdebug("ContainerType -> MapType");
703 $$ = $1;
704 }
705| SetType
706 {
707 pdebug("ContainerType -> SetType");
708 $$ = $1;
709 }
710| ListType
711 {
712 pdebug("ContainerType -> ListType");
713 $$ = $1;
714 }
715
716MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000717 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000718 {
719 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000720 $$ = new t_map($4, $6);
721 if ($2 != NULL) {
722 ((t_container*)$$)->set_cpp_name(std::string($2));
723 }
Mark Sleee8540632006-05-30 09:24:40 +0000724 }
725
726SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000727 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000728 {
729 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000730 $$ = new t_set($4);
731 if ($2 != NULL) {
732 ((t_container*)$$)->set_cpp_name(std::string($2));
733 }
Mark Sleee8540632006-05-30 09:24:40 +0000734 }
735
736ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000737 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +0000738 {
739 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000740 $$ = new t_list($3);
741 if ($5 != NULL) {
742 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000743 }
744 }
745
Mark Slee36bfa2e2007-01-19 20:09:51 +0000746CppType:
Mark Sleef0712dc2006-10-25 19:03:57 +0000747 '[' tok_cpp_type tok_literal ']'
Mark Slee4f8da1d2006-10-12 02:47:27 +0000748 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000749 $$ = $3;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000750 }
751|
752 {
753 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000754 }
755
Mark Slee31985722006-05-24 21:45:31 +0000756%%