Code

for IDL parsing
[inkscape.git] / src / dom / work / idl.g
1 header {\r
2   package org.apache.yoko.tools.processors.idl;\r
3 \r
4   import java.io.*;\r
5   import java.util.Vector;\r
6   import java.util.Hashtable;\r
7  }\r
8 \r
9 /**\r
10  *  This is a complete parser for the IDL language as defined\r
11  *  by the CORBA 3.0.2 specification.  It will allow those who\r
12  *  need an IDL parser to get up-and-running very quickly.\r
13  *  Though IDL's syntax is very similar to C++, it is also\r
14  *  much simpler, due in large part to the fact that it is\r
15  *  a declarative-only language.\r
16  *\r
17  *  Some things that are not included are: Symbol table construction\r
18  *  (it is not necessary for parsing, btw) and preprocessing (for\r
19  *  IDL compiler #pragma directives). You can use just about any\r
20  *  C or C++ preprocessor, but there is an interesting semantic\r
21  *  issue if you are going to generate code: In C, #include is\r
22  *  a literal include, in IDL, #include is more like Java's import:\r
23  *  It adds definitions to the scope of the parse, but included\r
24  *  definitions are not generated.\r
25  *\r
26  *  Jim Coker, jcoker@magelang.com\r
27  *  Gary Duzan, gduzan@bbn.com\r
28  *  Modified by Edell Nolan May 3, 2007:\r
29  *    We originally used the corba grammar supplied on your site\r
30  *    but it doesn't support forward declaration support for interfaces\r
31  *    we have actually modified the grammar and fixed it. \r
32  */\r
33 class IDLParser extends Parser;\r
34 options {\r
35         exportVocab=IDL;\r
36         buildAST=true;\r
37         k=4;\r
38 }\r
39 \r
40 specification\r
41         :   (import_dcl)* (definition)+\r
42         ;\r
43 \r
44 \r
45 definition\r
46         :   (   type_dcl SEMI!\r
47             |   const_dcl SEMI!\r
48             |   except_dcl SEMI!\r
49             |   (("abstract" | "local")? "interface") => interf SEMI!\r
50             |   module SEMI!\r
51             |   (("abstract" | "custom")? "valuetype") => value SEMI!\r
52             |   type_id_dcl SEMI!\r
53             |   type_prefix_dcl SEMI!\r
54             |   (("abstract" | "custom")? "eventtype") => event SEMI!\r
55             |   component SEMI!\r
56             |   home_dcl SEMI!\r
57             )\r
58         ;\r
59 \r
60 module\r
61         :    "module"^\r
62              identifier     \r
63              LCURLY! d:definition_list RCURLY!\r
64         ;\r
65 \r
66 definition_list\r
67         :   (definition)+\r
68         ;\r
69 \r
70 interf\r
71     : ( interface_dcl\r
72       | forward_dcl\r
73       )\r
74     ;\r
75  \r
76 // Grammar changed to differentiate between \r
77 // forward declared interfaces and empty interfaces\r
78 interface_dcl\r
79         :   (( "abstract" | "local" )?\r
80             "interface"^\r
81             identifier\r
82             ( interface_inheritance_spec )?        \r
83             LCURLY interface_body RCURLY) \r
84         ;\r
85         \r
86 forward_dcl\r
87         :    ( "abstract" | "local" )?\r
88             "interface"^\r
89             identifier\r
90         ;\r
91 \r
92 \r
93 interface_body\r
94         :   ( export )*\r
95         ;\r
96 \r
97 export\r
98         :   (   type_dcl SEMI!\r
99             |   const_dcl SEMI!\r
100             |   except_dcl SEMI!\r
101             |   attr_dcl SEMI!\r
102             |   op_dcl SEMI!\r
103             |   type_id_dcl SEMI!\r
104             |   type_prefix_dcl SEMI!\r
105             )\r
106         ;\r
107 \r
108 \r
109 interface_inheritance_spec\r
110         :   COLON^ scoped_name_list\r
111         ;\r
112 \r
113 interface_name\r
114         :   scoped_name\r
115         ;\r
116 \r
117 scoped_name_list\r
118         :    scoped_name (COMMA! scoped_name)*\r
119         ;\r
120 \r
121 \r
122 scoped_name\r
123         :   ( SCOPEOP^ )? IDENT^ /* identifier */ (SCOPEOP! identifier)*\r
124         ;\r
125 \r
126 value\r
127         :   ( value_dcl\r
128             | value_abs_dcl\r
129             | value_box_dcl\r
130             | value_custom_dcl\r
131             | value_forward_dcl\r
132             )\r
133         ;\r
134 \r
135 value_forward_dcl\r
136         :   "valuetype"^\r
137             identifier\r
138         ;\r
139 \r
140 value_box_dcl\r
141         :   "valuetype"^\r
142             identifier\r
143             type_spec\r
144         ;\r
145 \r
146 value_abs_dcl\r
147         :   "abstract"\r
148             "valuetype"^\r
149             identifier\r
150             ( value_abs_full_dcl\r
151             | // value_abs_forward_dcl\r
152             )\r
153         ;\r
154 \r
155 value_abs_full_dcl\r
156         :   value_inheritance_spec\r
157             LCURLY! ( export )* RCURLY!\r
158         ;\r
159 \r
160 // value_abs_forward_dcl\r
161 //      :\r
162 //      ;\r
163 \r
164 value_dcl\r
165         :   value_header\r
166             LCURLY! ( value_element )* RCURLY!\r
167         ;\r
168 \r
169 value_custom_dcl\r
170         :   "custom"^\r
171             value_dcl\r
172         ;\r
173 \r
174 value_header\r
175         :   "valuetype"^\r
176             identifier\r
177             value_inheritance_spec\r
178         ;\r
179 \r
180 value_inheritance_spec\r
181 /*\r
182         :   ( COLON ( "truncatable" )?\r
183               value_name ( COMMA! value_name )*\r
184             )?\r
185             ( "supports" interface_name ( COMMA! interface_name )* )?\r
186         ;\r
187 */\r
188         :   ( value_value_inheritance_spec )?\r
189             ( value_interface_inheritance_spec )?\r
190         ;\r
191 \r
192 value_value_inheritance_spec\r
193         :   COLON^ ( "truncatable" )?\r
194             value_name ( COMMA! value_name )*\r
195         ;\r
196 \r
197 value_interface_inheritance_spec\r
198         :   "supports"^ interface_name ( COMMA! interface_name )*\r
199         ;\r
200 \r
201 value_name\r
202         :   scoped_name\r
203         ;\r
204 \r
205 value_element\r
206         :   ( export\r
207             | state_member\r
208             | init_dcl\r
209             )\r
210         ;\r
211 \r
212 state_member\r
213         :   ( "public" | "private" )\r
214             type_spec declarators SEMI!\r
215         ;\r
216 \r
217 init_dcl\r
218         :   "factory"^ identifier\r
219             LPAREN! (init_param_decls)? RPAREN!\r
220             (raises_expr)?\r
221             SEMI!\r
222         ;\r
223 \r
224 init_param_decls\r
225         :   init_param_decl ( COMMA! init_param_decl )*\r
226         ;\r
227 \r
228 init_param_decl\r
229         :   init_param_attribute\r
230             param_type_spec\r
231             simple_declarator\r
232         ;\r
233 \r
234 init_param_attribute\r
235         :   "in"\r
236         ;\r
237 \r
238 const_dcl\r
239         :   "const"^ const_type identifier ASSIGN! const_exp\r
240         ;\r
241 \r
242 const_type\r
243         :   (integer_type) => integer_type\r
244         |   char_type\r
245         |   wide_char_type\r
246         |   boolean_type\r
247         |   floating_pt_type\r
248         |   string_type\r
249         |   wide_string_type\r
250         |   fixed_pt_const_type\r
251         |   scoped_name\r
252         |   octet_type\r
253         ;\r
254 \r
255 \r
256 /*   EXPRESSIONS   */\r
257 \r
258 const_exp\r
259         :   or_expr\r
260         ;\r
261 \r
262 or_expr\r
263         :   xor_expr\r
264             ( OR^ // or_op\r
265               xor_expr\r
266             )*\r
267         ;\r
268 \r
269 // or_op\r
270 //      :    OR\r
271 //      ;\r
272 \r
273 \r
274 xor_expr\r
275         :   and_expr\r
276             ( XOR^ // xor_op\r
277               and_expr\r
278             )*\r
279         ;\r
280 \r
281 // xor_op\r
282 //      :    XOR\r
283 //      ;\r
284 \r
285 and_expr\r
286         :   shift_expr\r
287             ( AND^ // and_op\r
288               shift_expr\r
289             )*\r
290         ;\r
291 \r
292 // and_op\r
293 //      :    AND\r
294 //      ;\r
295 \r
296 \r
297 shift_expr\r
298         :   add_expr\r
299             ( ( LSHIFT^\r
300               | RSHIFT^\r
301               ) // shift_op\r
302             add_expr\r
303             )*\r
304         ;\r
305 \r
306 // shift_op\r
307 //      :    LSHIFT\r
308 //      |    RSHIFT\r
309 //      ;\r
310 \r
311 \r
312 add_expr\r
313         :   mult_expr\r
314             ( ( PLUS^\r
315               | MINUS^\r
316               ) // add_op\r
317               mult_expr\r
318             )*\r
319         ;\r
320 \r
321 // add_op\r
322 //      :    PLUS\r
323 //      |    MINUS\r
324 //      ;\r
325 \r
326 mult_expr\r
327         :   unary_expr\r
328             ( ( STAR^\r
329               | DIV^\r
330               | MOD^\r
331               ) // mult_op\r
332               unary_expr\r
333             )*\r
334         ;\r
335 \r
336 // mult_op\r
337 //      :    STAR\r
338 //      |    DIV\r
339 //      |    MOD\r
340 //      ;\r
341 \r
342 unary_expr\r
343         :   ( MINUS^\r
344             | PLUS^\r
345             | TILDE^\r
346             ) // unary_operator\r
347             primary_expr\r
348         |   primary_expr\r
349         ;\r
350 \r
351 // unary_operator\r
352 //      :   MINUS\r
353 //      |   PLUS\r
354 //      |   TILDE\r
355 //      ;\r
356 \r
357 // Node of type TPrimaryExp serves to avoid inf. recursion on tree parse\r
358 primary_expr\r
359         :   scoped_name\r
360         |   literal\r
361         |   LPAREN^ const_exp RPAREN\r
362         ;\r
363 \r
364 literal\r
365         :   integer_literal\r
366         |   string_literal\r
367         |   wide_string_literal\r
368         |   character_literal\r
369         |   wide_character_literal\r
370         |   fixed_pt_literal\r
371         |   floating_pt_literal\r
372         |   boolean_literal\r
373         ;\r
374 \r
375 boolean_literal\r
376         :   "TRUE"\r
377         |   "FALSE"\r
378         ;\r
379 \r
380 positive_int_const\r
381         :    const_exp\r
382         ;\r
383 \r
384 \r
385 type_dcl\r
386         :   "typedef"^ type_declarator\r
387         |   (struct_type) => struct_type\r
388         |   (union_type) => union_type\r
389         |   enum_type\r
390         |   "native"^ simple_declarator\r
391         |   constr_forward_decl\r
392         ;\r
393 \r
394 type_declarator\r
395         :   type_spec declarators\r
396         ;\r
397 \r
398 type_spec\r
399         :   simple_type_spec\r
400         |   constr_type_spec\r
401         ;\r
402 \r
403 simple_type_spec\r
404         :   base_type_spec\r
405         |   template_type_spec\r
406         |   scoped_name\r
407         ;\r
408 \r
409 base_type_spec\r
410         :   (floating_pt_type) => floating_pt_type      \r
411         |   integer_type        \r
412         |   char_type           \r
413         |   wide_char_type              \r
414         |   boolean_type        \r
415         |   octet_type\r
416         |   any_type\r
417         |   object_type\r
418         |   value_base_type\r
419         ;\r
420 \r
421 template_type_spec\r
422         :   sequence_type\r
423         |   string_type\r
424         |   wide_string_type\r
425         |   fixed_pt_type\r
426         ;\r
427 \r
428 constr_type_spec\r
429         :   struct_type\r
430         |   union_type\r
431         |   enum_type\r
432         ;\r
433 \r
434 declarators\r
435         :   declarator (COMMA! declarator)*\r
436         ;\r
437 \r
438 declarator\r
439         :   simple_declarator\r
440         |   complex_declarator\r
441         ;\r
442 \r
443 simple_declarator\r
444         :   identifier\r
445         ;\r
446 \r
447 complex_declarator\r
448         :   array_declarator\r
449         ;\r
450 \r
451 floating_pt_type\r
452         :   "float"\r
453         |   "double"\r
454         |   "long"^ "double"\r
455         ;\r
456 \r
457 integer_type\r
458         :  signed_int\r
459         |  unsigned_int\r
460         ;\r
461 \r
462 signed_int\r
463         :  signed_short_int\r
464         |  signed_long_int\r
465         |  signed_longlong_int\r
466         ;\r
467 \r
468 signed_short_int\r
469         :  "short"\r
470         ;\r
471 \r
472 signed_long_int\r
473         :  "long"\r
474         ;\r
475 \r
476 signed_longlong_int\r
477         :  "long" "long"\r
478         ;\r
479 \r
480 unsigned_int\r
481         :  unsigned_short_int\r
482         |  unsigned_long_int\r
483         |  unsigned_longlong_int\r
484         ;\r
485 \r
486 unsigned_short_int\r
487         :  "unsigned" "short"\r
488         ;\r
489 \r
490 unsigned_long_int\r
491         :  "unsigned" "long"\r
492         ;\r
493 \r
494 unsigned_longlong_int\r
495         :  "unsigned" "long" "long"\r
496         ;\r
497 \r
498 char_type\r
499         :   "char"\r
500         ;\r
501 \r
502 wide_char_type\r
503         :   "wchar"\r
504         ;\r
505 \r
506 boolean_type\r
507         :   "boolean"\r
508         ;\r
509 \r
510 octet_type\r
511         :   "octet"\r
512         ;\r
513 \r
514 any_type\r
515         :   "any"\r
516         ;\r
517 \r
518 object_type\r
519         :   "Object"\r
520         ;\r
521 \r
522 struct_type\r
523         :   "struct"^\r
524             identifier\r
525             LCURLY! member_list RCURLY!\r
526         ;\r
527 \r
528 member_list\r
529         :   (member)+\r
530         ;\r
531 \r
532 member\r
533         :   type_spec declarators SEMI!\r
534         ;\r
535 \r
536 union_type\r
537         :   "union"^\r
538             identifier\r
539             "switch"! LPAREN! switch_type_spec RPAREN!\r
540             LCURLY! switch_body RCURLY!\r
541         ;\r
542 \r
543 switch_type_spec\r
544         :   integer_type\r
545         |   char_type\r
546         |   boolean_type\r
547         |   enum_type\r
548         |   scoped_name\r
549         ;\r
550 \r
551 switch_body\r
552         :   case_stmt_list\r
553         ;\r
554 \r
555 case_stmt_list\r
556         :  (case_stmt)+\r
557         ;\r
558 \r
559 case_stmt\r
560         :   // case_label_list\r
561             ( "case"^ const_exp COLON!\r
562             | "default"^ COLON!\r
563             )+\r
564             element_spec SEMI!\r
565         ;\r
566 \r
567 // case_label_list\r
568 //      :   (case_label)+\r
569 //      ;\r
570 \r
571 \r
572 // case_label\r
573 //      :   "case"^ const_exp COLON!\r
574 //      |   "default"^ COLON!\r
575 //      ;\r
576 \r
577 element_spec\r
578         :   type_spec declarator\r
579         ;\r
580 \r
581 enum_type\r
582         :   "enum"^ identifier LCURLY! enumerator_list RCURLY!\r
583         ;\r
584 \r
585 enumerator_list\r
586         :    enumerator (COMMA! enumerator)*\r
587         ;\r
588 \r
589 enumerator\r
590         :   identifier\r
591         ;\r
592 \r
593 sequence_type\r
594         :   "sequence"^\r
595              LT! simple_type_spec opt_pos_int GT!\r
596         ;\r
597 \r
598 opt_pos_int\r
599         :    (COMMA! positive_int_const)?\r
600         ;\r
601 \r
602 string_type\r
603         :   "string"^ (LT! positive_int_const GT!)?\r
604         ;\r
605 \r
606 wide_string_type\r
607         :   "wstring"^ (LT! positive_int_const GT!)?\r
608         ;\r
609 \r
610 array_declarator\r
611         :   IDENT^                                      // identifier\r
612             (fixed_array_size)+\r
613         ;\r
614 \r
615 fixed_array_size\r
616         :   LBRACK! positive_int_const RBRACK!\r
617         ;\r
618 \r
619 attr_dcl\r
620         :   readonly_attr_spec\r
621         |   attr_spec\r
622         ;\r
623 \r
624 except_dcl\r
625         :   "exception"^\r
626             identifier\r
627             LCURLY! opt_member_list RCURLY!\r
628         ;\r
629 \r
630 \r
631 opt_member_list\r
632         :    (member)*\r
633         ;\r
634 \r
635 op_dcl\r
636         :   (op_attribute)?\r
637             op_type_spec\r
638             IDENT^                              // identifier\r
639             parameter_dcls\r
640             (raises_expr)?\r
641             (context_expr)?\r
642         ;\r
643 \r
644 op_attribute\r
645         :   "oneway"\r
646         ;\r
647 \r
648 op_type_spec\r
649         :   param_type_spec\r
650         |   "void"\r
651         ;\r
652 \r
653 parameter_dcls\r
654         :   LPAREN! (param_dcl_list)? RPAREN!\r
655         ;\r
656 \r
657 param_dcl_list\r
658         :   param_dcl (COMMA! param_dcl)*\r
659         ;\r
660 \r
661 param_dcl\r
662         :   ("in"^ | "out"^ | "inout"^)         // param_attribute\r
663             param_type_spec simple_declarator\r
664         ;\r
665 \r
666 // param_attribute\r
667 //      :   "in"\r
668 //      |   "out"\r
669 //      |   "inout"\r
670 //      ;\r
671 \r
672 raises_expr\r
673         :   "raises"^ LPAREN! scoped_name_list RPAREN!\r
674         ;\r
675 \r
676 context_expr\r
677         :   "context"^ LPAREN! string_literal_list RPAREN!\r
678         ;\r
679 \r
680 string_literal_list\r
681         :    string_literal (COMMA! string_literal)*\r
682         ;\r
683 \r
684 param_type_spec\r
685         :   base_type_spec\r
686         |   string_type\r
687         |   wide_string_type\r
688         |   scoped_name\r
689         ;\r
690 \r
691 fixed_pt_type\r
692         :   "fixed"^ LT! positive_int_const COMMA! positive_int_const GT!\r
693         ;\r
694 \r
695 fixed_pt_const_type\r
696         :   "fixed"\r
697         ;\r
698 \r
699 value_base_type\r
700         :   "ValueBase"\r
701         ;\r
702 \r
703 constr_forward_decl\r
704         :   "struct"^ identifier\r
705         |   "union"^ identifier\r
706         ;\r
707 \r
708 import_dcl\r
709         :   "import"^ imported_scope SEMI!\r
710         ;\r
711 \r
712 imported_scope\r
713         :   scoped_name\r
714         |   string_literal\r
715         ;\r
716 \r
717 type_id_dcl\r
718         :   "typeid"^\r
719             scoped_name\r
720             string_literal\r
721         ;\r
722 \r
723 type_prefix_dcl\r
724         :   "typeprefix"^\r
725             scoped_name\r
726             string_literal\r
727         ;\r
728 \r
729 readonly_attr_spec\r
730         :   "readonly" "attribute"^\r
731             param_type_spec\r
732             readonly_attr_declarator\r
733         ;\r
734 \r
735 readonly_attr_declarator\r
736         :   simple_declarator\r
737             ( raises_expr\r
738             | (COMMA! simple_declarator)*\r
739             )\r
740         ;\r
741 \r
742 attr_spec\r
743         :   "attribute"^ param_type_spec attr_declarator\r
744         ;\r
745 \r
746 attr_declarator\r
747         :   simple_declarator\r
748             ( ("getraises" | "setraises") => attr_raises_expr\r
749             | (COMMA! simple_declarator)*\r
750             )\r
751         ;\r
752 \r
753 attr_raises_expr\r
754         :   (get_excep_expr)?\r
755             (set_excep_expr)?\r
756         ;\r
757 \r
758 get_excep_expr\r
759         :   "getraises"^ exception_list\r
760         ;\r
761 \r
762 set_excep_expr\r
763         :   "setraises"^ exception_list\r
764         ;\r
765 \r
766 exception_list\r
767         :   LPAREN! scoped_name (COMMA! scoped_name)* RPAREN!\r
768         ;\r
769 \r
770 // Component Stuff\r
771 \r
772 component\r
773         :   "component"^\r
774             identifier\r
775             (component_dcl)?\r
776         ;\r
777 \r
778 component_dcl\r
779         :   (component_inheritance_spec)?\r
780             (supported_interface_spec)?\r
781             LCURLY! component_body RCURLY!\r
782         ;\r
783 \r
784 supported_interface_spec\r
785         :   "supports"^ scoped_name ( COMMA! scoped_name )*\r
786         ;\r
787 \r
788 component_inheritance_spec\r
789         :   COLON^ scoped_name\r
790         ;\r
791 \r
792 component_body\r
793         :   (component_export)*\r
794         ;\r
795 \r
796 component_export\r
797         :   ( provides_dcl SEMI!\r
798             | uses_dcl SEMI!\r
799             | emits_dcl SEMI!\r
800             | publishes_dcl SEMI!\r
801             | consumes_dcl SEMI!\r
802             | attr_dcl SEMI!\r
803             )\r
804         ;\r
805 \r
806 provides_dcl\r
807         :   "provides"^ interface_type identifier\r
808         ;\r
809 \r
810 interface_type\r
811         :   ( scoped_name\r
812             | "Object"\r
813             )\r
814         ;\r
815 \r
816 uses_dcl\r
817         :   "uses"^ ("multiple")? interface_type identifier\r
818         ;\r
819 \r
820 emits_dcl\r
821         :   "emits"^ scoped_name identifier\r
822         ;\r
823 \r
824 publishes_dcl\r
825         :   "publishes"^ scoped_name identifier\r
826         ;\r
827 \r
828 consumes_dcl\r
829         :   "consumes"^ scoped_name identifier\r
830         ;\r
831 \r
832 home_dcl\r
833         :   home_header home_body\r
834         ;\r
835 \r
836 home_header\r
837         :   "home"^ identifier\r
838             (home_inheritance_spec)?\r
839             (supported_interface_spec)?\r
840             "manages"! scoped_name\r
841             (primary_key_spec)?\r
842         ;\r
843 \r
844 home_inheritance_spec\r
845         :   COLON^ scoped_name\r
846         ;\r
847 \r
848 primary_key_spec\r
849         :   "primarykey"^ scoped_name\r
850         ;\r
851 \r
852 home_body\r
853         :   LCURLY! (home_export)* RCURLY!\r
854         ;\r
855 \r
856 home_export\r
857         :   ( export\r
858             | factory_dcl SEMI!\r
859             | finder_dcl SEMI!\r
860             )\r
861         ;\r
862 \r
863 factory_dcl\r
864         :   "factory"^ identifier\r
865             LPAREN! init_param_decls RPAREN!\r
866             (raises_expr)?\r
867         ;\r
868 \r
869 finder_dcl\r
870         :   "finder"^ identifier\r
871             LPAREN! init_param_decls RPAREN!\r
872             (raises_expr)?\r
873         ;\r
874 \r
875 event\r
876         :   ( event_abs\r
877             | event_custom\r
878             | event_dcl\r
879             )\r
880         ;\r
881 \r
882 event_header\r
883         :   "eventtype"^\r
884             identifier\r
885         ;\r
886 \r
887 event_abs\r
888         :   "abstract"^\r
889             event_header\r
890             (event_abs_dcl)?\r
891         ;\r
892 \r
893 event_abs_dcl\r
894         :   value_inheritance_spec\r
895             LCURLY! (export)* RCURLY!\r
896         ;\r
897 \r
898 event_custom\r
899         :   "custom"^\r
900             event_header\r
901             event_elem_dcl\r
902         ;\r
903 \r
904 event_dcl\r
905         :   event_header\r
906             ( event_elem_dcl\r
907             | // event_forward_dcl\r
908             )\r
909         ;\r
910 \r
911 event_elem_dcl\r
912         :   value_inheritance_spec\r
913             LCURLY! (export)* RCURLY!\r
914         ;\r
915 \r
916 // event_forward_dcl\r
917 //      :\r
918 //      ;\r
919 \r
920 /* literals */\r
921 integer_literal\r
922         :   INT\r
923         |   OCTAL\r
924         |   HEX\r
925         ;\r
926 \r
927 string_literal\r
928         :  (STRING_LITERAL)+\r
929         ;\r
930 \r
931 wide_string_literal\r
932         :  (WIDE_STRING_LITERAL)+\r
933         ;\r
934 \r
935 character_literal\r
936         :  CHAR_LITERAL\r
937         ;\r
938 \r
939 wide_character_literal\r
940         :  WIDE_CHAR_LITERAL\r
941         ;\r
942 \r
943 fixed_pt_literal\r
944         :  FIXED\r
945         ;\r
946 \r
947 floating_pt_literal\r
948         :   f:FLOAT\r
949         ;\r
950 \r
951 identifier\r
952         :   IDENT\r
953         ;\r
954 \r
955 /* IDL LEXICAL RULES  */\r
956 class IDLLexer extends Lexer;\r
957 options {\r
958         exportVocab=IDL;\r
959         charVocabulary='\u0000'..'\uFFFE';\r
960         k=4;\r
961 }\r
962 \r
963 SEMI\r
964 options {\r
965   paraphrase = ";";\r
966 }\r
967         :       ';'\r
968         ;\r
969 \r
970 QUESTION\r
971 options {\r
972   paraphrase = "?";\r
973 }\r
974         :       '?'\r
975         ;\r
976 \r
977 LPAREN\r
978 options {\r
979   paraphrase = "(";\r
980 }\r
981         :       '('\r
982         ;\r
983 \r
984 RPAREN\r
985 options {\r
986   paraphrase = ")";\r
987 }\r
988         :       ')'\r
989         ;\r
990 \r
991 LBRACK\r
992 options {\r
993   paraphrase = "[";\r
994 }\r
995         :       '['\r
996         ;\r
997 \r
998 RBRACK\r
999 options {\r
1000   paraphrase = "]";\r
1001 }\r
1002         :       ']'\r
1003         ;\r
1004 \r
1005 LCURLY\r
1006 options {\r
1007   paraphrase = "{";\r
1008 }\r
1009         :       '{'\r
1010         ;\r
1011 \r
1012 RCURLY\r
1013 options {\r
1014   paraphrase = "}";\r
1015 }\r
1016         :       '}'\r
1017         ;\r
1018 \r
1019 OR\r
1020 options {\r
1021   paraphrase = "|";\r
1022 }\r
1023         :       '|'\r
1024         ;\r
1025 \r
1026 XOR\r
1027 options {\r
1028   paraphrase = "^";\r
1029 }\r
1030         :       '^'\r
1031         ;\r
1032 \r
1033 AND\r
1034 options {\r
1035   paraphrase = "&";\r
1036 }\r
1037         :       '&'\r
1038         ;\r
1039 \r
1040 COLON\r
1041 options {\r
1042   paraphrase = ":";\r
1043 }\r
1044         :       ':'\r
1045         ;\r
1046 \r
1047 COMMA\r
1048 options {\r
1049   paraphrase = ",";\r
1050 }\r
1051         :       ','\r
1052         ;\r
1053 \r
1054 DOT\r
1055 options {\r
1056   paraphrase = ".";\r
1057 }\r
1058         :       '.'\r
1059         ;\r
1060 \r
1061 ASSIGN\r
1062 options {\r
1063   paraphrase = "=";\r
1064 }\r
1065         :       '='\r
1066         ;\r
1067 \r
1068 NOT\r
1069 options {\r
1070   paraphrase = "!";\r
1071 }\r
1072         :       '!'\r
1073         ;\r
1074 \r
1075 LT\r
1076 options {\r
1077   paraphrase = "<";\r
1078 }\r
1079         :       '<'\r
1080         ;\r
1081 \r
1082 LSHIFT\r
1083 options {\r
1084   paraphrase = "<<";\r
1085 }\r
1086         : "<<"\r
1087         ;\r
1088 \r
1089 GT\r
1090 options {\r
1091   paraphrase = ">";\r
1092 }\r
1093         :       '>'\r
1094         ;\r
1095 \r
1096 RSHIFT\r
1097 options {\r
1098   paraphrase = ">>";\r
1099 }\r
1100         : ">>"\r
1101         ;\r
1102 \r
1103 DIV\r
1104 options {\r
1105   paraphrase = "/";\r
1106 }\r
1107         :       '/'\r
1108         ;\r
1109 \r
1110 PLUS\r
1111 options {\r
1112   paraphrase = "+";\r
1113 }\r
1114         :       '+'\r
1115         ;\r
1116 \r
1117 MINUS\r
1118 options {\r
1119   paraphrase = "-";\r
1120 }\r
1121         :       '-'\r
1122         ;\r
1123 \r
1124 TILDE\r
1125 options {\r
1126   paraphrase = "~";\r
1127 }\r
1128         :       '~'\r
1129         ;\r
1130 \r
1131 STAR\r
1132 options {\r
1133   paraphrase = "*";\r
1134 }\r
1135         :       '*'\r
1136         ;\r
1137 \r
1138 MOD\r
1139 options {\r
1140   paraphrase = "%";\r
1141 }\r
1142         :       '%'\r
1143         ;\r
1144 \r
1145 \r
1146 SCOPEOP\r
1147 options {\r
1148   paraphrase = "::";\r
1149 }\r
1150         :       "::"\r
1151         ;\r
1152 \r
1153 WS\r
1154 options {\r
1155   paraphrase = "white space";\r
1156 }\r
1157         :       (' '\r
1158         |       '\t'\r
1159         |       '\n'  { newline(); }\r
1160         |       '\r')\r
1161                 { $setType(Token.SKIP); }\r
1162         ;\r
1163 \r
1164 \r
1165 PREPROC_DIRECTIVE\r
1166 options {\r
1167   paraphrase = "a preprocessor directive";\r
1168 }\r
1169 \r
1170         :\r
1171         '#'!\r
1172         (~'\n')* '\n'!\r
1173         { $setType(Token.SKIP); newline(); }\r
1174         ;\r
1175 \r
1176 \r
1177 SL_COMMENT\r
1178 options {\r
1179   paraphrase = "a comment";\r
1180 }\r
1181 \r
1182         :\r
1183         "//"!\r
1184         (~'\n')* '\n'\r
1185         { $setType(Token.SKIP); newline(); }\r
1186         ;\r
1187 \r
1188 ML_COMMENT\r
1189 options {\r
1190   paraphrase = "a comment";\r
1191 }\r
1192         :\r
1193         "/*"!\r
1194         (\r
1195                         '\n' { newline(); }\r
1196                 |       ('*')+\r
1197                         (       '\n' { newline(); }\r
1198                         |       ~('*' | '/' | '\n')\r
1199                         )\r
1200                 |       ~('*' | '\n')\r
1201         )*\r
1202         "*/"!\r
1203         { $setType(Token.SKIP);  }\r
1204         ;\r
1205 \r
1206 CHAR_LITERAL\r
1207 options {\r
1208   paraphrase = "a character literal";\r
1209 }\r
1210         :\r
1211         '\''!\r
1212         ( ESC | ~'\'' )\r
1213         '\''!\r
1214         ;\r
1215 \r
1216 WIDE_CHAR_LITERAL\r
1217 options {\r
1218   paraphrase = "a wide character literal";\r
1219 }\r
1220         : 'L'! CHAR_LITERAL\r
1221         ;\r
1222 \r
1223 STRING_LITERAL\r
1224 options {\r
1225   paraphrase = "a string literal";\r
1226 }\r
1227         :\r
1228         '"'!\r
1229         (ESC|~'"')*\r
1230         '"'!\r
1231         ;\r
1232 \r
1233 \r
1234 WIDE_STRING_LITERAL\r
1235 options {\r
1236   paraphrase = "a wide string literal";\r
1237 }\r
1238         :\r
1239         'L'! STRING_LITERAL\r
1240         ;\r
1241 \r
1242 protected\r
1243 ESC\r
1244 options {\r
1245   paraphrase = "an escape sequence";\r
1246 }\r
1247         :       '\\'!\r
1248                 (       'n'             {$setText("\n");}\r
1249                 |       't'             {$setText("\t");}\r
1250                 |       'v'             {$setText("\013");}\r
1251                 |       'b'             {$setText("\b");}\r
1252                 |       'r'             {$setText("\r");}\r
1253                 |       'f'             {$setText("\r");}\r
1254                 |       'a'             {$setText("\007");}\r
1255                 |       '\\'            {$setText("\\");}\r
1256                 |       '?'             {$setText("?");}\r
1257                 |       '\''            {$setText("'");}\r
1258                 |       '"'             {$setText("\"");}\r
1259                 |       OCTDIGIT\r
1260                         (options {greedy=true;}:OCTDIGIT\r
1261                           (options {greedy=true;}:OCTDIGIT)?\r
1262                         )?\r
1263                         {char realc = (char) Integer.valueOf($getText, 8).intValue(); $setText(realc);}\r
1264                 |       'x'! HEXDIGIT\r
1265                         (options {greedy=true;}:HEXDIGIT)?\r
1266                         {char realc = (char) Integer.valueOf($getText, 16).intValue(); $setText(realc);}\r
1267                 |       'u'!\r
1268                         HEXDIGIT\r
1269                         (options {greedy=true;}:HEXDIGIT\r
1270                           (options {greedy=true;}:HEXDIGIT\r
1271                             (options {greedy=true;}:HEXDIGIT)?\r
1272                           )?\r
1273                         )?\r
1274                         {char realc = (char) Integer.valueOf($getText, 16).intValue(); $setText(realc);}\r
1275                 )\r
1276         ;\r
1277 \r
1278 protected\r
1279 VOCAB\r
1280 options {\r
1281   paraphrase = "an escaped character value";\r
1282 }\r
1283         :       '\3'..'\377'\r
1284         ;\r
1285 \r
1286 protected\r
1287 DIGIT\r
1288 options {\r
1289   paraphrase = "a digit";\r
1290 }\r
1291         :       '0'..'9'\r
1292         ;\r
1293 \r
1294 protected\r
1295 NONZERODIGIT\r
1296 options {\r
1297   paraphrase = "a non-zero digit";\r
1298 }\r
1299         :       '1'..'9'\r
1300         ;\r
1301 \r
1302 protected\r
1303 OCTDIGIT\r
1304 options {\r
1305   paraphrase = "an octal digit";\r
1306 }\r
1307         :       '0'..'7'\r
1308         ;\r
1309 \r
1310 protected\r
1311 HEXDIGIT\r
1312 options {\r
1313   paraphrase = "a hexadecimal digit";\r
1314 }\r
1315         :       ('0'..'9' | 'a'..'f' | 'A'..'F')\r
1316         ;\r
1317 \r
1318 HEX\r
1319 options {\r
1320   paraphrase = "a hexadecimal value value";\r
1321 }\r
1322 \r
1323         :    ("0x" | "0X") (HEXDIGIT)+\r
1324         ;\r
1325 \r
1326 INT\r
1327 options {\r
1328   paraphrase = "an integer value";\r
1329 }\r
1330         :    NONZERODIGIT (DIGIT)*                  // base-10\r
1331              (  '.' (DIGIT)*\r
1332                  ( (('e' | 'E') ('+' | '-')? (DIGIT)+)  {$setType(FLOAT);}\r
1333                  | ('d' | 'D')!                         {$setType(FIXED);}\r
1334                  |                                      {$setType(FLOAT);}\r
1335                  )\r
1336              |   ('e' | 'E') ('+' | '-')? (DIGIT)+      {$setType(FLOAT);}\r
1337              |   ('d' | 'D')!                           {$setType(FIXED);}\r
1338              )?\r
1339         ;\r
1340 \r
1341 OCTAL\r
1342 options {\r
1343   paraphrase = "an octal value";\r
1344 }\r
1345         :    '0'\r
1346              ( (DIGIT)+\r
1347              | FLOAT                                    {$setType(FLOAT);}\r
1348              | ('d' | 'D')!                             {$setType(FIXED);}\r
1349              |                                          {$setType(INT);}\r
1350              )\r
1351         ;\r
1352 \r
1353 \r
1354 FLOAT\r
1355 options {\r
1356   paraphrase = "a floating point value";\r
1357 }\r
1358 \r
1359         :    '.' (DIGIT)+\r
1360              ( ('e' | 'E') ('+' | '-')? (DIGIT)+\r
1361              | ('d' | 'D')!                             {$setType(FIXED);}\r
1362              )?\r
1363         ;\r
1364 \r
1365 IDENT\r
1366 options {\r
1367   paraphrase = "an identifer";\r
1368   testLiterals = true;\r
1369 }\r
1370 \r
1371         :   ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*\r
1372         ;\r
1373 \r
1374 ESCAPED_IDENT\r
1375 options {\r
1376   paraphrase = "an escaped identifer";\r
1377   testLiterals = false;                 // redundant, but explicit is good.\r
1378 }\r
1379     // NOTE: Adding a ! to the '_' doesn't seem to work,\r
1380     //       so we adjust _begin manually.\r
1381 \r
1382         :   '_' ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*\r
1383                                                         {_begin++;$setType(IDENT);}\r
1384         ;\r
1385 \r
1386 \r