ridl 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,933 @@
1
+ #--------------------------------------------------------------------
2
+ # parser.ry - source for RACC generated IDL parser
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the RIDL LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ # Chamber of commerce Rotterdam nr.276339, The Netherlands
12
+ #--------------------------------------------------------------------
13
+
14
+ class Parser
15
+ options no_result_var
16
+ start specification
17
+
18
+ rule
19
+ specification : definition
20
+ | specification definition
21
+
22
+ definition : type_dcl ";"
23
+ | const_dcl ";"
24
+ | except_dcl ";"
25
+ | interface ";"
26
+ | porttype ";"
27
+ | component ";"
28
+ | connector ";"
29
+ | home ";"
30
+ | module ";"
31
+ | template_module ";"
32
+ | template_module_inst ";"
33
+ | value ";"
34
+ | event ";"
35
+ | typeid ";"
36
+ | typeprefix ";"
37
+ |
38
+
39
+ module : module_header "{" _definition_1 "}"
40
+ { @d.end_module(val[0]) }
41
+
42
+ module_header : "module" identifier
43
+ { @d.define_module(val[1]) }
44
+
45
+ _definition_1 : definition
46
+ | _definition_1 definition
47
+
48
+ template_module : template_module_header "<" template_module_parameters ">" "{" template_module_body "}"
49
+ { @d.end_template_module(val[0]) }
50
+
51
+ template_module_header : "module" scoped_name_0
52
+ { @d.register_template_module_name(val[1]) }
53
+
54
+ template_module_parameters : template_module_parameter
55
+ | template_module_parameters "," template_module_parameter
56
+
57
+ template_module_parameter : "typename" identifier
58
+ { @d.define_template_parameter(val[1], IDL::Type::Any.new) }
59
+ | "interface" identifier
60
+ { @d.define_template_parameter(val[1], IDL::Type::Interface.new(nil)) }
61
+ | "valuetype" identifier
62
+ { @d.define_template_parameter(val[1], IDL::Type::Valuetype.new(nil)) }
63
+ | "eventtype" identifier
64
+ { @d.define_template_parameter(val[1], IDL::Type::Eventtype.new(nil)) }
65
+ | "struct" identifier
66
+ { @d.define_template_parameter(val[1], IDL::Type::Struct.new(nil)) }
67
+ | "union" identifier
68
+ { @d.define_template_parameter(val[1], IDL::Type::Union.new(nil)) }
69
+ | "exception" identifier
70
+ { @d.define_template_parameter(val[1], IDL::Type::Exception.new(nil)) }
71
+ | "enum" identifier
72
+ { @d.define_template_parameter(val[1], IDL::Type::Enum.new(nil)) }
73
+ | "sequence" identifier
74
+ { @d.define_template_parameter(val[1], IDL::Type::Sequence.new(IDL::Type::Void.new, nil)) }
75
+ | "const" const_type identifier
76
+ { @d.define_template_parameter(val[2], IDL::Type::Const.new(val[1])) }
77
+ | sequence_type identifier
78
+ { @d.define_template_parameter(val[1], val[0]) }
79
+
80
+ template_module_body : template_module_definition
81
+ | template_module_body template_module_definition
82
+
83
+ template_module_definition : type_dcl ";"
84
+ | const_dcl ";"
85
+ | except_dcl ";"
86
+ | interface ";"
87
+ | porttype ";"
88
+ | component ";"
89
+ | connector ";"
90
+ | home ";"
91
+ | fixed_module ";"
92
+ | template_module_reference ";"
93
+ | value ";"
94
+ | event ";"
95
+ | typeid ";"
96
+ | typeprefix ";"
97
+
98
+ fixed_module : module_header "{" fixed_module_body "}"
99
+ { @d.end_module(val[0]) }
100
+
101
+ fixed_module_body : fixed_module_definition
102
+ | fixed_module_body fixed_module_definition
103
+
104
+ fixed_module_definition : type_dcl ";"
105
+ | const_dcl ";"
106
+ | except_dcl ";"
107
+ | interface ";"
108
+ | porttype ";"
109
+ | component ";"
110
+ | connector ";"
111
+ | home ";"
112
+ | fixed_module ";"
113
+ | value ";"
114
+ | event ";"
115
+ | typeid ";"
116
+ | typeprefix ";"
117
+
118
+ template_module_inst : template_module_header "<" template_module_inst_parameters ">" identifier
119
+ { @d.instantiate_template_module(val[4], val[2]) }
120
+
121
+ template_module_inst_parameters : template_module_inst_parameter
122
+ { [val[0]] }
123
+ | template_module_inst_parameters "," template_module_inst_parameter
124
+ { val[0] << val[2]; val[0] }
125
+
126
+ template_module_inst_parameter : base_type_spec
127
+ { val[0] }
128
+ | template_type_spec
129
+ { val[0] }
130
+ | const_exp
131
+ { val[0] }
132
+
133
+ template_module_reference : "alias" scoped_name "<" _scoped_name_list ">" identifier
134
+ { @d.declare_template_reference(val[5], val[1], val[3]) }
135
+
136
+ interface : interface_dcl
137
+ | forward_dcl
138
+
139
+
140
+ forward_dcl : local_interface_ identifier
141
+ { @d.declare_interface(val[1], val[0]) }
142
+ | abstract_interface_ identifier
143
+ { @d.declare_interface(val[1], val[0]) }
144
+ | regular_interface_ identifier
145
+ { @d.declare_interface(val[1], val[0]) }
146
+
147
+ interface_dcl : interface_header "{" interface_body "}"
148
+ { @d.end_interface(val[0]) }
149
+ | pseudo_interface_header "{" "}"
150
+ { @d.end_interface(val[0]) }
151
+
152
+ interface_header : local_interface_ identifier interface_inheritance_spec
153
+ { @d.define_interface(val[1], val[0], val[2]) }
154
+ | local_interface_ identifier
155
+ { @d.define_interface(val[1], val[0]) }
156
+ | abstract_interface_ identifier interface_inheritance_spec
157
+ { @d.define_interface(val[1], val[0], val[2]) }
158
+ | abstract_interface_ identifier
159
+ { @d.define_interface(val[1], val[0]) }
160
+ | regular_interface_ identifier interface_inheritance_spec
161
+ { @d.define_interface(val[1], val[0], val[2]) }
162
+ | regular_interface_ identifier
163
+ { @d.define_interface(val[1], val[0]) }
164
+
165
+ local_interface_ : "local" "interface" { :local }
166
+
167
+ abstract_interface_ : "abstract" "interface" { :abstract }
168
+
169
+ pseudo_interface_header : pseudo_interface_ identifier
170
+ { @d.define_interface(val[1], val[0]) }
171
+
172
+ pseudo_interface_ : "pseudo" "interface" { :pseudo }
173
+
174
+ regular_interface_ : "interface" { :none }
175
+
176
+ interface_body : export
177
+ | interface_body export
178
+
179
+ export : type_dcl ";"
180
+ | const_dcl ";"
181
+ | except_dcl ";"
182
+ | attr_dcl ";"
183
+ | op_dcl ";"
184
+ | typeid ";"
185
+ | typeprefix ";"
186
+ |
187
+
188
+ interface_inheritance_spec: ":" _interface_name_list { val[1] }
189
+ _interface_name_list : interface_name { [val[0]] }
190
+ | _interface_name_list "," interface_name
191
+ { val[0] << val[2]; val[0] }
192
+
193
+ interface_name : scoped_name
194
+
195
+ home : home_header "{" home_body "}"
196
+ { @d.end_home(val[0]) }
197
+
198
+ home_header : "home" identifier ":" home_inheritance_spec "supports" home_supports_spec "manages" scoped_name "primarykey" home_primarykey_spec
199
+ { @d.define_home(val[1], val[3], val[7], val[9], val[5]) }
200
+ | "home" identifier ":" home_inheritance_spec "supports" home_supports_spec "manages" scoped_name
201
+ { @d.define_home(val[1], val[3], val[7], nil, val[5]) }
202
+ | "home" identifier ":" home_inheritance_spec "manages" scoped_name "primarykey" home_primarykey_spec
203
+ { @d.define_home(val[1], val[3], val[5], val[7], nil) }
204
+ | "home" identifier "supports" home_supports_spec "manages" scoped_name "primarykey" home_primarykey_spec
205
+ { @d.define_home(val[1], nil, val[5], val[7], val[3]) }
206
+ | "home" identifier "supports" home_supports_spec "manages" scoped_name
207
+ { @d.define_home(val[1], nil, val[5], nil, val[3]) }
208
+ | "home" identifier ":" home_inheritance_spec "manages" scoped_name
209
+ { @d.define_home(val[1], val[3], val[5], nil, nil) }
210
+ | "home" identifier "manages" scoped_name "primarykey" home_primarykey_spec
211
+ { @d.define_home(val[1], nil, val[3], val[5], nil) }
212
+ | "home" identifier "manages" scoped_name
213
+ { @d.define_home(val[1], nil, val[3], nil, nil) }
214
+
215
+ home_inheritance_spec : scoped_name
216
+
217
+ home_supports_spec : _interface_name_list
218
+
219
+ home_primarykey_spec : scoped_name
220
+
221
+ home_body : home_export
222
+ | home_body home_export
223
+
224
+ home_export : export
225
+ | init_dcl ";"
226
+ | finder_dcl ";"
227
+
228
+ porttype : porttype_header "{" porttype_body "}"
229
+ { @d.end_porttype(val[0]) }
230
+
231
+ porttype_header : "porttype" identifier
232
+ { @d.define_porttype(val[1]) }
233
+
234
+ porttype_body : porttype_export
235
+ | porttype_body porttype_export
236
+
237
+ porttype_export : provides_dcl ";"
238
+ | uses_dcl ";"
239
+ | attr_dcl ";"
240
+
241
+ component : component_dcl
242
+ | component_forward_dcl
243
+
244
+ component_forward_dcl : "component" identifier
245
+ { @d.declare_component(val[1]) }
246
+
247
+ component_dcl : component_header "{" component_body "}"
248
+ { @d.end_component(val[0]) }
249
+
250
+ component_header : "component" identifier ":" component_inheritance_spec "supports" component_supports_spec
251
+ { @d.define_component(val[1], val[3], val[5]) }
252
+ | "component" identifier ":" component_inheritance_spec
253
+ { @d.define_component(val[1], val[3], nil) }
254
+ | "component" identifier "supports" component_supports_spec
255
+ { @d.define_component(val[1], nil, val[3]) }
256
+ | "component" identifier
257
+ { @d.define_component(val[1], nil, nil) }
258
+
259
+ component_inheritance_spec : scoped_name
260
+
261
+ component_supports_spec : _interface_name_list
262
+
263
+ component_body : component_export
264
+ | component_body component_export
265
+
266
+ component_export : provides_dcl ";"
267
+ | uses_dcl ";"
268
+ | emits_dcl ";"
269
+ | publishes_dcl ";"
270
+ | consumes_dcl ";"
271
+ | port_dcl ";"
272
+ | attr_dcl ";"
273
+ |
274
+
275
+ connector : connector_header "{" connector_body "}"
276
+ { @d.end_connector(val[0]) }
277
+
278
+ connector_header : "connector" identifier ":" scoped_name
279
+ { @d.define_connector(val[1], val[3]) }
280
+ | "connector" identifier
281
+ { @d.define_connector(val[1], nil) }
282
+
283
+ connector_body : connector_export
284
+ | connector_body connector_export
285
+
286
+ connector_export : provides_dcl ";"
287
+ | uses_dcl ";"
288
+ | port_dcl ";"
289
+ | attr_dcl ";"
290
+ |
291
+
292
+ provides_dcl : "provides" interface_type identifier
293
+ { @d.declare_port(val[2], :facet, val[1]) }
294
+
295
+ uses_dcl : "uses" "multiple" interface_type identifier
296
+ { @d.declare_port(val[3], :receptacle, val[2], true) }
297
+ | "uses" interface_type identifier
298
+ { @d.declare_port(val[2], :receptacle, val[1], false) }
299
+
300
+ publishes_dcl : "publishes" scoped_name identifier
301
+ { @d.declare_port(val[2], :publisher, val[1]) }
302
+
303
+ emits_dcl : "emits" scoped_name identifier
304
+ { @d.declare_port(val[2], :emitter, val[1]) }
305
+
306
+ consumes_dcl : "consumes" scoped_name identifier
307
+ { @d.declare_port(val[2], :consumer, val[1]) }
308
+
309
+ port_dcl : "port" scoped_name identifier
310
+ { @d.declare_port(val[2], :port, val[1]) }
311
+ | "mirrorport" scoped_name identifier
312
+ { @d.declare_port(val[2], :mirrorport, val[1]) }
313
+
314
+ interface_type : scoped_name
315
+ | object_type
316
+
317
+ scoped_name : scoped_name_0 { @d.parse_scopedname(*val[0]) }
318
+
319
+ scoped_name_0 : identifier { [FALSE, [val[0]]] }
320
+ | "::" identifier { [TRUE, [val[1]]] }
321
+ | scoped_name_0 "::" identifier
322
+ { val[0][1] << val[2]; val[0] }
323
+
324
+ event : event_dcl
325
+ | event_forward_dcl
326
+
327
+ event_forward_dcl : "abstract" "eventtype" identifier
328
+ { @d.declare_eventtype(val[2], :abstract) }
329
+ | "eventtype" identifier
330
+ { @d.declare_eventtype(val[1], :none) }
331
+
332
+ event_dcl : eventtype_header "{" value_body "}"
333
+ { @d.end_eventtype(val[0]) }
334
+
335
+ eventtype_header : "abstract" "eventtype" identifier value_inheritance_spec
336
+ { @d.define_eventtype(val[2], :abstract, val[3]) }
337
+ | "abstract" "eventtype" identifier
338
+ { @d.define_eventtype(val[2], :abstract) }
339
+ | "custom" "eventtype" identifier value_inheritance_spec
340
+ { @d.define_eventtype(val[2], :custom, val[3]) }
341
+ | "custom" "eventtype" identifier
342
+ { @d.define_eventtype(val[2], :custom) }
343
+ | "eventtype" identifier value_inheritance_spec
344
+ { @d.define_eventtype(val[1], :none, val[2]) }
345
+ | "eventtype" identifier
346
+ { @d.define_eventtype(val[1], :none) }
347
+
348
+ value : value_dcl
349
+ | value_box_dcl
350
+ | value_forward_dcl
351
+
352
+ value_forward_dcl : "abstract" "valuetype" identifier
353
+ { @d.declare_valuetype(val[2], :abstract) }
354
+ | "valuetype" identifier
355
+ { @d.declare_valuetype(val[1], :none) }
356
+
357
+ value_box_dcl : "valuetype" identifier type_spec
358
+ { @d.define_valuebox(val[1], val[2]) }
359
+
360
+ value_dcl : valuetype_header "{" value_body "}"
361
+ { @d.end_valuetype(val[0]) }
362
+
363
+ valuetype_header : "abstract" "valuetype" identifier value_inheritance_spec
364
+ { @d.define_valuetype(val[2], :abstract, val[3]) }
365
+ | "abstract" "valuetype" identifier
366
+ { @d.define_valuetype(val[2], :abstract) }
367
+ | "custom" "valuetype" identifier value_inheritance_spec
368
+ { @d.define_valuetype(val[2], :custom, val[3]) }
369
+ | "custom" "valuetype" identifier
370
+ { @d.define_valuetype(val[2], :custom) }
371
+ | "valuetype" identifier value_inheritance_spec
372
+ { @d.define_valuetype(val[1], :none, val[2]) }
373
+ | "valuetype" identifier
374
+ { @d.define_valuetype(val[1], :none) }
375
+
376
+ value_body : value_element
377
+ | value_body value_element
378
+
379
+ value_inheritance_spec : value_basevalue_list value_interface_support_list
380
+ { Hash[ :base => val[0], :supports => val[1] ] }
381
+ | value_basevalue_list
382
+ { Hash[ :base => val[0] ] }
383
+ | value_interface_support_list
384
+ { Hash[ :supports => val[0] ] }
385
+
386
+ value_basevalue_list : ":" "truncatable" _value_name_list
387
+ { Hash[ :truncatable => true, :list => val[2] ] }
388
+ | ":" _value_name_list
389
+ { Hash[ :truncatable => false, :list => val[1] ] }
390
+
391
+ value_interface_support_list : "supports" _interface_name_list
392
+ { val[1] }
393
+
394
+ _value_name_list : value_name { val }
395
+ | _value_name_list "," value_name { val[0] << val[2]; val[0] }
396
+
397
+ value_name : scoped_name
398
+
399
+ value_element : export
400
+ | state_member ";"
401
+ | init_dcl ";"
402
+
403
+ state_member : "public" type_spec declarators
404
+ {
405
+ dcls = parse_type_declarator(val[1], val[2])
406
+ dcls.each { |d| @d.declare_state_member(d[0], d[1], true) }
407
+ }
408
+ | "private" type_spec declarators
409
+ {
410
+ dcls = parse_type_declarator(val[1], val[2])
411
+ dcls.each { |d| @d.declare_state_member(d[0], d[1], false) }
412
+ }
413
+
414
+ init_dcl : "factory" identifier "(" ")"
415
+ { @d.declare_initializer(val[1], [], []) }
416
+ | "factory" identifier "(" init_param_decls ")"
417
+ { @d.declare_initializer(val[1], val[3], []) }
418
+ | "factory" identifier "(" ")" raises_expr
419
+ { @d.declare_initializer(val[1], [], val[4]) }
420
+ | "factory" identifier "(" init_param_decls ")" raises_expr
421
+ { @d.declare_initializer(val[1], val[3], val[5]) }
422
+
423
+ finder_dcl : "finder" identifier "(" ")"
424
+ { @d.declare_finder(val[1], [], []) }
425
+ | "finder" identifier "(" init_param_decls ")"
426
+ { @d.declare_finder(val[1], val[3], []) }
427
+ | "finder" identifier "(" ")" raises_expr
428
+ { @d.declare_finder(val[1], [], val[4]) }
429
+ | "finder" identifier "(" init_param_decls ")" raises_expr
430
+ { @d.declare_finder(val[1], val[3], val[5]) }
431
+
432
+ init_param_decls : init_param_decl { val }
433
+ | init_param_decls "," init_param_decl { val[0] << val[2]; val[0] }
434
+
435
+ init_param_decl : init_param_attribute param_type_spec simple_declarator
436
+ { [val[1], val[2]] }
437
+
438
+ init_param_attribute : "in"
439
+
440
+ typeprefix : "typeprefix" scoped_name string_literal
441
+ { @d.define_typeprefix(val[1], val[2]) }
442
+
443
+ typeid : "typeid" scoped_name string_literal
444
+ { @d.define_typeid(val[1], val[2]) }
445
+
446
+ const_dcl : "const" const_type identifier "=" const_exp
447
+ { @d.define_const(val[1], val[2], val[4]) }
448
+
449
+ const_type : integer_type
450
+ | char_type
451
+ | wide_char_type
452
+ | boolean_type
453
+ | floating_pt_type
454
+ | string_type
455
+ | wide_string_type
456
+ | fixed_pt_const_type
457
+ | scoped_name
458
+ | octet_type
459
+
460
+ const_exp : or_expr
461
+
462
+ or_expr : xor_expr
463
+ | or_expr "|" xor_expr
464
+ { Expression::Operation::Or.new(val[0], val[2]) }
465
+
466
+ xor_expr : and_expr
467
+ | xor_expr "^" and_expr
468
+ { Expression::Operation::Xor.new(val[0], val[2]) }
469
+
470
+ and_expr : shift_expr
471
+ | and_expr "&" shift_expr
472
+ { Expression::Operation::And.new(val[0], val[2]) }
473
+
474
+ shift_expr : add_expr
475
+ | shift_expr ">>" add_expr
476
+ { Expression::Operation::RShift.new(val[0], val[2]) }
477
+ | shift_expr "<<" add_expr
478
+ { Expression::Operation::LShift.new(val[0], val[2]) }
479
+
480
+ add_expr : mult_expr
481
+ | add_expr "+" mult_expr
482
+ { Expression::Operation::Add.new(val[0], val[2]) }
483
+ | add_expr "-" mult_expr
484
+ { Expression::Operation::Minus.new(val[0], val[2]) }
485
+
486
+ mult_expr : unary_expr
487
+ | mult_expr "*" unary_expr
488
+ { Expression::Operation::Mult.new(val[0], val[2]) }
489
+ | mult_expr "/" unary_expr
490
+ { Expression::Operation::Div.new(val[0], val[2]) }
491
+ | mult_expr "%" unary_expr
492
+ { Expression::Operation::Mod.new(val[0], val[2]) }
493
+
494
+ unary_expr : unary_operator primary_expr { val[0].new(val[1]) }
495
+ | primary_expr
496
+
497
+ unary_operator : "-" { Expression::Operation::UnaryMinus }
498
+ | "+" { Expression::Operation::UnaryPlus }
499
+ | "~" { Expression::Operation::UnaryNot }
500
+
501
+
502
+ primary_expr : scoped_name
503
+ | literal
504
+ | "(" const_exp ")" { val[1] }
505
+
506
+ literal : integer_literal { @d.parse_literal(:integer, val[0]) }
507
+ | string_literal { @d.parse_literal(:string, val[0]) }
508
+ | wide_string_literal { @d.parse_literal(:wstring, val[0]) }
509
+ | character_literal { @d.parse_literal(:char, val[0]) }
510
+ | wide_character_literal { @d.parse_literal(:wchar, val[0]) }
511
+ | fixed_pt_literal { @d.parse_literal(:fixed, val[0]) }
512
+ | floating_pt_literal { @d.parse_literal(:float, val[0]) }
513
+ | boolean_literal { @d.parse_literal(:boolean, val[0]) }
514
+
515
+ boolean_literal : "TRUE" { TRUE }
516
+ | "FALSE" { FALSE }
517
+
518
+ positive_int_const : const_exp { @d.parse_positive_int(val[0]) }
519
+
520
+ type_dcl : "typedef" type_declarator
521
+ | struct_type
522
+ | struct_forward_dcl
523
+ | union_type
524
+ | union_forward_dcl
525
+ | enum_type
526
+ | "native" native_declarator
527
+
528
+ type_declarator : type_spec declarators
529
+ {
530
+ dcls = parse_type_declarator(val[0], val[1])
531
+ dcls.each do |d|
532
+ @d.declare_typedef(d[0], d[1])
533
+ end
534
+ }
535
+
536
+ type_spec : simple_type_spec
537
+ | constr_type_spec
538
+
539
+ simple_type_spec : base_type_spec
540
+ | template_type_spec
541
+ | scoped_name
542
+
543
+ base_type_spec : floating_pt_type
544
+ | integer_type
545
+ | char_type
546
+ | wide_char_type
547
+ | boolean_type
548
+ | octet_type
549
+ | any_type
550
+ | object_type
551
+ | value_base_type
552
+
553
+ template_type_spec : sequence_type
554
+ | string_type
555
+ | wide_string_type
556
+ | fixed_pt_type
557
+
558
+ constr_type_spec : struct_type
559
+ | union_type
560
+ | enum_type
561
+
562
+ declarators : declarator { [val[0]] }
563
+ | declarators "," declarator { val[0] << val[2] }
564
+
565
+ declarator : simple_declarator
566
+ | complex_declarator
567
+
568
+ native_declarator : identifier { @d.declare_typedef(::IDL::Type::Native.new, val[0]) }
569
+
570
+ simple_declarator : identifier
571
+
572
+ complex_declarator : array_declarator
573
+
574
+ floating_pt_type : "float" { ::IDL::Type::Float.new }
575
+ | "double" { ::IDL::Type::Double.new }
576
+ | "long" "double" { ::IDL::Type::LongDouble.new }
577
+
578
+ integer_type : signed_int
579
+ | unsigned_int
580
+
581
+ signed_int : signed_short_int
582
+ | signed_long_int
583
+ | signed_longlong_int
584
+
585
+ signed_short_int : "short" { ::IDL::Type::Short.new }
586
+
587
+ signed_long_int : "long" { ::IDL::Type::Long.new }
588
+
589
+ signed_longlong_int : "long" "long" { ::IDL::Type::LongLong.new }
590
+
591
+ unsigned_int : unsigned_short_int
592
+ | unsigned_long_int
593
+ | unsigned_longlong_int
594
+
595
+ unsigned_short_int : "unsigned" "short" { ::IDL::Type::UShort.new }
596
+
597
+ unsigned_long_int : "unsigned" "long" { ::IDL::Type::ULong.new }
598
+
599
+ unsigned_longlong_int : "unsigned" "long" "long"
600
+ { ::IDL::Type::ULongLong.new }
601
+
602
+ char_type : "char" { ::IDL::Type::Char.new }
603
+
604
+ wide_char_type : "wchar" { ::IDL::Type::WChar.new }
605
+
606
+ boolean_type : "boolean" { ::IDL::Type::Boolean.new }
607
+
608
+ octet_type : "octet" { ::IDL::Type::Octet.new }
609
+
610
+ any_type : "any" { ::IDL::Type::Any.new }
611
+
612
+ object_type : "Object" { ::IDL::Type::Object.new }
613
+
614
+ struct_forward_dcl : struct_def identifier { @d.declare_struct(val[1]) }
615
+
616
+ struct_type : struct_header "{" member_list "}"
617
+ { @d.end_struct(val[0]) }
618
+
619
+ struct_header : struct_def identifier { @d.define_struct(val[1]) }
620
+
621
+ struct_def : "struct" { nil }
622
+
623
+
624
+ member_list : member
625
+ | member_list member
626
+
627
+ member : type_spec declarators ";"
628
+ {
629
+ dcls = parse_type_declarator(val[0], val[1])
630
+ dcls.each do |d|
631
+ @d.declare_member(d[0], d[1])
632
+ end
633
+ }
634
+
635
+ union_forward_dcl : union_def identifier
636
+ { @d.declare_union(val[1]) }
637
+
638
+ union_type : union_header "{" union_body "}"
639
+ { @d.end_union(val[0]) }
640
+
641
+ union_header : union_dcl union_switch_spec
642
+ { @d.define_union_switchtype(val[0], val[1]) }
643
+
644
+ union_dcl : union_def identifier
645
+ { @d.define_union(val[1]) }
646
+
647
+ union_def : "union" { nil }
648
+
649
+ union_switch_spec : "switch" "(" switch_type_spec ")"
650
+ { val[2] }
651
+
652
+ switch_type_spec : integer_type
653
+ | char_type
654
+ | boolean_type
655
+ | enum_type
656
+ | scoped_name
657
+
658
+ union_body : union_case
659
+ | union_body union_case
660
+
661
+ union_case : _case_label_1 element_spec ";"
662
+ {
663
+ dcls = parse_type_declarator(val[1][0], [val[1][1]])
664
+ dcls.each do |d|
665
+ @d.define_case(val[0], d[0], d[1])
666
+ end
667
+ }
668
+
669
+ _case_label_1 : case_label { [val[0]] }
670
+ | _case_label_1 case_label { val[0] << val[1] }
671
+
672
+ case_label : "case" const_exp ":" { val[1] }
673
+ | "default" ":" { :default }
674
+
675
+ element_spec : type_spec declarator
676
+ { val }
677
+
678
+ enum_type : _enum_header _enum_body
679
+ { @d.end_enum(val[0]) }
680
+
681
+ _enum_header : "enum" identifier { @d.define_enum(val[1]) }
682
+ _enum_body : "{" _enumerator_list "}"
683
+
684
+ _enumerator_list : enumerator
685
+ | _enumerator_list "," enumerator
686
+
687
+ enumerator : identifier
688
+ {
689
+ @d.declare_enumerator(val[0])
690
+ }
691
+
692
+ sequence_type : "sequence" "<" simple_type_spec "," positive_int_const ">"
693
+ { ::IDL::Type::Sequence.new(val[2], val[4]) }
694
+ | "sequence" "<" simple_type_spec ">"
695
+ { ::IDL::Type::Sequence.new(val[2], nil) }
696
+
697
+ string_type : "string" "<" positive_int_const ">"
698
+ { ::IDL::Type::String.new(val[2]) }
699
+ | "string"
700
+ { ::IDL::Type::String.new() }
701
+
702
+ wide_string_type : "wstring" "<" positive_int_const ">"
703
+ { ::IDL::Type::WString.new(val[2]) }
704
+ | "wstring"
705
+ { ::IDL::Type::WString.new() }
706
+
707
+ array_declarator : identifier _fixed_array_size_1 { val }
708
+
709
+ _fixed_array_size_1 : fixed_array_size { [val[0]] }
710
+ | _fixed_array_size_1 fixed_array_size {val[0] << val[1]}
711
+
712
+ fixed_array_size : "[" positive_int_const "]" { val[1] }
713
+
714
+ attr_dcl : "readonly" "attribute" param_type_spec readonly_attr_declarator
715
+ { dcls = parse_type_declarator(val[2], val[3][0])
716
+ dcls.each do |d|
717
+ @d.declare_attribute(d[0], d[1], true).get_raises = val[3][1]
718
+ end
719
+ }
720
+ | "attribute" param_type_spec simple_declarator attr_raises_expr
721
+ { att = @d.declare_attribute(val[1], val[2])
722
+ att.get_raises = val[3][0] unless val[3][0].empty?
723
+ att.set_raises = val[3][1] unless val[3][1].empty?
724
+ }
725
+ | "attribute" param_type_spec attr_declarator_list
726
+ { dcls = parse_type_declarator(val[1], val[2])
727
+ dcls.each do |d|
728
+ att = @d.declare_attribute(d[0], d[1])
729
+ end
730
+ }
731
+
732
+ attr_raises_expr : attr_both_raises_expr1
733
+ | attr_both_raises_expr2
734
+ | attr_get_raises_expr
735
+ | attr_set_raises_expr
736
+ | attr_no_raises_expr
737
+
738
+ attr_both_raises_expr1 : get_raises_expr set_raises_expr { [val[0], val[1]] }
739
+
740
+ attr_both_raises_expr2 : set_raises_expr get_raises_expr { [val[1], val[0]] }
741
+
742
+ attr_get_raises_expr : get_raises_expr { [val[0], []] }
743
+
744
+ attr_set_raises_expr : set_raises_expr { [[], val[0]] }
745
+
746
+ attr_no_raises_expr : { [[], []] }
747
+
748
+ attr_declarator_list : simple_declarator "," _simple_declarator_list
749
+ { [val[0]].concat(val[2]) }
750
+
751
+ readonly_attr_declarator : simple_declarator raises_expr
752
+ { [[val[0]], val[1]] }
753
+ | _simple_declarator_list { [val[0], []] }
754
+
755
+ _simple_declarator_list : simple_declarator { [val[0]] }
756
+ | _simple_declarator_list "," simple_declarator { val[0] << val[2] }
757
+
758
+ except_dcl : _except_header _except_body
759
+ { @d.end_exception(val[0]) }
760
+
761
+ _except_header : "exception" identifier { @d.define_exception(val[1]) }
762
+ _except_body : "{" _member_list0 "}"
763
+
764
+ _member_list0 :
765
+ | _member_list0 member
766
+
767
+ op_dcl : _op_dcl_header _op_dcl_parameter _op_dcl_footer
768
+
769
+ _op_dcl_header : op_attribute op_type_spec identifier
770
+ { @d.declare_op_header(val[0], val[1], val[2]) }
771
+ | op_type_spec identifier
772
+ { @d.declare_op_header(nil, val[0], val[1]) }
773
+
774
+ _op_dcl_parameter : parameter_dcls
775
+
776
+ _op_dcl_footer : raises_expr context_expr
777
+ { @d.declare_op_footer(val[0], val[1]) }
778
+ | raises_expr
779
+ { @d.declare_op_footer(val[0], nil) }
780
+ | context_expr
781
+ { @d.declare_op_footer(nil, val[0]) }
782
+ |
783
+ { @d.declare_op_footer(nil,nil) }
784
+
785
+ op_attribute : "oneway" { :oneway }
786
+
787
+ op_type_spec : param_type_spec { val[0] }
788
+ | "void" { ::IDL::Type::Void.new }
789
+
790
+ parameter_dcls : "(" ")"
791
+ | "(" _param_dcl_list ")"
792
+
793
+ _param_dcl_list: param_dcl
794
+ | _param_dcl_list "," param_dcl
795
+
796
+ param_dcl : param_attribute param_type_spec simple_declarator
797
+ { @d.declare_op_parameter(val[0], val[1], val[2]) }
798
+
799
+ param_attribute : "in" { :in }
800
+ | "out" { :out }
801
+ | "inout" { :inout }
802
+
803
+ raises_expr : "raises" "(" _scoped_name_list ")" { val[2] }
804
+
805
+ get_raises_expr : "getraises" "(" _scoped_name_list ")" { val[2] }
806
+
807
+ set_raises_expr : "setraises" "(" _scoped_name_list ")" { val[2] }
808
+
809
+ _scoped_name_list: scoped_name { val }
810
+ | _scoped_name_list "," scoped_name { val[0] << val[2] }
811
+
812
+ context_expr : "context" "(" _string_literal_list ")" { val[2] }
813
+
814
+ _string_literal_list: string_literal { val }
815
+ | _string_literal_list "," string_literal { val[0] << val[2] }
816
+
817
+ param_type_spec : base_type_spec { val[0] }
818
+ | string_type { val[0] }
819
+ | wide_string_type { val[0] }
820
+ | scoped_name { val[0] }
821
+
822
+ fixed_pt_type : "fixed" "<" positive_int_const ","
823
+ positive_int_const ">"
824
+ { IDL::Type::Fixed.new(val[2], val[4]) }
825
+
826
+ fixed_pt_const_type : "fixed" { ::IDL::Type::Fixed.new }
827
+
828
+ value_base_type : "ValueBase" { ::IDL::Type::ValueBase.new }
829
+
830
+ end
831
+
832
+ ---- inner
833
+
834
+ def parse_type_declarator(type_spec, declarators)
835
+ ret = Array.new
836
+ t = type_spec
837
+ declarators.each do |d|
838
+ case d
839
+ when ::String
840
+ ret << [t, d]
841
+ when ::Array # array_declarator -> [identifier, size]
842
+ ret << [IDL::Type::Array.new(t, d[1]), d[0]]
843
+ else
844
+ raise RuntimeError, "unknown declarator: #{d.inspect}"
845
+ end
846
+ end
847
+ ret
848
+ end
849
+
850
+ #attr_accessor :default_namespace, :output
851
+ attr_accessor :yydebug
852
+ def initialize(params = {})
853
+ @d = ::IDL::Delegator.new(params)
854
+ @params = params
855
+ end
856
+
857
+ alias on_error0 on_error
858
+ def on_error(err_tok, err_val, _value)
859
+ begin
860
+ on_error0(err_tok, err_val, _value)
861
+ rescue IDL::ParseError
862
+ raise
863
+ rescue
864
+ raise IDL::ParseError.new($!.message, @scanner.positions)
865
+ end
866
+ end
867
+
868
+ def parse(src)
869
+ @scanner = Scanner.new(src, self, @params)
870
+ @d.pre_parse
871
+ begin
872
+ do_parse
873
+ rescue IDL::ParseError
874
+ raise
875
+ rescue
876
+ STDERR.puts "#{$!}\n#{$!.backtrace.join("\n")}" if $VERBOSE
877
+ raise IDL::ParseError.new($!.message, @scanner.positions)
878
+ end
879
+ @d.post_parse
880
+ end
881
+
882
+ def visit_nodes(walker)
883
+ @d.visit_nodes(walker)
884
+ end
885
+
886
+ def pragma_prefix(s)
887
+ @d.pragma_prefix(s)
888
+ end
889
+
890
+ def pragma_version(id, major, minor)
891
+ @d.pragma_version(id, major, minor)
892
+ end
893
+
894
+ def pragma_id(id, repo_id)
895
+ @d.pragma_id(id, repo_id)
896
+ end
897
+
898
+ def handle_pragma(s)
899
+ @d.handle_pragma(s)
900
+ end
901
+
902
+ def is_included?(s)
903
+ @d.is_included?(s)
904
+ end
905
+
906
+ def enter_include(s)
907
+ @d.enter_include(s)
908
+ end
909
+
910
+ def leave_include()
911
+ @d.leave_include
912
+ end
913
+
914
+ def declare_include(s)
915
+ @d.declare_include(s)
916
+ end
917
+
918
+ def define_annotation(annid, annbody)
919
+ @d.define_annotation(annid, annbody)
920
+ end
921
+
922
+ def next_token
923
+ ret = @scanner.next_token
924
+ end
925
+
926
+ ---- header
927
+ require 'ridl/delegate'
928
+
929
+ module IDL
930
+
931
+ ---- footer
932
+
933
+ end #of module IDL