blob: c6f38a2218abaa6e9e9eb21671375dbbc68355e7 [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;
Mark Slee6a47fed2007-02-07 02:40:59 +000036 t_base_type* tbase;
Mark Slee30152872006-11-28 01:24:07 +000037 t_typedef* ttypedef;
38 t_enum* tenum;
39 t_enum_value* tenumv;
40 t_const* tconst;
41 t_const_value* tconstv;
42 t_struct* tstruct;
43 t_service* tservice;
44 t_function* tfunction;
45 t_field* tfield;
ccheeverf53b5cf2007-02-05 20:33:11 +000046 char* tdoc;
Mark Slee31985722006-05-24 21:45:31 +000047}
48
Mark Sleef5377b32006-10-10 01:42:59 +000049/**
50 * Strings identifier
51 */
Mark Slee31985722006-05-24 21:45:31 +000052%token<id> tok_identifier
Mark Sleef0712dc2006-10-25 19:03:57 +000053%token<id> tok_literal
ccheeverf53b5cf2007-02-05 20:33:11 +000054%token<tdoc> tok_doctext
Mark Sleef5377b32006-10-10 01:42:59 +000055
56/**
Mark Slee30152872006-11-28 01:24:07 +000057 * Constant values
Mark Sleef5377b32006-10-10 01:42:59 +000058 */
Mark Slee31985722006-05-24 21:45:31 +000059%token<iconst> tok_int_constant
Mark Slee30152872006-11-28 01:24:07 +000060%token<dconst> tok_dub_constant
Mark Slee31985722006-05-24 21:45:31 +000061
Mark Sleef5377b32006-10-10 01:42:59 +000062/**
Mark Sleef0712dc2006-10-25 19:03:57 +000063 * Header keywoards
Mark Sleef5377b32006-10-10 01:42:59 +000064 */
Mark Sleef0712dc2006-10-25 19:03:57 +000065%token tok_include
Mark Slee9cb7c612006-09-01 22:17:45 +000066%token tok_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000067%token tok_cpp_namespace
68%token tok_cpp_include
69%token tok_cpp_type
Mark Sleee888b372007-01-12 01:06:24 +000070%token tok_php_namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000071%token tok_java_package
Mark Slee782abbb2007-01-19 00:17:02 +000072%token tok_xsd_all
Mark Slee36bfa2e2007-01-19 20:09:51 +000073%token tok_xsd_optional
Mark Slee7df0e2a2007-02-06 21:03:18 +000074%token tok_xsd_nillable
Mark Slee0d9199e2007-01-31 02:08:30 +000075%token tok_xsd_namespace
Mark Slee21135c32007-02-05 21:52:08 +000076%token tok_xsd_attrs
Mark Slee9cb7c612006-09-01 22:17:45 +000077
Mark Sleef5377b32006-10-10 01:42:59 +000078/**
79 * Base datatype keywords
80 */
81%token tok_void
Mark Slee78f58e22006-09-02 04:17:07 +000082%token tok_bool
Mark Slee31985722006-05-24 21:45:31 +000083%token tok_byte
84%token tok_string
Mark Slee8d725a22007-04-13 01:57:12 +000085%token tok_binary
Mark Sleeb6200d82007-01-19 19:14:36 +000086%token tok_slist
Mark Slee6a47fed2007-02-07 02:40:59 +000087%token tok_senum
Mark Slee9cb7c612006-09-01 22:17:45 +000088%token tok_i16
Mark Slee31985722006-05-24 21:45:31 +000089%token tok_i32
Mark Slee31985722006-05-24 21:45:31 +000090%token tok_i64
Mark Slee9cb7c612006-09-01 22:17:45 +000091%token tok_double
Mark Slee31985722006-05-24 21:45:31 +000092
Mark Sleef5377b32006-10-10 01:42:59 +000093/**
94 * Complex type keywords
95 */
Mark Slee31985722006-05-24 21:45:31 +000096%token tok_map
97%token tok_list
98%token tok_set
99
Mark Sleef5377b32006-10-10 01:42:59 +0000100/**
101 * Function modifiers
102 */
Mark Slee31985722006-05-24 21:45:31 +0000103%token tok_async
104
Mark Sleef5377b32006-10-10 01:42:59 +0000105/**
106 * Thrift language keywords
107 */
Mark Slee31985722006-05-24 21:45:31 +0000108%token tok_typedef
109%token tok_struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000110%token tok_xception
111%token tok_throws
Mark Sleef0712dc2006-10-25 19:03:57 +0000112%token tok_extends
Mark Slee31985722006-05-24 21:45:31 +0000113%token tok_service
114%token tok_enum
Mark Slee30152872006-11-28 01:24:07 +0000115%token tok_const
Mark Slee31985722006-05-24 21:45:31 +0000116
Mark Sleef5377b32006-10-10 01:42:59 +0000117/**
118 * Grammar nodes
119 */
120
Mark Slee31985722006-05-24 21:45:31 +0000121%type<ttype> BaseType
Mark Sleee8540632006-05-30 09:24:40 +0000122%type<ttype> ContainerType
123%type<ttype> MapType
124%type<ttype> SetType
125%type<ttype> ListType
Mark Slee31985722006-05-24 21:45:31 +0000126
Mark Sleef0712dc2006-10-25 19:03:57 +0000127%type<ttype> TypeDefinition
128
Mark Slee31985722006-05-24 21:45:31 +0000129%type<ttypedef> Typedef
130%type<ttype> DefinitionType
131
132%type<tfield> Field
Mark Slee7ff32452007-02-01 05:26:18 +0000133%type<iconst> FieldIdentifier
Mark Slee31985722006-05-24 21:45:31 +0000134%type<ttype> FieldType
Mark Slee7ff32452007-02-01 05:26:18 +0000135%type<tconstv> FieldValue
Mark Sleee8540632006-05-30 09:24:40 +0000136%type<tstruct> FieldList
Mark Slee31985722006-05-24 21:45:31 +0000137
138%type<tenum> Enum
139%type<tenum> EnumDefList
Mark Slee30152872006-11-28 01:24:07 +0000140%type<tenumv> EnumDef
141
Mark Slee6a47fed2007-02-07 02:40:59 +0000142%type<ttypedef> Senum
143%type<tbase> SenumDefList
144%type<id> SenumDef
145
Mark Slee30152872006-11-28 01:24:07 +0000146%type<tconst> Const
147%type<tconstv> ConstValue
148%type<tconstv> ConstList
149%type<tconstv> ConstListContents
150%type<tconstv> ConstMap
151%type<tconstv> ConstMapContents
Mark Slee31985722006-05-24 21:45:31 +0000152
153%type<tstruct> Struct
Mark Slee9cb7c612006-09-01 22:17:45 +0000154%type<tstruct> Xception
Mark Slee31985722006-05-24 21:45:31 +0000155%type<tservice> Service
156
157%type<tfunction> Function
Mark Slee31985722006-05-24 21:45:31 +0000158%type<ttype> FunctionType
159%type<tservice> FunctionList
160
Mark Slee36bfa2e2007-01-19 20:09:51 +0000161%type<tstruct> Throws
162%type<tservice> Extends
163%type<tbool> Async
164%type<tbool> XsdAll
165%type<tbool> XsdOptional
Mark Slee7df0e2a2007-02-06 21:03:18 +0000166%type<tbool> XsdNillable
Mark Slee748d83f2007-02-07 01:20:08 +0000167%type<tstruct> XsdAttributes
Mark Slee36bfa2e2007-01-19 20:09:51 +0000168%type<id> CppType
Mark Slee52f643d2006-08-09 00:03:43 +0000169
ccheeverf53b5cf2007-02-05 20:33:11 +0000170%type<tdoc> DocTextOptional
171
Mark Slee31985722006-05-24 21:45:31 +0000172%%
173
Mark Sleef5377b32006-10-10 01:42:59 +0000174/**
175 * Thrift Grammar Implementation.
176 *
177 * For the most part this source file works its way top down from what you
178 * might expect to find in a typical .thrift file, i.e. type definitions and
179 * namespaces up top followed by service definitions using those types.
180 */
Mark Slee31985722006-05-24 21:45:31 +0000181
182Program:
Mark Sleef0712dc2006-10-25 19:03:57 +0000183 HeaderList DefinitionList
184 {
185 pdebug("Program -> Headers DefinitionList");
186 }
187
188HeaderList:
189 HeaderList Header
190 {
191 pdebug("HeaderList -> HeaderList Header");
192 }
193|
194 {
195 pdebug("HeaderList -> ");
196 }
197
198Header:
199 Include
200 {
201 pdebug("Header -> Include");
202 }
203| tok_namespace tok_identifier
204 {
205 pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead");
206 if (g_parse_mode == PROGRAM) {
207 g_program->set_cpp_namespace($2);
208 g_program->set_java_package($2);
209 }
210 }
211| tok_cpp_namespace tok_identifier
212 {
213 pdebug("Header -> tok_cpp_namespace tok_identifier");
214 if (g_parse_mode == PROGRAM) {
215 g_program->set_cpp_namespace($2);
216 }
217 }
218| tok_cpp_include tok_literal
219 {
220 pdebug("Header -> tok_cpp_include tok_literal");
221 if (g_parse_mode == PROGRAM) {
222 g_program->add_cpp_include($2);
223 }
224 }
Mark Sleee888b372007-01-12 01:06:24 +0000225| tok_php_namespace tok_identifier
226 {
227 pdebug("Header -> tok_php_namespace tok_identifier");
228 if (g_parse_mode == PROGRAM) {
229 g_program->set_php_namespace($2);
230 }
231 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000232| tok_java_package tok_identifier
233 {
234 pdebug("Header -> tok_java_package tok_identifier");
235 if (g_parse_mode == PROGRAM) {
236 g_program->set_java_package($2);
237 }
238 }
Mark Slee0d9199e2007-01-31 02:08:30 +0000239| tok_xsd_namespace tok_literal
240 {
241 pdebug("Header -> tok_xsd_namespace tok_literal");
242 if (g_parse_mode == PROGRAM) {
243 g_program->set_xsd_namespace($2);
244 }
245 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000246
247Include:
248 tok_include tok_literal
249 {
250 pdebug("Include -> tok_include tok_literal");
251 if (g_parse_mode == INCLUDES) {
252 std::string path = include_file(std::string($2));
253 if (!path.empty()) {
254 g_program->add_include(path);
255 }
256 }
257 }
Mark Slee31985722006-05-24 21:45:31 +0000258
259DefinitionList:
260 DefinitionList Definition
261 {
262 pdebug("DefinitionList -> DefinitionList Definition");
263 }
264|
265 {
266 pdebug("DefinitionList -> ");
267 }
268
269Definition:
Mark Slee30152872006-11-28 01:24:07 +0000270 Const
271 {
272 pdebug("Definition -> Const");
273 if (g_parse_mode == PROGRAM) {
274 g_program->add_const($1);
275 }
276 }
277| TypeDefinition
Mark Slee9cb7c612006-09-01 22:17:45 +0000278 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000279 pdebug("Definition -> TypeDefinition");
280 if (g_parse_mode == PROGRAM) {
281 g_scope->add_type($1->get_name(), $1);
282 if (g_parent_scope != NULL) {
283 g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
284 }
285 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000286 }
Mark Slee31985722006-05-24 21:45:31 +0000287| Service
288 {
289 pdebug("Definition -> Service");
Mark Sleef0712dc2006-10-25 19:03:57 +0000290 if (g_parse_mode == PROGRAM) {
291 g_scope->add_service($1->get_name(), $1);
292 if (g_parent_scope != NULL) {
293 g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
294 }
295 g_program->add_service($1);
296 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000297 }
298
Mark Sleef0712dc2006-10-25 19:03:57 +0000299TypeDefinition:
300 Typedef
Mark Slee9cb7c612006-09-01 22:17:45 +0000301 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000302 pdebug("TypeDefinition -> Typedef");
303 if (g_parse_mode == PROGRAM) {
304 g_program->add_typedef($1);
305 }
306 }
307| Enum
308 {
309 pdebug("TypeDefinition -> Enum");
310 if (g_parse_mode == PROGRAM) {
311 g_program->add_enum($1);
312 }
313 }
Mark Slee6a47fed2007-02-07 02:40:59 +0000314| Senum
315 {
316 pdebug("TypeDefinition -> Senum");
317 if (g_parse_mode == PROGRAM) {
318 g_program->add_typedef($1);
319 }
320 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000321| Struct
322 {
323 pdebug("TypeDefinition -> Struct");
324 if (g_parse_mode == PROGRAM) {
325 g_program->add_struct($1);
326 }
327 }
328| Xception
329 {
330 pdebug("TypeDefinition -> Xception");
331 if (g_parse_mode == PROGRAM) {
332 g_program->add_xception($1);
333 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000334 }
Mark Slee31985722006-05-24 21:45:31 +0000335
336Typedef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000337 DocTextOptional tok_typedef DefinitionType tok_identifier
Mark Slee31985722006-05-24 21:45:31 +0000338 {
339 pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000340 t_typedef *td = new t_typedef(g_program, $3, $4);
Mark Slee31985722006-05-24 21:45:31 +0000341 $$ = td;
ccheeverf53b5cf2007-02-05 20:33:11 +0000342 if ($1 != NULL) {
343 td->set_doc($1);
344 }
Mark Slee31985722006-05-24 21:45:31 +0000345 }
346
ccheeverf53b5cf2007-02-05 20:33:11 +0000347DocTextOptional:
348 tok_doctext
349 {
350 pdebug("DocTextOptional -> tok_doctext");
351 $$ = $1;
352 }
353|
354 {
355 $$ = NULL;
356 }
357
Mark Slee6a47fed2007-02-07 02:40:59 +0000358CommaOrSemicolonOptional:
359 ','
360 {}
361| ';'
362 {}
363|
364 {}
ccheeverf53b5cf2007-02-05 20:33:11 +0000365
Mark Slee31985722006-05-24 21:45:31 +0000366Enum:
ccheeverf53b5cf2007-02-05 20:33:11 +0000367 DocTextOptional tok_enum tok_identifier '{' EnumDefList '}'
Mark Slee31985722006-05-24 21:45:31 +0000368 {
369 pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000370 $$ = $5;
371 $$->set_name($3);
372 if ($1 != NULL) {
373 $$->set_doc($1);
374 }
Mark Slee31985722006-05-24 21:45:31 +0000375 }
376
377EnumDefList:
Mark Slee207cb462006-11-02 18:43:12 +0000378 EnumDefList EnumDef
Mark Slee31985722006-05-24 21:45:31 +0000379 {
380 pdebug("EnumDefList -> EnumDefList EnumDef");
381 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000382 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000383 }
384|
385 {
386 pdebug("EnumDefList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000387 $$ = new t_enum(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000388 }
389
390EnumDef:
ccheeverf53b5cf2007-02-05 20:33:11 +0000391 DocTextOptional tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000392 {
Mark Slee30152872006-11-28 01:24:07 +0000393 pdebug("EnumDef -> tok_identifier = tok_int_constant");
ccheeverf53b5cf2007-02-05 20:33:11 +0000394 if ($4 < 0) {
395 pwarning(1, "Negative value supplied for enum %s.\n", $2);
Mark Slee31985722006-05-24 21:45:31 +0000396 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000397 $$ = new t_enum_value($2, $4);
398 if ($1 != NULL) {
399 $$->set_doc($1);
400 }
Mark Slee31985722006-05-24 21:45:31 +0000401 }
402|
ccheeverf53b5cf2007-02-05 20:33:11 +0000403 DocTextOptional tok_identifier CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000404 {
Mark Slee30152872006-11-28 01:24:07 +0000405 pdebug("EnumDef -> tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000406 $$ = new t_enum_value($2);
407 if ($1 != NULL) {
408 $$->set_doc($1);
409 }
Mark Slee30152872006-11-28 01:24:07 +0000410 }
411
Mark Slee6a47fed2007-02-07 02:40:59 +0000412Senum:
413 DocTextOptional tok_senum tok_identifier '{' SenumDefList '}'
414 {
415 pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
416 $$ = new t_typedef(g_program, $5, $3);
417 if ($1 != NULL) {
418 $$->set_doc($1);
419 }
420 }
421
422SenumDefList:
423 SenumDefList SenumDef
424 {
425 pdebug("SenumDefList -> SenumDefList SenumDef");
426 $$ = $1;
427 $$->add_string_enum_val($2);
428 }
429|
430 {
431 pdebug("SenumDefList -> ");
432 $$ = new t_base_type("string", t_base_type::TYPE_STRING);
433 $$->set_string_enum(true);
434 }
435
436SenumDef:
437 tok_literal CommaOrSemicolonOptional
438 {
439 pdebug("SenumDef -> tok_literal");
440 $$ = $1;
441 }
442
Mark Slee30152872006-11-28 01:24:07 +0000443Const:
444 tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
445 {
446 pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
Mark Sleeaa7671d2006-11-29 03:19:31 +0000447 if (g_parse_mode == PROGRAM) {
448 $$ = new t_const($2, $3, $5);
449 validate_const_type($$);
450 } else {
451 $$ = NULL;
452 }
Mark Slee30152872006-11-28 01:24:07 +0000453 }
454
455ConstValue:
456 tok_int_constant
457 {
458 pdebug("ConstValue => tok_int_constant");
459 $$ = new t_const_value();
460 $$->set_integer($1);
461 }
462| tok_dub_constant
463 {
464 pdebug("ConstValue => tok_dub_constant");
465 $$ = new t_const_value();
466 $$->set_double($1);
467 }
468| tok_literal
469 {
470 pdebug("ConstValue => tok_literal");
471 $$ = new t_const_value();
472 $$->set_string($1);
473 }
Mark Slee67fc6342006-11-29 03:37:04 +0000474| tok_identifier
475 {
476 pdebug("ConstValue => tok_identifier");
477 $$ = new t_const_value();
478 $$->set_string($1);
479 }
Mark Slee30152872006-11-28 01:24:07 +0000480| ConstList
481 {
482 pdebug("ConstValue => ConstList");
483 $$ = $1;
484 }
485| ConstMap
486 {
487 pdebug("ConstValue => ConstMap");
488 $$ = $1;
489 }
490
491ConstList:
492 '[' ConstListContents ']'
493 {
494 pdebug("ConstList => [ ConstListContents ]");
495 $$ = $2;
496 }
497
498ConstListContents:
499 ConstListContents ConstValue CommaOrSemicolonOptional
500 {
501 pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
502 $$ = $1;
503 $$->add_list($2);
504 }
505|
506 {
507 pdebug("ConstListContents =>");
508 $$ = new t_const_value();
509 $$->set_list();
510 }
511
512ConstMap:
513 '{' ConstMapContents '}'
514 {
515 pdebug("ConstMap => { ConstMapContents }");
516 $$ = $2;
517 }
518
519ConstMapContents:
520 ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
521 {
522 pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
523 $$ = $1;
524 $$->add_map($2, $4);
525 }
526|
527 {
528 pdebug("ConstMapContents =>");
529 $$ = new t_const_value();
530 $$->set_map();
Mark Slee31985722006-05-24 21:45:31 +0000531 }
532
533Struct:
ccheeverf53b5cf2007-02-05 20:33:11 +0000534 DocTextOptional tok_struct tok_identifier XsdAll '{' FieldList '}'
Mark Slee31985722006-05-24 21:45:31 +0000535 {
536 pdebug("Struct -> tok_struct tok_identifier { FieldList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000537 $6->set_name($3);
538 if ($1 != NULL) {
539 $6->set_doc($1);
540 }
541 $6->set_xsd_all($4);
542 $$ = $6;
Mark Slee9cb7c612006-09-01 22:17:45 +0000543 y_field_val = -1;
544 }
545
Mark Slee36bfa2e2007-01-19 20:09:51 +0000546XsdAll:
Mark Slee782abbb2007-01-19 00:17:02 +0000547 tok_xsd_all
548 {
549 $$ = true;
550 }
551|
552 {
553 $$ = false;
554 }
555
Mark Slee36bfa2e2007-01-19 20:09:51 +0000556XsdOptional:
557 tok_xsd_optional
558 {
559 $$ = true;
560 }
561|
562 {
563 $$ = false;
564 }
565
Mark Slee7df0e2a2007-02-06 21:03:18 +0000566XsdNillable:
567 tok_xsd_nillable
568 {
569 $$ = true;
570 }
571|
572 {
573 $$ = false;
574 }
575
Mark Slee21135c32007-02-05 21:52:08 +0000576XsdAttributes:
Mark Slee748d83f2007-02-07 01:20:08 +0000577 tok_xsd_attrs '{' FieldList '}'
Mark Slee21135c32007-02-05 21:52:08 +0000578 {
Mark Slee748d83f2007-02-07 01:20:08 +0000579 $$ = $3;
Mark Slee21135c32007-02-05 21:52:08 +0000580 }
581|
582 {
583 $$ = NULL;
584 }
585
Mark Slee9cb7c612006-09-01 22:17:45 +0000586Xception:
587 tok_xception tok_identifier '{' FieldList '}'
588 {
589 pdebug("Xception -> tok_xception tok_identifier { FieldList }");
590 $4->set_name($2);
591 $4->set_xception(true);
ccheeverf53b5cf2007-02-05 20:33:11 +0000592/*
593 if ($4 != NULL) {
594 $5->set_doc($4);
595 }
596*/
Mark Slee9cb7c612006-09-01 22:17:45 +0000597 $$ = $4;
598 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000599 }
600
601Service:
ccheeverf53b5cf2007-02-05 20:33:11 +0000602 DocTextOptional tok_service tok_identifier Extends '{' FunctionList '}'
Mark Slee31985722006-05-24 21:45:31 +0000603 {
604 pdebug("Service -> tok_service tok_identifier { FunctionList }");
ccheeverf53b5cf2007-02-05 20:33:11 +0000605 $$ = $6;
606 $$->set_name($3);
607 $$->set_extends($4);
608 if ($1 != NULL) {
609 $$->set_doc($1);
610 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000611 }
612
Mark Slee36bfa2e2007-01-19 20:09:51 +0000613Extends:
Mark Sleef0712dc2006-10-25 19:03:57 +0000614 tok_extends tok_identifier
615 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000616 pdebug("Extends -> tok_extends tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000617 $$ = NULL;
618 if (g_parse_mode == PROGRAM) {
619 $$ = g_scope->get_service($2);
620 if ($$ == NULL) {
621 yyerror("Service \"%s\" has not been defined.", $2);
622 exit(1);
623 }
624 }
625 }
626|
627 {
628 $$ = NULL;
Mark Slee31985722006-05-24 21:45:31 +0000629 }
630
631FunctionList:
Mark Slee207cb462006-11-02 18:43:12 +0000632 FunctionList Function
Mark Slee31985722006-05-24 21:45:31 +0000633 {
634 pdebug("FunctionList -> FunctionList Function");
635 $$ = $1;
636 $1->add_function($2);
637 }
638|
639 {
640 pdebug("FunctionList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000641 $$ = new t_service(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000642 }
643
644Function:
ccheeverf53b5cf2007-02-05 20:33:11 +0000645 DocTextOptional Async FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000646 {
ccheeverf53b5cf2007-02-05 20:33:11 +0000647 $6->set_name(std::string($4) + "_args");
648 $$ = new t_function($3, $4, $6, $8, $2);
649 if ($1 != NULL) {
650 $$->set_doc($1);
651 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000652 y_field_val = -1;
Mark Slee31985722006-05-24 21:45:31 +0000653 }
654
Mark Slee36bfa2e2007-01-19 20:09:51 +0000655Async:
Mark Slee52f643d2006-08-09 00:03:43 +0000656 tok_async
Mark Slee31985722006-05-24 21:45:31 +0000657 {
Mark Slee52f643d2006-08-09 00:03:43 +0000658 $$ = true;
659 }
660|
661 {
662 $$ = false;
Mark Slee31985722006-05-24 21:45:31 +0000663 }
664
Mark Slee36bfa2e2007-01-19 20:09:51 +0000665Throws:
Mark Slee9cb7c612006-09-01 22:17:45 +0000666 tok_throws '(' FieldList ')'
667 {
Mark Slee36bfa2e2007-01-19 20:09:51 +0000668 pdebug("Throws -> tok_throws ( FieldList )");
Mark Slee9cb7c612006-09-01 22:17:45 +0000669 $$ = $3;
670 }
671|
672 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000673 $$ = new t_struct(g_program);
Mark Slee9cb7c612006-09-01 22:17:45 +0000674 }
675
Mark Slee31985722006-05-24 21:45:31 +0000676FieldList:
Mark Slee207cb462006-11-02 18:43:12 +0000677 FieldList Field
Mark Slee31985722006-05-24 21:45:31 +0000678 {
679 pdebug("FieldList -> FieldList , Field");
680 $$ = $1;
Mark Slee207cb462006-11-02 18:43:12 +0000681 $$->append($2);
Mark Slee31985722006-05-24 21:45:31 +0000682 }
683|
684 {
685 pdebug("FieldList -> ");
Mark Sleef0712dc2006-10-25 19:03:57 +0000686 $$ = new t_struct(g_program);
Mark Slee31985722006-05-24 21:45:31 +0000687 }
688
689Field:
Mark Slee7df0e2a2007-02-06 21:03:18 +0000690 DocTextOptional FieldIdentifier FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional
Mark Slee31985722006-05-24 21:45:31 +0000691 {
Mark Sleef0712dc2006-10-25 19:03:57 +0000692 pdebug("tok_int_constant : Field -> FieldType tok_identifier");
ccheeverf53b5cf2007-02-05 20:33:11 +0000693 if ($2 < 0) {
Mark Slee21135c32007-02-05 21:52:08 +0000694 pwarning(2, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $4);
Mark Slee31985722006-05-24 21:45:31 +0000695 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000696 $$ = new t_field($3, $4, $2);
697 if ($5 != NULL) {
698 validate_field_value($$, $5);
699 $$->set_value($5);
Mark Slee7ff32452007-02-01 05:26:18 +0000700 }
ccheeverf53b5cf2007-02-05 20:33:11 +0000701 $$->set_xsd_optional($6);
Mark Slee7df0e2a2007-02-06 21:03:18 +0000702 $$->set_xsd_nillable($7);
ccheeverf53b5cf2007-02-05 20:33:11 +0000703 if ($1 != NULL) {
704 $$->set_doc($1);
705 }
Mark Slee7df0e2a2007-02-06 21:03:18 +0000706 if ($8 != NULL) {
Mark Slee748d83f2007-02-07 01:20:08 +0000707 $$->set_xsd_attrs($8);
Mark Slee21135c32007-02-05 21:52:08 +0000708 }
Mark Slee31985722006-05-24 21:45:31 +0000709 }
Mark Slee7ff32452007-02-01 05:26:18 +0000710
711FieldIdentifier:
712 tok_int_constant ':'
Mark Slee31985722006-05-24 21:45:31 +0000713 {
Mark Slee7ff32452007-02-01 05:26:18 +0000714 if ($1 <= 0) {
715 pwarning(1, "Nonpositive value (%d) not allowed as a field key.\n", $1);
716 $1 = y_field_val--;
Mark Sleef0712dc2006-10-25 19:03:57 +0000717 }
Mark Slee7ff32452007-02-01 05:26:18 +0000718 $$ = $1;
719 }
720|
721 {
722 $$ = y_field_val--;
723 }
724
725FieldValue:
726 '=' ConstValue
727 {
728 if (g_parse_mode == PROGRAM) {
729 $$ = $2;
730 } else {
731 $$ = NULL;
732 }
733 }
734|
735 {
736 $$ = NULL;
Mark Sleef0712dc2006-10-25 19:03:57 +0000737 }
Mark Slee31985722006-05-24 21:45:31 +0000738
739DefinitionType:
740 BaseType
741 {
742 pdebug("DefinitionType -> BaseType");
743 $$ = $1;
744 }
Mark Sleee8540632006-05-30 09:24:40 +0000745| ContainerType
746 {
747 pdebug("DefinitionType -> ContainerType");
748 $$ = $1;
749 }
Mark Slee31985722006-05-24 21:45:31 +0000750
751FunctionType:
752 FieldType
753 {
Mark Sleee8540632006-05-30 09:24:40 +0000754 pdebug("FunctionType -> FieldType");
Mark Slee31985722006-05-24 21:45:31 +0000755 $$ = $1;
756 }
757| tok_void
758 {
Mark Sleee8540632006-05-30 09:24:40 +0000759 pdebug("FunctionType -> tok_void");
Mark Sleef0712dc2006-10-25 19:03:57 +0000760 $$ = g_type_void;
Mark Slee31985722006-05-24 21:45:31 +0000761 }
762
763FieldType:
764 tok_identifier
765 {
Mark Sleee8540632006-05-30 09:24:40 +0000766 pdebug("FieldType -> tok_identifier");
Mark Sleef0712dc2006-10-25 19:03:57 +0000767 if (g_parse_mode == INCLUDES) {
768 // Ignore identifiers in include mode
769 $$ = NULL;
770 } else {
771 // Lookup the identifier in the current scope
772 $$ = g_scope->get_type($1);
773 if ($$ == NULL) {
774 yyerror("Type \"%s\" has not been defined.", $1);
775 exit(1);
776 }
Mark Sleee8540632006-05-30 09:24:40 +0000777 }
Mark Slee31985722006-05-24 21:45:31 +0000778 }
779| BaseType
780 {
Mark Sleee8540632006-05-30 09:24:40 +0000781 pdebug("FieldType -> BaseType");
782 $$ = $1;
783 }
784| ContainerType
785 {
786 pdebug("FieldType -> ContainerType");
Mark Slee31985722006-05-24 21:45:31 +0000787 $$ = $1;
788 }
789
790BaseType:
791 tok_string
792 {
793 pdebug("BaseType -> tok_string");
Mark Sleef0712dc2006-10-25 19:03:57 +0000794 $$ = g_type_string;
Mark Slee31985722006-05-24 21:45:31 +0000795 }
Mark Slee8d725a22007-04-13 01:57:12 +0000796| tok_binary
797 {
798 pdebug("BaseType -> tok_binary");
799 $$ = g_type_binary;
800 }
Mark Sleeb6200d82007-01-19 19:14:36 +0000801| tok_slist
802 {
803 pdebug("BaseType -> tok_slist");
804 $$ = g_type_slist;
805 }
Mark Slee78f58e22006-09-02 04:17:07 +0000806| tok_bool
807 {
808 pdebug("BaseType -> tok_bool");
Mark Sleef0712dc2006-10-25 19:03:57 +0000809 $$ = g_type_bool;
Mark Slee78f58e22006-09-02 04:17:07 +0000810 }
Mark Slee31985722006-05-24 21:45:31 +0000811| tok_byte
812 {
813 pdebug("BaseType -> tok_byte");
Mark Sleef0712dc2006-10-25 19:03:57 +0000814 $$ = g_type_byte;
Mark Slee31985722006-05-24 21:45:31 +0000815 }
Mark Slee9cb7c612006-09-01 22:17:45 +0000816| tok_i16
817 {
818 pdebug("BaseType -> tok_i16");
Mark Sleef0712dc2006-10-25 19:03:57 +0000819 $$ = g_type_i16;
Mark Slee9cb7c612006-09-01 22:17:45 +0000820 }
Mark Slee31985722006-05-24 21:45:31 +0000821| tok_i32
822 {
823 pdebug("BaseType -> tok_i32");
Mark Sleef0712dc2006-10-25 19:03:57 +0000824 $$ = g_type_i32;
Mark Slee31985722006-05-24 21:45:31 +0000825 }
Mark Slee31985722006-05-24 21:45:31 +0000826| tok_i64
827 {
828 pdebug("BaseType -> tok_i64");
Mark Sleef0712dc2006-10-25 19:03:57 +0000829 $$ = g_type_i64;
Mark Slee31985722006-05-24 21:45:31 +0000830 }
Mark Sleec98d0502006-09-06 02:42:25 +0000831| tok_double
832 {
833 pdebug("BaseType -> tok_double");
Mark Sleef0712dc2006-10-25 19:03:57 +0000834 $$ = g_type_double;
Mark Sleec98d0502006-09-06 02:42:25 +0000835 }
Mark Slee31985722006-05-24 21:45:31 +0000836
Mark Sleee8540632006-05-30 09:24:40 +0000837ContainerType:
838 MapType
839 {
840 pdebug("ContainerType -> MapType");
841 $$ = $1;
842 }
843| SetType
844 {
845 pdebug("ContainerType -> SetType");
846 $$ = $1;
847 }
848| ListType
849 {
850 pdebug("ContainerType -> ListType");
851 $$ = $1;
852 }
853
854MapType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000855 tok_map CppType '<' FieldType ',' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000856 {
857 pdebug("MapType -> tok_map <FieldType, FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000858 $$ = new t_map($4, $6);
859 if ($2 != NULL) {
860 ((t_container*)$$)->set_cpp_name(std::string($2));
861 }
Mark Sleee8540632006-05-30 09:24:40 +0000862 }
863
864SetType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000865 tok_set CppType '<' FieldType '>'
Mark Sleee8540632006-05-30 09:24:40 +0000866 {
867 pdebug("SetType -> tok_set<FieldType>");
Mark Slee4f8da1d2006-10-12 02:47:27 +0000868 $$ = new t_set($4);
869 if ($2 != NULL) {
870 ((t_container*)$$)->set_cpp_name(std::string($2));
871 }
Mark Sleee8540632006-05-30 09:24:40 +0000872 }
873
874ListType:
Mark Slee36bfa2e2007-01-19 20:09:51 +0000875 tok_list '<' FieldType '>' CppType
Mark Sleee8540632006-05-30 09:24:40 +0000876 {
877 pdebug("ListType -> tok_list<FieldType>");
Mark Sleef0712dc2006-10-25 19:03:57 +0000878 $$ = new t_list($3);
879 if ($5 != NULL) {
880 ((t_container*)$$)->set_cpp_name(std::string($5));
Mark Slee4f8da1d2006-10-12 02:47:27 +0000881 }
882 }
883
Mark Slee36bfa2e2007-01-19 20:09:51 +0000884CppType:
Mark Sleeafc76542007-02-09 21:55:44 +0000885 tok_cpp_type tok_literal
Mark Slee4f8da1d2006-10-12 02:47:27 +0000886 {
Mark Sleeafc76542007-02-09 21:55:44 +0000887 $$ = $2;
Mark Slee4f8da1d2006-10-12 02:47:27 +0000888 }
889|
890 {
891 $$ = NULL;
Mark Sleee8540632006-05-30 09:24:40 +0000892 }
893
Mark Slee31985722006-05-24 21:45:31 +0000894%%