Debian Codegraph @

src/main/antlr4/kiara/com/eprosima/idl/parser/grammar/KIARAIDL.g4

raw
1 // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 grammar KIARAIDL;
16
17 @header {
18 //package com.eprosima.idl.parser.grammar;
19
20 import com.eprosima.idl.context.Context;
21 import com.eprosima.idl.generator.manager.TemplateManager;
22 import com.eprosima.idl.generator.manager.TemplateGroup;
23 import com.eprosima.idl.generator.manager.TemplateUtil;
24 import com.eprosima.idl.parser.typecode.*;
25 import com.eprosima.idl.parser.tree.*;
26 import com.eprosima.idl.util.Pair;
27 import com.eprosima.idl.parser.strategy.DefaultErrorStrategy;
28 import com.eprosima.idl.parser.listener.DefaultErrorListener;
29 import com.eprosima.idl.parser.exception.ParseException;
30
31 import java.util.Vector;
32 }
33
34 @parser::members {
35 private TemplateManager tmanager = null;
36 private Context ctx = null;
37
38 public Context getContext_()
39 {
40 return ctx;
41 }
42 }
43
44 @lexer::members{
45 private Context ctx = null;
46
47 public void setContext(Context _ctx)
48 {
49 ctx = _ctx;
50 }
51 }
52
53 specification [Context context, TemplateManager templatemanager, TemplateGroup maintemplates] returns [Specification spec = null]
54 @init{
55 //! Used to catch each definition grammar element in the whole IDL file.
56 Pair<Vector<Definition>, TemplateGroup> dtg = null;
57 List<Definition> specificationChildren = new ArrayList<Definition>();
58 ctx = context;
59 tmanager = templatemanager;
60
61 // Set error handler
62 DefaultErrorListener listener = new DefaultErrorListener(ctx);
63 this.setErrorHandler(DefaultErrorStrategy.INSTANCE);
64 // Select listener for errors.
65 ((Lexer)this._input.getTokenSource()).removeErrorListeners();
66 ((Lexer)this._input.getTokenSource()).addErrorListener(listener);
67 this.removeErrorListeners();
68 this.addErrorListener(listener);
69 }
70 : import_decl*
71 (
72 definition[null]
73 {
74 dtg=$definition.dtg;
75 if (dtg!=null) {
76 if(maintemplates != null) {
77 maintemplates.setAttribute("definitions", dtg.second());
78 }
79 for(int count = 0; count < dtg.first().size(); ++count)
80 {
81 ctx.addDefinition(dtg.first().get(count));
82 specificationChildren.add(dtg.first().get(count));
83 }
84 }
85 }
86 )+
87 {
88 if(getNumberOfSyntaxErrors() == 0)
89 {
90 $spec = new Specification();
91 $spec.setDefinitions(specificationChildren);
92 }
93 }
94 ;
95
96 /*!
97 * @brief This grammar element represents a global definition: type declaration, interface, module, etc...
98 * @return A pair with the object that represents the definition (interface for other objects like module grammar element)
99 * and the template group generated by the definition (in fact the template group generated by the element who inherits).
100 */
101 definition [Vector<Annotation> annotations] returns [Pair<Vector<Definition>, TemplateGroup> dtg = null]
102 @init {
103 // TODO Cambiar esto. No me gusta la forma.
104
105 Vector<Definition> vector = new Vector<Definition>();
106 Pair<Vector<TypeDeclaration>, TemplateGroup> tdtg = null;
107 Pair<ConstDeclaration, TemplateGroup> cdtg = null;
108 Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup> etg = null;
109 Pair<Interface, TemplateGroup> itg = null;
110 Pair<com.eprosima.idl.parser.tree.Module, TemplateGroup> mtg = null;
111 Pair<AnnotationDeclaration, TemplateGroup> atg = null;
112
113 if(annotations == null) annotations = new Vector<Annotation>();
114 }
115 : type_decl[annotations] SEMICOLON { tdtg=$type_decl.returnPair; if(tdtg!=null){ for(TypeDeclaration tydl : tdtg.first()) vector.add(tydl); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, tdtg.second());}} // Type Declaration
116 | const_decl SEMICOLON { cdtg=$const_decl.returnPair; if(cdtg!=null){ vector.add(cdtg.first()); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, cdtg.second());}} // Const Declaration
117 | except_decl SEMICOLON { etg=$except_decl.returnPair; if(etg!=null){ vector.add(etg.first()); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, etg.second());}} // Exception.
118 | interface_or_forward_decl[annotations] SEMICOLON { itg=$interface_or_forward_decl.itg; if(itg!=null){ vector.add(itg.first()); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, itg.second());}} // Interface
119 | module SEMICOLON { mtg=$module.returnPair; if(mtg!=null){ vector.add(mtg.first()); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, mtg.second());}} // Module
120 | value SEMICOLON
121 | type_id_decl SEMICOLON
122 | type_prefix_decl SEMICOLON
123 | event SEMICOLON
124 | component SEMICOLON
125 | home_decl SEMICOLON
126 | annotation_decl SEMICOLON { atg=$annotation_decl.returnPair; if(atg!=null){ vector.add(atg.first()); $dtg = new Pair<Vector<Definition>, TemplateGroup>(vector, atg.second());}}
127 | annotation_appl
128 {
129 annotations.add($annotation_appl.annotation);
130 }
131 aux_definition[annotations]{$dtg=$aux_definition.dtg;}
132 ;
133
134 aux_definition [Vector<Annotation> annotations] returns [Pair<Vector<Definition>, TemplateGroup> dtg = null]
135 : definition[annotations] {$dtg=$definition.dtg;}
136 ;
137
138 /*!
139 * @brief This grammar expression catches a module definition.
140 * @return This grammar expression returns the Module object as DefinitionContainer to be stored.
141 * Also the TemplateGroup of module is returned.
142 */
143 module returns [Pair<com.eprosima.idl.parser.tree.Module, TemplateGroup> returnPair = null]
144 @init{
145 com.eprosima.idl.parser.tree.Module moduleObject = null;
146 TemplateGroup moduleTemplates = null;
147 TemplateGroup tg = null;
148 // Store old namespace.
149 String name = null, old_scope = ctx.getScope();
150 Token tk = null;
151 }
152 : ( KW_MODULE | KW_NAMESPACE )
153 {
154 tk = _input.LT(1);
155 }
156 identifier
157 {
158 name=$identifier.id;
159 // Create the Module object.
160 moduleObject = new com.eprosima.idl.parser.tree.Module(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), name, tk);
161
162 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll()) {
163 if(tmanager != null) {
164 moduleTemplates = tmanager.createTemplateGroup("module");
165 moduleTemplates.setAttribute("ctx", ctx);
166 // Set the module object to the TemplateGroup of the module.
167 moduleTemplates.setAttribute("module", moduleObject);
168 }
169 }
170
171 // Update to a new namespace.
172 if(old_scope.isEmpty())
173 ctx.setScope(name);
174 else
175 ctx.setScope(old_scope + "::" + name);
176
177 // Add the module to the context.
178 ctx.addModule(moduleObject);
179 }
180 // Each definition is stored in the Module and each TemplateGroup is set as attribute in the TemplateGroup of the module.
181 LEFT_BRACE
182 definition_list[moduleObject]{ tg=$definition_list.dlTemplates; if(moduleTemplates!=null && tg!=null)moduleTemplates.setAttribute("definition_list", tg);}
183 RIGHT_BRACE
184 {
185 // Set the old namespace.
186 ctx.setScope(old_scope);
187 // Create the returned data.
188 $returnPair = new Pair<com.eprosima.idl.parser.tree.Module, TemplateGroup>(moduleObject, moduleTemplates);
189 }
190 ;
191
192
193 /*!
194 * @brief This grammar expression catches a list of definitions.
195 * @param dc An object that inherits from DefinitionContainer. This object could store all definitions.
196 * @return This grammar expression returns the template group with all template groups of definitions.
197 */
198 definition_list [DefinitionContainer dc] returns [TemplateGroup dlTemplates]
199 @init{
200 Pair<Vector<Definition>, TemplateGroup> dtg = null;
201 if(tmanager != null) {
202 $dlTemplates = tmanager.createTemplateGroup("definition_list");
203 }
204 }
205 : (
206 definition[null]
207 {
208 dtg=$definition.dtg;
209 if(dtg!=null)
210 {
211 for(int count = 0; count < dtg.first().size(); ++count)
212 dc.add(dtg.first().get(count));
213
214 if($dlTemplates != null && dtg.second() != null)
215 {
216 // Set parent
217 dtg.second().setAttribute("parent", dc);
218 // Print template into definitions rule
219 $dlTemplates.setAttribute("definitions", dtg.second());
220 }
221 }
222 }
223 )+
224 ;
225
226 /*!
227 * @brief This grammar expression catches currently a interface declaration.
228 * @return This grammar expression returns the interface object and its template group.
229 */
230 interface_or_forward_decl [Vector<Annotation> annotations] returns [Pair<Interface, TemplateGroup> itg = null]
231 : interface_decl[annotations] {$itg = $interface_decl.returnPair;}
232 | forward_decl
233 ;
234
235 interface_decl [Vector<Annotation> annotations] returns [Pair<Interface, TemplateGroup> returnPair = null]
236 @init {
237 Token tk = null;
238 Interface interfaceObject = null;
239 TemplateGroup interfaceTemplates = null;
240 TemplateGroup tg = null;
241 String name = null, old_scope = ctx.getScope();
242 }
243 : ( ( KW_ABSTRACT | KW_LOCAL )? ( KW_INTERFACE | KW_SERVICE )
244 {
245 tk = _input.LT(1);
246 }
247 identifier
248 {
249 name=$identifier.id;
250 // Create the Interface object.
251 interfaceObject = ctx.createInterface(name, tk);
252
253 // Add annotations.
254 for(Annotation annotation : annotations)
255 interfaceObject.addAnnotation(ctx, annotation);
256
257 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
258 {
259 if(tmanager != null) {
260 interfaceTemplates = tmanager.createTemplateGroup("interface");
261 interfaceTemplates.setAttribute("ctx", ctx);
262 // Set the the interface object to the TemplateGroup of the module.
263 interfaceTemplates.setAttribute("interface", interfaceObject);
264 }
265 }
266
267 // Update to a new namespace.
268 if(old_scope.isEmpty())
269 ctx.setScope(name);
270 else
271 ctx.setScope(old_scope + "::" + name);
272 }
273 ( interface_inheritance_spec[interfaceObject] )?
274 LEFT_BRACE interface_body[interfaceObject]{ tg=$interface_body.elTemplates; if(interfaceTemplates!=null && tg!=null)interfaceTemplates.setAttribute("export_list", tg);} RIGHT_BRACE )
275 {
276 // Set the old namespace.
277 ctx.setScope(old_scope);
278 // Create the returned data.
279 $returnPair = new Pair<Interface, TemplateGroup>(interfaceObject, interfaceTemplates);
280 }
281 ;
282
283 forward_decl
284 : ( KW_ABSTRACT | KW_LOCAL )? ( KW_INTERFACE | KW_SERVICE ) ID
285 ;
286
287
288 /*!
289 * @brief This grammar expression catches a list of exports.
290 * @param dc An object that inherits from ExportContainer. This object could store all exports.
291 * @return This grammar expression returns the template group with all template groups of exports.
292 */
293 interface_body [ExportContainer ec] returns [TemplateGroup elTemplates]
294 @init{
295 Pair<Vector<Export>, TemplateGroup> etg = null;
296 if(tmanager != null) {
297 $elTemplates = tmanager.createTemplateGroup("export_list");
298 }
299 }
300 : (
301 export[null]
302 {
303 etg=$export.etg;
304 if(etg!=null)
305 {
306 for(int count = 0; count < etg.first().size(); ++count)
307 {
308 ec.add(etg.first().get(count));
309 etg.first().get(count).resolve(ctx);
310 }
311 if($elTemplates != null && etg.second() != null)
312 {
313 // Add parent
314 etg.second().setAttribute("parent", ec);
315 // Print template into exports rule
316 $elTemplates.setAttribute("exports", etg.second());
317 }
318 }
319 }
320 )*
321 ;
322
323 /*!
324 * @brief This grammar element represents an export of a interface: type declaration, operation, etc...
325 * @return A pair with the object that represents the export (interface for other objects like operation grammar element)
326 * and the template group generated by the export (in fact the template group generated by the element who inherits).
327 */
328 export [Vector<Annotation> annotations] returns [Pair<Vector<Export>, TemplateGroup> etg = null]
329 @init {
330 // TODO Cambiar esto. No me gusta la forma.
331 Vector<Export> vector = new Vector<Export>();
332 Pair<Vector<TypeDeclaration>, TemplateGroup> tetg = null;
333 Pair<ConstDeclaration, TemplateGroup> cetg = null;
334 Pair<Operation, TemplateGroup> oetg = null;
335 Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup> eetg = null;
336
337 if(annotations == null) annotations = new Vector<Annotation>();
338 }
339 : type_decl[annotations] SEMICOLON { tetg=$type_decl.returnPair; if(tetg!=null){ for(TypeDeclaration tydl : tetg.first()) vector.add(tydl); $etg = new Pair<Vector<Export>, TemplateGroup>(vector, tetg.second());} } // Type Declaration
340 | const_decl SEMICOLON { cetg=$const_decl.returnPair; if(cetg!=null){ vector.add(cetg.first()); $etg = new Pair<Vector<Export>, TemplateGroup>(vector, cetg.second());}} // Const Declaration
341 | except_decl SEMICOLON { eetg=$except_decl.returnPair; if(eetg!=null){ vector.add(eetg.first()); $etg = new Pair<Vector<Export>, TemplateGroup>(vector, eetg.second());}} // Exception
342 | attr_decl SEMICOLON
343 { System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Attribute declarations are not supported. Ignoring..."); }
344 | op_decl[annotations] SEMICOLON { oetg=$op_decl.returnPair; if(oetg!=null){ vector.add(oetg.first()); $etg = new Pair<Vector<Export>, TemplateGroup>(vector, oetg.second());}} // Operation
345 | type_id_decl SEMICOLON
346 | type_prefix_decl SEMICOLON
347 | annotation_appl
348 {
349 annotations.add($annotation_appl.annotation);
350 }
351 aux_export[annotations]{$etg=$aux_export.etg;}
352 ;
353
354 aux_export [Vector<Annotation> annotations] returns [Pair<Vector<Export>, TemplateGroup> etg = null]
355 : export {$etg=$export.etg;}
356 ;
357
358 interface_inheritance_spec [Interface interfaceObject]
359 @init{
360 Vector<Pair<String, Token>> iflist = null;
361 }
362 : COLON scoped_name_list { iflist=$scoped_name_list.retlist; }
363 {
364 for(Pair<String, Token> pair : iflist)
365 {
366 Interface base = ctx.getInterface(pair.first());
367
368 if(base != null)
369 {
370 if(!$interfaceObject.addBase(base))
371 throw new ParseException(pair.second(), " is duplicated.");
372 }
373 else
374 {
375 throw new ParseException(pair.second(), "was not defined previously");
376 }
377 }
378 }
379 ;
380
381 interface_name
382 : scoped_name
383 ;
384
385 scoped_name_list returns [Vector<Pair<String, Token>> retlist = null]
386 @init{
387 $retlist = new Vector<Pair<String, Token>>();
388 Pair<String, Token> pair = null;
389 }
390 : scoped_name{ pair=$scoped_name.pair; $retlist.add(pair);} (COMA scoped_name{ pair=$scoped_name.pair; $retlist.add(pair);})*
391 ;
392
393 scoped_name returns [Pair<String, Token> pair = null]
394 @init{
395 String literalStr = "";
396 Token tk = _input.LT(1);
397 }
398 : ( {literalStr += _input.LT(1).getText();} DOUBLE_COLON )?
399 {literalStr += _input.LT(1).getText();} ID /* identifier */
400 ( {literalStr += _input.LT(1).getText();} DOUBLE_COLON identifier { literalStr+=$identifier.id; } )*
401 {$pair = new Pair<String, Token>(literalStr, tk);}
402 ;
403
404 value
405 @init{
406 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): ValueType declarations are not supported. Ignoring...");
407 }
408 : ( value_decl | value_abs_decl | value_box_decl | value_forward_decl )
409 ;
410
411 value_forward_decl
412 : ( KW_ABSTRACT )? KW_VALUETYPE ID
413 ;
414
415 value_box_decl
416 : KW_VALUETYPE ID type_spec
417 ;
418
419 value_abs_decl
420 : KW_ABSTRACT KW_VALUETYPE ID value_inheritance_spec LEFT_BRACE export[null]* RIGHT_BRACE
421 ;
422
423 value_decl
424 : value_header LEFT_BRACE value_element* RIGHT_BRACE
425 ;
426
427 value_header
428 : ( KW_CUSTOM )? KW_VALUETYPE ID value_inheritance_spec
429 ;
430
431 value_inheritance_spec
432 : ( COLON ( KW_TRUNCATABLE )? value_name ( COMA value_name )* )? ( KW_SUPPORTS interface_name ( COMA interface_name )* )?
433 ;
434
435 value_name
436 : scoped_name
437 ;
438
439 value_element
440 : ( export[null] | state_member | init_decl )
441 ;
442
443 state_member
444 : ( KW_PUBLIC | KW_PRIVATE ) type_spec declarators SEMICOLON
445 ;
446
447 init_decl
448 : KW_FACTORY ID LEFT_BRACKET ( init_param_decls )? RIGHT_BRACKET ( raises_expr )? SEMICOLON
449 ;
450
451 init_param_decls
452 : init_param_decl ( COMA init_param_decl )*
453 ;
454
455 init_param_decl
456 : init_param_attribute param_type_spec simple_declarator
457 ;
458
459 init_param_attribute
460 : KW_IN
461 ;
462
463 const_decl returns [Pair<ConstDeclaration, TemplateGroup> returnPair = null]
464 @init {
465 ConstDeclaration constDecl = null;
466 TypeCode typecode = null;
467 String constName = null, constValue = null;
468 TemplateGroup constTemplates = null;
469 if(tmanager != null) {
470 constTemplates = tmanager.createTemplateGroup("const_decl");
471 }
472 Token tk = null;
473 }
474 : KW_CONST const_type { typecode=$const_type.typecode; tk = _input.LT(1);} identifier { constName=$identifier.id; } EQUAL const_exp { constValue=$const_exp.literalStr; }
475 {
476 if(typecode != null)
477 {
478 constDecl = new ConstDeclaration(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), constName, typecode, constValue, tk);
479
480 if(constTemplates != null)
481 {
482 constTemplates.setAttribute("ctx", ctx);
483 constTemplates.setAttribute("const", constDecl);
484 }
485
486 $returnPair = new Pair<ConstDeclaration, TemplateGroup>(constDecl, constTemplates);
487 }
488 }
489 ;
490
491 // TODO Not supported fixed types: Show warning
492 const_type returns [TypeCode typecode = null]
493 @init{
494 Pair<String, Token> pair = null;
495 }
496 : integer_type { $typecode = $integer_type.typecode; }
497 | char_type { $typecode = $char_type.typecode; }
498 | wide_char_type { $typecode = $wide_char_type.typecode; }
499 | boolean_type { $typecode = $boolean_type.typecode; }
500 | floating_pt_type { $typecode = $floating_pt_type.typecode; }
501 | string_type { $typecode = $string_type.typecode; }
502 | wide_string_type { $typecode = $wide_string_type.typecode; }
503 | fixed_pt_const_type
504 | scoped_name
505 {
506 pair = $scoped_name.pair;
507 // Find typecode in the global map.
508 $typecode = ctx.getTypeCode(pair.first());
509
510 if($typecode == null)
511 throw new ParseException(pair.second(), "was not defined previously");
512 }
513 | octet_type { $typecode = $octet_type.typecode; }
514 ;
515
516 /* EXPRESSIONS */
517
518 const_exp returns [String literalStr = null]
519 @init{
520 String aux = null;
521 }
522 : or_expr { $literalStr = $or_expr.literalStr; }
523 ;
524
525 or_expr returns [String literalStr = null]
526 @init{
527 String aux = null;
528 }
529 : xor_expr { $literalStr = $xor_expr.literalStr; }
530 (
531 {$literalStr += _input.LT(1).getText();}
532 PIPE
533 xor_expr
534 { aux=$xor_expr.literalStr; $literalStr += aux;}
535 )*
536 ;
537
538 xor_expr returns [String literalStr = null]
539 @init{
540 String aux = null;
541 }
542 : and_expr { $literalStr = $and_expr.literalStr; }
543 (
544 {$literalStr += _input.LT(1).getText();}
545 CARET
546 and_expr
547 { aux=$and_expr.literalStr; $literalStr += aux;}
548 )*
549 ;
550
551 and_expr returns [String literalStr = null]
552 @init{
553 String aux = null;
554 }
555 : shift_expr { $literalStr = $shift_expr.literalStr; }
556 (
557 {$literalStr += _input.LT(1).getText();}
558 AMPERSAND
559 shift_expr
560 { aux=$shift_expr.literalStr; $literalStr += aux;}
561 )*
562 ;
563
564 shift_expr returns [String literalStr = null]
565 @init{
566 String aux = null;
567 }
568 : add_expr { $literalStr = $add_expr.literalStr; }
569 (
570 {$literalStr += _input.LT(1).getText();}
571 ( RIGHT_SHIFT | LEFT_SHIFT )
572 add_expr
573 { aux=$add_expr.literalStr; $literalStr += aux;}
574 )*
575 ;
576
577 add_expr returns [String literalStr = null]
578 @init{
579 String aux = null;
580 }
581 : mult_expr { $literalStr = $mult_expr.literalStr; }
582 (
583 {$literalStr += _input.LT(1).getText();}
584 ( PLUS | MINUS )
585 mult_expr
586 { aux=$mult_expr.literalStr; $literalStr += aux;}
587 )*
588 ;
589
590 mult_expr returns [String literalStr = null]
591 @init{
592 String aux = null;
593 }
594 : unary_expr { $literalStr = $unary_expr.literalStr; }
595 (
596 {$literalStr += _input.LT(1).getText();}
597 ( '*' | SLASH | PERCENT )
598 unary_expr
599 { aux=$unary_expr.literalStr; $literalStr += aux;}
600 )*
601 ;
602
603 unary_expr returns [String literalStr = null]
604 @init{
605 String aux = null;
606 }
607 :
608 {$literalStr = _input.LT(1).getText();}
609 ( MINUS | PLUS | TILDE )
610 primary_expr
611 { aux=$primary_expr.literalStr; $literalStr += aux;}
612 | primary_expr { $literalStr = $primary_expr.literalStr; }
613 ;
614
615 //unary_operator
616 // : ( MINUS | PLUS | TILDE )
617 // ;
618
619 primary_expr returns [String literalStr = null]
620 @init{
621 String aux = null;
622 }
623 : scoped_name { $literalStr = $scoped_name.pair.first(); }
624 | literal { $literalStr = $literal.pair.first(); }
625 | {$literalStr = _input.LT(1).getText();}
626 LEFT_BRACKET
627 const_exp
628 { aux=$const_exp.literalStr; $literalStr += aux; $literalStr += _input.LT(1).getText();}
629 RIGHT_BRACKET
630 ;
631
632 literal returns [Pair<String, Token> pair = null]
633 @init{
634 Token tk = _input.LT(1);
635 String literalStr = tk.getText();
636 }
637 : ( HEX_LITERAL
638 | INTEGER_LITERAL
639 | STRING_LITERAL
640 | WIDE_STRING_LITERAL
641 | CHARACTER_LITERAL
642 | WIDE_CHARACTER_LITERAL
643 | FIXED_PT_LITERAL
644 | FLOATING_PT_LITERAL
645 | boolean_literal {literalStr = $boolean_literal.literalStr;} )
646 {$pair = new Pair<String, Token>(literalStr, tk);}
647 ;
648
649 boolean_literal returns [String literalStr = null]
650 : 'TRUE'{ $literalStr = "true";}
651 | 'FALSE'{ $literalStr = "false";}
652 ;
653
654 positive_int_const returns [String literalStr = null]
655 : const_exp { $literalStr = $const_exp.literalStr; }
656 {
657 // TODO Calcular expresion
658 /*try {
659 int value = Integer.parseInt($literalStr);
660
661 if(value < 0)
662 throw new ParseException($literalStr, "expression is not supported. You must use a positive integer.");
663 } catch(NumberFormatException e) {
664 }*/
665 }
666 ;
667
668 type_decl [Vector<Annotation> annotations] returns [Pair<Vector<TypeDeclaration>, TemplateGroup> returnPair = null]
669 @init {
670 Pair<Vector<TypeCode>, TemplateGroup> ttg = null;
671 Vector<TypeDeclaration> vector = null;
672 Token tk = null;
673 }
674 : ( KW_TYPEDEF {tk = _input.LT(1);} type_declarator { ttg=$type_declarator.returnPair; }
675 | struct_type { ttg=$struct_type.returnPair; }
676 | union_type { ttg=$union_type.returnPair; }
677 | enum_type { ttg=$enum_type.returnPair; }
678 | KW_NATIVE { System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Native declarations are not supported. Ignoring..."); } simple_declarator
679 | constr_forward_decl )
680 {
681 if(ttg!=null)
682 {
683 vector = new Vector<TypeDeclaration>();
684
685 for(int count = 0; count < ttg.first().size(); ++count)
686 {
687 String name = null;
688 if(ttg.first().get(count) instanceof MemberedTypeCode)
689 name = ((MemberedTypeCode)ttg.first().get(count)).getName();
690 else if(ttg.first().get(count) instanceof AliasTypeCode)
691 name = ((AliasTypeCode)ttg.first().get(count)).getName();
692
693 TypeDeclaration typedeclaration = new TypeDeclaration(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), name, ttg.first().get(count), tk);
694
695 // Add annotations
696 for(Annotation annotation : annotations)
697 typedeclaration.addAnnotation(ctx, annotation);
698
699 // Add type declaration to the map with all typedeclarations.
700 ctx.addTypeDeclaration(typedeclaration);
701
702 vector.add(typedeclaration);
703
704 $returnPair = new Pair<Vector<TypeDeclaration>, TemplateGroup>(vector, ttg.second());
705 }
706 }
707 }
708 ;
709
710 type_declarator returns [Pair<Vector<TypeCode>, TemplateGroup> returnPair = null]
711 @init {
712 Vector<TypeCode> vector = null;
713 AliasTypeCode typedefTypecode = null;
714 TemplateGroup typedefTemplates = null;
715 if(tmanager != null) {
716 typedefTemplates = tmanager.createTemplateGroup("typedef_decl");
717 }
718 }
719 : type_spec declarators
720 {
721 if($type_spec.typecode != null)
722 {
723 vector = new Vector<TypeCode>();
724
725 for(int count = 0; count < $declarators.ret.size(); ++count)
726 {
727 typedefTypecode = new AliasTypeCode(ctx.getScope(), $declarators.ret.get(count).first().first());
728
729 if($declarators.ret.get(count).second() != null)
730 {
731 // Array declaration
732 $declarators.ret.get(count).second().setContentTypeCode($type_spec.typecode);
733 typedefTypecode.setContentTypeCode($declarators.ret.get(count).second());
734 }
735 else
736 {
737 // Simple declaration
738 typedefTypecode.setContentTypeCode($type_spec.typecode);
739 }
740
741 if(typedefTemplates != null) {
742 typedefTemplates.setAttribute("typedefs", typedefTypecode);
743 }
744
745 vector.add(typedefTypecode);
746 }
747
748 if(typedefTemplates != null) {
749 typedefTemplates.setAttribute("ctx", ctx);
750 }
751
752 $returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, typedefTemplates);
753 }
754 }
755 ;
756
757 type_spec returns [TypeCode typecode = null]
758 : simple_type_spec { $typecode=$simple_type_spec.typecode; }
759 | constr_type_spec
760 ;
761
762 simple_type_spec returns [TypeCode typecode = null]
763 @init {
764 Pair<String, Token> pair = null;
765 }
766 : base_type_spec { $typecode=$base_type_spec.typecode; }
767 | template_type_spec { $typecode=$template_type_spec.typecode; }
768 | scoped_name
769 {
770 pair=$scoped_name.pair;
771
772 // Find typecode in the global map.
773 $typecode = ctx.getTypeCode(pair.first());
774
775 if($typecode == null)
776 throw new ParseException(pair.second(), "was not supported previously");
777 }
778 ;
779
780 base_type_spec returns [TypeCode typecode = null]
781 : floating_pt_type { $typecode=$floating_pt_type.typecode; }
782 | integer_type { $typecode=$integer_type.typecode; }
783 | char_type { $typecode=$char_type.typecode; }
784 | wide_char_type { $typecode=$wide_char_type.typecode; }
785 | boolean_type { $typecode=$boolean_type.typecode; }
786 | octet_type { $typecode=$octet_type.typecode; }
787 | any_type
788 | object_type
789 | value_base_type
790 ;
791
792 template_type_spec returns [TypeCode typecode = null]
793 : sequence_type { $typecode=$sequence_type.typecode; }
794 | set_type { $typecode=$set_type.typecode; }
795 | map_type { $typecode=$map_type.typecode; }
796 | string_type { $typecode=$string_type.typecode; }
797 | wide_string_type { $typecode=$wide_string_type.typecode; }
798 | fixed_pt_type
799 ;
800
801 constr_type_spec
802 : struct_type
803 | union_type
804 | enum_type
805 ;
806
807 declarators returns [Vector<Pair<Pair<String, Token>, ContainerTypeCode>> ret = new Vector<Pair<Pair<String, Token>, ContainerTypeCode>>()]
808 : declarator
809 {
810 if($declarator.ret != null)
811 $ret.add($declarator.ret);
812 else
813 throw new ParseException(null, "Cannot parse type declarator");
814 }
815 ( COMA declarator
816 {
817 if($declarator.ret != null)
818 $ret.add($declarator.ret);
819 else
820 throw new ParseException(null, "Cannot parse type declarator");
821 }
822 )*
823 ;
824
825 declarator returns [Pair<Pair<String, Token>, ContainerTypeCode> ret = null]
826 : simple_declarator { $ret=$simple_declarator.ret; }
827 | complex_declarator { $ret=$complex_declarator.ret; }
828 ;
829
830 simple_declarator returns [Pair<Pair<String, Token>, ContainerTypeCode> ret = null]
831 @init
832 {
833 Token tk = _input.LT(1);
834 }
835 : identifier
836 {
837 Pair<String, Token> p = new Pair<String, Token>($identifier.id, tk);
838 $ret = new Pair<Pair<String, Token>, ContainerTypeCode>(p, null);
839 }
840 ;
841
842 complex_declarator returns [Pair<Pair<String, Token>, ContainerTypeCode> ret = null]
843 : array_declarator { $ret=$array_declarator.pair; }
844 ;
845
846 floating_pt_type returns [TypeCode typecode = null]
847 : ( KW_FLOAT { $typecode = new PrimitiveTypeCode(Kind.KIND_FLOAT);}
848 | KW_DOUBLE { $typecode = new PrimitiveTypeCode(Kind.KIND_DOUBLE);}
849 | KW_LONG KW_DOUBLE { $typecode = new PrimitiveTypeCode(Kind.KIND_LONGDOUBLE);}
850 | KW_FLOAT32 { $typecode = new PrimitiveTypeCode(Kind.KIND_FLOAT);}
851 | KW_FLOAT64 { $typecode = new PrimitiveTypeCode(Kind.KIND_FLOAT);}
852 | KW_FLOAT128 { $typecode = new PrimitiveTypeCode(Kind.KIND_FLOAT);}
853 )
854 ;
855
856 integer_type returns [TypeCode typecode = null]
857 : signed_int { $typecode = $signed_int.typecode; }
858 | unsigned_int { $typecode = $unsigned_int.typecode; }
859 ;
860
861 signed_int returns [TypeCode typecode = null]
862 : signed_short_int { $typecode = $signed_short_int.typecode; }
863 | signed_long_int { $typecode = $signed_long_int.typecode; }
864 | signed_longlong_int { $typecode = $signed_longlong_int.typecode; }
865 ;
866
867 signed_short_int returns [TypeCode typecode]
868 @init{
869 $typecode = new PrimitiveTypeCode(Kind.KIND_SHORT);
870 }
871 : KW_SHORT | KW_I16
872 ;
873
874 signed_long_int returns [TypeCode typecode]
875 @init{
876 $typecode = new PrimitiveTypeCode(Kind.KIND_LONG);
877 }
878 : KW_LONG | KW_I32
879 ;
880
881 signed_longlong_int returns [TypeCode typecode]
882 @init{
883 $typecode = new PrimitiveTypeCode(Kind.KIND_LONGLONG);
884 }
885 : KW_LONG KW_LONG | KW_I64
886 ;
887
888 unsigned_int returns [TypeCode typecode = null]
889 : unsigned_short_int { $typecode = $unsigned_short_int.typecode; }
890 | unsigned_long_int { $typecode = $unsigned_long_int.typecode; }
891 | unsigned_longlong_int { $typecode = $unsigned_longlong_int.typecode; }
892 ;
893
894 unsigned_short_int returns [TypeCode typecode]
895 @init{
896 $typecode = new PrimitiveTypeCode(Kind.KIND_USHORT);
897 }
898 : KW_UNSIGNED KW_SHORT | KW_U16
899 ;
900
901 unsigned_long_int returns [TypeCode typecode]
902 @init{
903 $typecode = new PrimitiveTypeCode(Kind.KIND_ULONG);
904 }
905 : KW_UNSIGNED KW_LONG | KW_U32
906 ;
907
908 unsigned_longlong_int returns [TypeCode typecode]
909 @init{
910 $typecode = new PrimitiveTypeCode(Kind.KIND_ULONGLONG);
911 }
912 : KW_UNSIGNED KW_LONG KW_LONG | KW_U64
913 ;
914
915 char_type returns [TypeCode typecode]
916 @init{
917 $typecode = new PrimitiveTypeCode(Kind.KIND_CHAR);
918 }
919 : KW_CHAR
920 ;
921
922 wide_char_type returns [TypeCode typecode]
923 @init{
924 $typecode = new PrimitiveTypeCode(Kind.KIND_WCHAR);
925 }
926 : KW_WCHAR
927 ;
928
929 boolean_type returns [TypeCode typecode]
930 @init{
931 $typecode = new PrimitiveTypeCode(Kind.KIND_BOOLEAN);
932 }
933 : KW_BOOLEAN
934 ;
935
936 octet_type returns [TypeCode typecode]
937 @init{
938 $typecode = new PrimitiveTypeCode(Kind.KIND_OCTET);
939 }
940 : KW_OCTET | KW_BYTE
941 ;
942
943 any_type
944 @init{
945 Token tk = _input.LT(1);
946 }
947 : KW_ANY
948 {throw new ParseException(tk, ". Any type is not supported"); }
949 ;
950
951 object_type
952 @init{
953 Token tk = _input.LT(1);
954 }
955 : KW_OBJECT
956 {throw new ParseException(tk, ". Object type is not supported"); }
957 ;
958
959 annotation_decl returns [Pair<AnnotationDeclaration, TemplateGroup> returnPair = null]
960 :
961 annotation_def { $returnPair=$annotation_def.returnPair; }
962 | annotation_forward_dcl
963 ;
964
965 annotation_def returns [Pair<AnnotationDeclaration, TemplateGroup> returnPair = null]
966 @init
967 {
968 TemplateGroup annotationTemplates = null;
969 }
970 : annotation_header LEFT_BRACE annotation_body[$annotation_header.annotation] RIGHT_BRACE
971 {
972 if($annotation_header.annotation != null)
973 {
974 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
975 {
976 if(tmanager != null)
977 {
978 annotationTemplates = tmanager.createTemplateGroup("annotation");
979 annotationTemplates.setAttribute("ctx", ctx);
980 // Set the annotation object to the TemplateGroup of the annotation.
981 annotationTemplates.setAttribute("annotation", $annotation_header.annotation);
982 }
983 }
984
985 $returnPair = new Pair<AnnotationDeclaration, TemplateGroup>($annotation_header.annotation, annotationTemplates);
986 }
987 }
988 ;
989
990 annotation_header returns [AnnotationDeclaration annotation = null]
991 @init
992 {
993 Token tk = null;
994 }
995 : KW_AT_ANNOTATION
996 {
997 tk = _input.LT(1);
998 }
999 identifier { $annotation = ctx.createAnnotationDeclaration($identifier.id, tk); }
1000 ( annotation_inheritance_spec[$annotation] )?
1001 ;
1002
1003 annotation_inheritance_spec [AnnotationDeclaration annotation]
1004 @init
1005 {
1006 AnnotationDeclaration inhanno = null;
1007 }
1008 :
1009 COLON scoped_name
1010 {
1011 if(annotation != null)
1012 {
1013 inhanno = ctx.getAnnotationDeclaration($scoped_name.pair.first());
1014
1015 if(inhanno != null)
1016 {
1017 annotation.addMembers(inhanno);
1018 }
1019 else
1020 throw new ParseException($scoped_name.pair.second(), "was not defined previously");
1021 }
1022 }
1023 ;
1024
1025 annotation_body [AnnotationDeclaration annotation]
1026 :
1027 ( annotation_member[annotation] )*
1028 ;
1029
1030 annotation_member [AnnotationDeclaration annotation]
1031 @init
1032 {
1033 String literalStr = null;
1034 }
1035 :
1036 const_type simple_declarator ( KW_DEFAULT const_exp { literalStr=$const_exp.literalStr; } )? SEMICOLON
1037 {
1038 if(!$annotation.addMember(new AnnotationMember($simple_declarator.ret.first().first(), $const_type.typecode, literalStr)))
1039 {
1040 throw new ParseException($simple_declarator.ret.first().second(), "was defined previously");
1041 }
1042 }
1043 ;
1044
1045 annotation_forward_dcl
1046 :
1047 KW_AT_ANNOTATION scoped_name
1048 ;
1049
1050 struct_type returns [Pair<Vector<TypeCode>, TemplateGroup> returnPair = null]
1051 @init{
1052 String name = null;
1053 Vector<TypeCode> vector = null;
1054 StructTypeCode structTP = null;
1055 TemplateGroup structTemplates = null;
1056 }
1057 : KW_STRUCT
1058 identifier
1059 {
1060 name=$identifier.id;
1061 structTP = ctx.createStructTypeCode(name);
1062 }
1063 LEFT_BRACE member_list[structTP] RIGHT_BRACE
1064 {
1065 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
1066 {
1067 if(tmanager != null) {
1068 structTemplates = tmanager.createTemplateGroup("struct_type");
1069 structTemplates.setAttribute("ctx", ctx);
1070 structTemplates.setAttribute("struct", structTP);
1071 }
1072 }
1073 // Return the returned data.
1074 vector = new Vector<TypeCode>();
1075 vector.add(structTP);
1076 $returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, structTemplates);
1077 }
1078 ;
1079
1080 member_list [StructTypeCode structTP]
1081 : (
1082 member_def
1083 {
1084 if($member_def.ret != null)
1085 {
1086 for(Pair<Pair<String, Token>, Member> pair : $member_def.ret)
1087 {
1088 if(!$structTP.addMember(pair.second()))
1089 throw new ParseException(pair.first().second(), "was defined previously");
1090 }
1091 }
1092 }
1093 )+
1094 ;
1095
1096 member_def returns [Vector<Pair<Pair<String, Token>, Member>> ret = null]
1097 : member { $ret=$member.ret; }
1098 | annotation_appl defret=member_def
1099 {
1100 if($defret.ret != null)
1101 {
1102 $ret=$defret.ret;
1103
1104 for(Pair<Pair<String, Token>, Member> pair : $ret)
1105 {
1106 if(pair.second() != null)
1107 pair.second().addAnnotation(ctx, $annotation_appl.annotation);
1108 }
1109 }
1110 }
1111 ;
1112
1113 member returns [Vector<Pair<Pair<String, Token>, Member>> ret = new Vector<Pair<Pair<String, Token>, Member>>()]
1114 : type_spec declarators SEMICOLON
1115 {
1116 if($type_spec.typecode!=null)
1117 {
1118 for(int count = 0; count < $declarators.ret.size(); ++count)
1119 {
1120 Member member = null;
1121
1122 if($declarators.ret.get(count).second() != null)
1123 {
1124 // Array declaration
1125 $declarators.ret.get(count).second().setContentTypeCode($type_spec.typecode);
1126 member = new Member($declarators.ret.get(count).second(), $declarators.ret.get(count).first().first());
1127
1128 }
1129 else
1130 {
1131 // Simple declaration
1132 member = new Member($type_spec.typecode, $declarators.ret.get(count).first().first());
1133 }
1134
1135 $ret.add(new Pair<Pair<String, Token>, Member>($declarators.ret.get(count).first(), member));
1136 }
1137 }
1138 }
1139 ;
1140
1141 union_type returns [Pair<Vector<TypeCode>, TemplateGroup> returnPair = null]
1142 @init {
1143 System.out.println("Entrando a union_type");
1144 String name = null;
1145 int line = 0;
1146 TypeCode dist_type = null;
1147 Vector<TypeCode> vector = null;
1148 UnionTypeCode unionTP = null;
1149 TemplateGroup unionTemplates = null;
1150 }
1151 : KW_UNION
1152 identifier { name=$identifier.id; System.out.println("\tidentifier: " + name);}
1153 KW_SWITCH LEFT_BRACKET switch_type_spec { dist_type=$switch_type_spec.typecode; } RIGHT_BRACKET
1154 {
1155 // TODO Check supported types for discriminator: long, enumeration, etc...
1156 unionTP = new UnionTypeCode(ctx.getScope(), name, dist_type);
1157 line = _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1;
1158 }
1159 LEFT_BRACE switch_body[unionTP] RIGHT_BRACE
1160 {
1161 // Calculate default label.
1162 TemplateUtil.setUnionDefaultLabel(unionTP, ctx.getScopeFile(), line);
1163
1164 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
1165 {
1166 if(tmanager != null) {
1167 unionTemplates = tmanager.createTemplateGroup("union_type");
1168 unionTemplates.setAttribute("ctx", ctx);
1169 unionTemplates.setAttribute("union", unionTP);
1170 }
1171 }
1172
1173 // Return the returned data.
1174 vector = new Vector<TypeCode>();
1175 vector.add(unionTP);
1176 $returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, unionTemplates);
1177 }
1178 ;
1179
1180 switch_type_spec returns [TypeCode typecode = null]
1181 @init {
1182 Pair<String, Token> pair = null;
1183 }
1184 : integer_type { $typecode=$integer_type.typecode; }
1185 | char_type { $typecode=$char_type.typecode; }
1186 | boolean_type { $typecode=$boolean_type.typecode; }
1187 | enum_type
1188 | scoped_name
1189 {
1190 pair=$scoped_name.pair;
1191 // Find typecode in the global map.
1192 $typecode = ctx.getTypeCode(pair.first());
1193
1194 if($typecode == null)
1195 throw new ParseException(pair.second(), "was not defined previously");
1196 }
1197 ;
1198
1199 switch_body [UnionTypeCode unionTP]
1200 @init {
1201 System.out.println("Entrando a switch_body");
1202 }
1203 : case_stmt_list[unionTP]
1204 ;
1205
1206 case_stmt_list [UnionTypeCode unionTP]
1207 @init {
1208 System.out.println("Entrando a case_stmt_list");
1209 }
1210 : (case_stmt[unionTP])+
1211 ;
1212
1213 case_stmt [UnionTypeCode unionTP]
1214 @init
1215 {
1216 List<String> labels = new ArrayList<String>();
1217 boolean defaul = false;
1218 }
1219 : ( KW_CASE const_exp
1220 {
1221 labels.add(TemplateUtil.checkUnionLabel(unionTP.getDiscriminator().getTypecode(), $const_exp.literalStr, ctx.getScopeFile(), _input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : 1));
1222 } COLON
1223 | KW_DEFAULT { defaul = true; } COLON
1224 )+
1225 element_spec[labels, defaul] SEMICOLON
1226 {
1227 if($element_spec.ret != null)
1228 {
1229 int ret = unionTP.addMember($element_spec.ret.second());
1230
1231 if(ret == -1)
1232 throw new ParseException($element_spec.ret.first().second(), " is already defined.");
1233 else if(ret == -2)
1234 throw new ParseException($element_spec.ret.first().second(), " is also a default attribute. Another was defined previously.");
1235 }
1236 }
1237 ;
1238
1239 //case_label
1240 // : KW_CASE const_exp COLON
1241 // | KW_DEFAULT COLON
1242 // ;
1243
1244 element_spec [List<String> labels, boolean isDefault] returns [Pair<Pair<String, Token>, UnionMember> ret = null]
1245 : type_spec declarator
1246 {
1247 if($type_spec.typecode != null)
1248 {
1249 UnionMember member = null;
1250
1251 if($declarator.ret.second() != null)
1252 {
1253 $declarator.ret.second().setContentTypeCode($type_spec.typecode);
1254 member = new UnionMember($declarator.ret.second(), $declarator.ret.first().first(), labels, isDefault);
1255 }
1256 else
1257 {
1258 member = new UnionMember($type_spec.typecode, $declarator.ret.first().first(), labels, isDefault);
1259 }
1260
1261 $ret = new Pair<Pair<String, Token>, UnionMember>($declarator.ret.first(), member);
1262 }
1263 }
1264 ;
1265
1266 enum_type returns [Pair<Vector<TypeCode>, TemplateGroup> returnPair = null]
1267 @init{
1268 String name = null;
1269 Vector<TypeCode> vector = null;
1270 EnumTypeCode enumTP = null;
1271 TemplateGroup enumTemplates = null;
1272 }
1273 : KW_ENUM
1274 identifier { name=$identifier.id; enumTP = new EnumTypeCode(ctx.getScope(), name); }
1275 LEFT_BRACE enumerator_list[enumTP] RIGHT_BRACE
1276 {
1277 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
1278 {
1279 if(tmanager != null) {
1280 enumTemplates = tmanager.createTemplateGroup("enum_type");
1281 enumTemplates.setAttribute("ctx", ctx);
1282 enumTemplates.setAttribute("enum", enumTP);
1283 }
1284 }
1285 // Return the returned data.
1286 vector = new Vector<TypeCode>();
1287 vector.add(enumTP);
1288 $returnPair = new Pair<Vector<TypeCode>, TemplateGroup>(vector, enumTemplates);
1289 }
1290 ;
1291
1292 enumerator_list [EnumTypeCode enumTP]
1293 : enumerator[enumTP] (COMA enumerator[enumTP])*
1294 ;
1295
1296 enumerator [EnumTypeCode enumTP]
1297 @init{
1298 String name = null;
1299 }
1300 : identifier{ name=$identifier.id; enumTP.addMember(new EnumMember(name));}
1301 ;
1302
1303 sequence_type returns [SequenceTypeCode typecode = null]
1304 @init {
1305 TypeCode type = null;
1306 String maxsize = null;
1307 }
1308 : ( (KW_SEQUENCE | KW_LIST)
1309 LEFT_ANG_BRACKET simple_type_spec { type=$simple_type_spec.typecode; } COMA positive_int_const { maxsize=$positive_int_const.literalStr; } RIGHT_ANG_BRACKET
1310 | (KW_SEQUENCE | KW_LIST)
1311 LEFT_ANG_BRACKET simple_type_spec { type=$simple_type_spec.typecode; } RIGHT_ANG_BRACKET )
1312 {
1313 if(type != null)
1314 {
1315 $typecode = new SequenceTypeCode(maxsize);
1316 $typecode.setContentTypeCode(type);
1317 }
1318 }
1319 ;
1320
1321 set_type returns [SetTypeCode typecode = null]
1322 @init {
1323 TypeCode type = null;
1324 String maxsize = null;
1325 } : ( KW_SET
1326 LEFT_ANG_BRACKET simple_type_spec { type=$simple_type_spec.typecode; } COMA positive_int_const { maxsize=$positive_int_const.literalStr; } RIGHT_ANG_BRACKET
1327 | KW_SET
1328 LEFT_ANG_BRACKET simple_type_spec { type=$simple_type_spec.typecode; } RIGHT_ANG_BRACKET )
1329 {
1330 $typecode = new SetTypeCode(maxsize);
1331 $typecode.setContentTypeCode(type);
1332 }
1333 ;
1334
1335 map_type returns [MapTypeCode typecode = null]
1336 @init {
1337 TypeCode keyType = null;
1338 TypeCode valueType = null;
1339 String maxsize = null;
1340 } : ( KW_MAP
1341 LEFT_ANG_BRACKET simple_type_spec { keyType=$simple_type_spec.typecode; } COMA simple_type_spec { valueType=$simple_type_spec.typecode; } COMA positive_int_const { maxsize=$positive_int_const.literalStr; } RIGHT_ANG_BRACKET
1342 | KW_MAP
1343 LEFT_ANG_BRACKET simple_type_spec { keyType=$simple_type_spec.typecode; } COMA simple_type_spec { valueType=$simple_type_spec.typecode; } RIGHT_ANG_BRACKET )
1344 {
1345 $typecode = new MapTypeCode(maxsize);
1346 $typecode.setKeyTypeCode(keyType);
1347 $typecode.setValueTypeCode(valueType);
1348 }
1349 ;
1350
1351
1352 string_type returns [TypeCode typecode = null]
1353 @init{
1354 String maxsize = null;
1355 }
1356 : ( KW_STRING LEFT_ANG_BRACKET positive_int_const { maxsize=$positive_int_const.literalStr; } RIGHT_ANG_BRACKET
1357 | KW_STRING )
1358 {$typecode = new StringTypeCode(Kind.KIND_STRING, maxsize);}
1359 ;
1360
1361 wide_string_type returns [TypeCode typecode = null]
1362 @init
1363 {
1364 String maxsize = null;
1365 }
1366 : ( KW_WSTRING LEFT_ANG_BRACKET positive_int_const { maxsize=$positive_int_const.literalStr; } RIGHT_ANG_BRACKET
1367 | KW_WSTRING )
1368 {$typecode = new StringTypeCode(Kind.KIND_WSTRING, maxsize);}
1369 ;
1370
1371 array_declarator returns [Pair<Pair<String, Token>, ContainerTypeCode> pair = null]
1372 @init
1373 {
1374 Token tk = _input.LT(1);
1375 ArrayTypeCode typecode = new ArrayTypeCode();
1376 }
1377 : ID
1378 (
1379 fixed_array_size
1380 {
1381 typecode.addDimension($fixed_array_size.literalStr);
1382 }
1383 )+
1384 {
1385 Pair<String, Token> p = new Pair<String, Token>(tk.getText(), tk);
1386 $pair = new Pair<Pair<String, Token>, ContainerTypeCode>(p, typecode);
1387 }
1388 ;
1389
1390 fixed_array_size returns [String literalStr = null]
1391 : LEFT_SQUARE_BRACKET
1392 positive_int_const { $literalStr=$positive_int_const.literalStr; }
1393 RIGHT_SQUARE_BRACKET
1394 ;
1395
1396 attr_decl returns [Vector<Pair<Pair<String, Token>, TypeCode>> ret = null]
1397 : readonly_attr_spec
1398 | attr_spec { $ret=$attr_spec.ret; }
1399 ;
1400
1401 except_decl returns [Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup> returnPair = null]
1402 @init {
1403 String name = null;
1404 com.eprosima.idl.parser.tree.Exception exceptionObject = null;
1405 TemplateGroup exTemplates = null;
1406 Token tk = null;
1407 }
1408 : KW_EXCEPTION
1409 {
1410 tk = _input.LT(1);
1411 }
1412 identifier { name=$identifier.id; }
1413 {
1414 // Create the Exception object.
1415 exceptionObject = ctx.createException(name, tk);
1416
1417 if(ctx.isInScopedFile() || ctx.isScopeLimitToAll())
1418 {
1419 if(tmanager != null) {
1420 exTemplates = tmanager.createTemplateGroup("exception");
1421 exTemplates.setAttribute("ctx", ctx);
1422 // Set the the exception object to the TemplateGroup of the module.
1423 exTemplates.setAttribute("exception", exceptionObject);
1424 }
1425 }
1426 // Its a dependency.
1427 else
1428 {
1429 ctx.addIncludeDependency(ctx.getScopeFile());
1430 }
1431 }
1432 LEFT_BRACE opt_member_list[exceptionObject] RIGHT_BRACE
1433 {
1434 // Create the returned data.
1435 $returnPair = new Pair<com.eprosima.idl.parser.tree.Exception, TemplateGroup>(exceptionObject, exTemplates);
1436 }
1437 ;
1438
1439 opt_member_list [com.eprosima.idl.parser.tree.Exception exceptionObject]
1440 : (
1441 member
1442 {
1443 for(int count = 0; count < $member.ret.size(); ++count)
1444 $exceptionObject.addMember($member.ret.get(count).second());
1445 }
1446 )*
1447 ;
1448
1449 /*!
1450 * @brief This grammar expression catches a operation.
1451 * @return This grammar expression returns the operation object and its template group.
1452 */
1453 op_decl [Vector<Annotation> annotations] returns [Pair<Operation, TemplateGroup> returnPair = null]
1454 @init {
1455 Operation operationObject = null;
1456 TemplateGroup operationTemplates = null;
1457 if(tmanager != null) {
1458 operationTemplates = tmanager.createTemplateGroup("operation");
1459 }
1460 TemplateGroup tpl = null;
1461 String name = "";
1462 Token tk = null, tkoneway = null;
1463 TypeCode retType = null;
1464 Vector<Pair<String, Token>> exceptions = null;
1465 }
1466 : ( op_attribute { tkoneway=$op_attribute.token; } )?
1467 op_type_spec { retType=$op_type_spec.typecode; }
1468 {
1469 tk = _input.LT(1);
1470 name += tk.getText();
1471 }
1472 ID
1473 {
1474 // Create the Operation object.
1475 operationObject = ctx.createOperation(name, tk);
1476
1477 // Add annotations.
1478 for(Annotation annotation : annotations)
1479 operationObject.addAnnotation(ctx, annotation);
1480
1481 if(operationTemplates != null)
1482 {
1483 operationTemplates.setAttribute("ctx", ctx);
1484 // Set the the interface object to the TemplateGroup of the module.
1485 operationTemplates.setAttribute("operation", operationObject);
1486 }
1487
1488 // Set return type
1489 operationObject.setRettype(retType);
1490
1491 // Set oneway
1492 if(tkoneway != null) {
1493 operationObject.setOneway(true);
1494
1495 if(retType != null)
1496 {
1497 throw new ParseException(tkoneway, ". Oneway function cannot have a return type.");
1498 }
1499 }
1500 }
1501 parameter_decls[operationObject] { tpl=$parameter_decls.tpl; }
1502 (
1503 raises_expr { exceptions=$raises_expr.exlist; }
1504 {
1505 // Search global exceptions and add them to the operation.
1506 for(Pair<String, Token> pair : exceptions)
1507 {
1508 com.eprosima.idl.parser.tree.Exception exception = ctx.getException(pair.first());
1509
1510 if(exception != null)
1511 operationObject.addException(exception);
1512 else
1513 operationObject.addUnresolvedException(pair.first());
1514 }
1515 }
1516 )?
1517 ( context_expr )?
1518 {
1519 if(operationTemplates != null) {
1520 // Store the parameter list template group in the operation template group.
1521 operationTemplates.setAttribute("param_list", tpl);
1522 }
1523 // Create the returned data.
1524 $returnPair = new Pair<Operation, TemplateGroup>(operationObject, operationTemplates);
1525 }
1526 ;
1527
1528 op_attribute returns [Token token = null]
1529 @init {
1530 Token tk = _input.LT(1);
1531 }
1532 : KW_ONEWAY { $token = tk;}
1533 ;
1534
1535 op_type_spec returns [TypeCode typecode = null]
1536 : param_type_spec { $typecode=$param_type_spec.typecode; }
1537 | KW_VOID
1538 ;
1539
1540 parameter_decls [Operation operation] returns [TemplateGroup tpl]
1541 @init {
1542 if(tmanager != null) {
1543 $tpl = tmanager.createTemplateGroup("param_list");
1544 }
1545 }
1546 : LEFT_BRACKET (param_decl_list[operation, $tpl])? RIGHT_BRACKET
1547 ;
1548
1549 param_decl_list [Operation operation, TemplateGroup tpl]
1550 @init {
1551 Pair<Param, TemplateGroup> ptg = null;
1552 }
1553 : param_decl { ptg=$param_decl.returnPair; }
1554 {
1555 if(ptg!=null) {
1556 operation.add(ptg.first());
1557 if(tpl != null) {
1558 tpl.setAttribute("parameters", ptg.second());
1559 }
1560 }
1561 }
1562 (
1563 COMA param_decl { ptg=$param_decl.returnPair; }
1564 {
1565 if(ptg!=null) {
1566 operation.add(ptg.first());
1567 if(tpl != null) {
1568 tpl.setAttribute("parameters", ptg.second());
1569 }
1570 }
1571 }
1572 )*
1573 ;
1574
1575 param_decl returns [Pair<Param, TemplateGroup> returnPair = null]
1576 @init{
1577 TemplateGroup paramTemplate = null;
1578 if(tmanager != null) {
1579 paramTemplate = tmanager.createTemplateGroup("param");
1580 }
1581 TypeCode typecode = null;
1582 String literalStr = _input.LT(1).getText();
1583 }
1584 : ('in' | 'out' | 'inout')?
1585 param_type_spec { typecode=$param_type_spec.typecode; }
1586 simple_declarator
1587 {
1588 if(typecode != null)
1589 {
1590 Param param = null;
1591
1592 if(literalStr.equals("out") || literalStr.equals("inout")) {
1593 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " +
1594 (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") +
1595 "): The only supported parameter declaration is 'in'. Treating as 'in'...");
1596 }
1597
1598 param = ctx.createParam($simple_declarator.ret.first().first(), typecode, Param.Kind.IN_PARAM);
1599
1600 if(paramTemplate != null) {
1601 paramTemplate.setAttribute("parameter", param);
1602 }
1603 $returnPair = new Pair<Param, TemplateGroup>(param, paramTemplate);
1604 }
1605 }
1606 ;
1607
1608 //param_attribute
1609 // : KW_IN
1610 // | KW_OUT
1611 // | KW_INOUT
1612 // ;
1613
1614 raises_expr returns [Vector<Pair<String, Token>> exlist = null]
1615 : KW_RAISES LEFT_BRACKET scoped_name_list { $exlist=$scoped_name_list.retlist; } RIGHT_BRACKET
1616 ;
1617
1618 context_expr
1619 @init {
1620 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Context declarations are not supported. Ignoring...");
1621 }
1622 : KW_CONTEXT LEFT_BRACKET STRING_LITERAL ( COMA STRING_LITERAL )* RIGHT_BRACKET
1623 ;
1624
1625 param_type_spec returns [TypeCode typecode = null]
1626 @init{
1627 Pair<String, Token> pair = null;
1628 }
1629 : base_type_spec { $typecode=$base_type_spec.typecode; }
1630 | string_type { $typecode=$string_type.typecode; }
1631 | wide_string_type { $typecode=$wide_string_type.typecode; }
1632 | scoped_name
1633 {
1634 pair=$scoped_name.pair;
1635 // Find typecode in the global map.
1636 $typecode = ctx.getTypeCode(pair.first());
1637
1638 if($typecode == null)
1639 throw new ParseException(pair.second(), "was not defined previously");
1640 }
1641 ;
1642
1643 fixed_pt_type
1644 @init{
1645 Token tk = _input.LT(1);
1646 }
1647 : KW_FIXED LEFT_ANG_BRACKET positive_int_const COMA positive_int_const RIGHT_ANG_BRACKET
1648 {throw new ParseException(tk, ". Fixed type is not supported");}
1649 ;
1650
1651 fixed_pt_const_type
1652 @init{
1653 Token tk = _input.LT(1);
1654 }
1655 : KW_FIXED
1656 {throw new ParseException(tk, ". Fixed type is not supported");}
1657 ;
1658
1659 value_base_type
1660 @init{
1661 Token tk = _input.LT(1);
1662 }
1663 : KW_VALUEBASE
1664 {throw new ParseException(tk, ". Value type is not supported");}
1665 ;
1666
1667 constr_forward_decl
1668 : KW_STRUCT ID
1669 | KW_UNION ID
1670 ;
1671
1672 import_decl
1673 : KW_IMPORT
1674 {
1675 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Import declarations are not supported. Ignoring...");
1676 }
1677 imported_scope SEMICOLON
1678 ;
1679
1680 imported_scope
1681 : scoped_name | STRING_LITERAL
1682 ;
1683
1684 type_id_decl
1685 : KW_TYPEID
1686 {
1687 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): TypeID declarations are not supported. Ignoring...");
1688 }
1689 scoped_name STRING_LITERAL
1690 ;
1691
1692 type_prefix_decl
1693 : KW_TYPEPREFIX
1694 {
1695 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): TypePrefix declarations are not supported. Ignoring...");
1696 }
1697 scoped_name STRING_LITERAL
1698 ;
1699
1700 readonly_attr_spec
1701 : KW_READONLY KW_ATTRIBUTE param_type_spec readonly_attr_declarator
1702 ;
1703
1704 readonly_attr_declarator
1705 : simple_declarator raises_expr
1706 | simple_declarator ( COMA simple_declarator )*
1707 ;
1708
1709 attr_spec returns [Vector<Pair<Pair<String, Token>, TypeCode>> ret = new Vector<Pair<Pair<String, Token>, TypeCode>>()]
1710 @init {
1711 TypeCode typecode = null;
1712 }
1713 : KW_ATTRIBUTE param_type_spec { typecode=$param_type_spec.typecode; } attr_declarator
1714 {
1715 if(typecode != null)
1716 {
1717 for(int count = 0; count < $attr_declarator.ret.size(); ++count)
1718 {
1719 // attr_declarator always is a simple declarator. Not a complex (array):
1720 // Simple declaration
1721 $ret.add(new Pair<Pair<String, Token>, TypeCode>($attr_declarator.ret.get(count).first(), typecode));
1722 }
1723 }
1724 }
1725 ;
1726
1727 attr_declarator returns [Vector<Pair<Pair<String, Token>, ContainerTypeCode>> ret]
1728 @init {
1729 $ret = new Vector<Pair<Pair<String, Token>, ContainerTypeCode>>();
1730 }
1731 : simple_declarator {$ret.add($simple_declarator.ret);}
1732 ( attr_raises_expr
1733 | (COMA simple_declarator {$ret.add($simple_declarator.ret);})*
1734 )
1735 ;
1736
1737 attr_raises_expr
1738 : get_excep_expr ( set_excep_expr )?
1739 | set_excep_expr
1740 ;
1741
1742 get_excep_expr
1743 : KW_GETRAISES exception_list
1744 ;
1745
1746 set_excep_expr
1747 : KW_SETRAISES exception_list
1748 ;
1749
1750 exception_list
1751 : LEFT_BRACKET scoped_name ( COMA scoped_name )* RIGHT_BRACKET
1752 ;
1753
1754 // Component Stuff
1755
1756 component
1757 : component_decl
1758 | component_forward_decl
1759 ;
1760
1761 component_forward_decl
1762 : KW_COMPONENT
1763 {
1764 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Component declarations are not supported. Ignoring...");
1765 }
1766 ID
1767 ;
1768
1769 component_decl
1770 : component_header LEFT_BRACE component_body RIGHT_BRACE
1771 ;
1772
1773 component_header
1774 : KW_COMPONENT ID ( component_inheritance_spec )? ( supported_interface_spec )?
1775 ;
1776
1777 supported_interface_spec
1778 : KW_SUPPORTS scoped_name ( COMA scoped_name )*
1779 ;
1780
1781 component_inheritance_spec
1782 : COLON scoped_name
1783 ;
1784
1785 component_body
1786 : component_export*
1787 ;
1788
1789 component_export
1790 : provides_decl SEMICOLON
1791 | uses_decl SEMICOLON
1792 | emits_decl SEMICOLON
1793 | publishes_decl SEMICOLON
1794 | consumes_decl SEMICOLON
1795 | attr_decl SEMICOLON
1796 ;
1797
1798 provides_decl
1799 : KW_PROVIDES interface_type ID
1800 ;
1801
1802 interface_type
1803 : scoped_name
1804 | KW_OBJECT
1805 ;
1806
1807 uses_decl
1808 : KW_USES ( KW_MULTIPLE )? interface_type ID
1809 ;
1810
1811 emits_decl
1812 : KW_EMITS scoped_name ID
1813 ;
1814
1815 publishes_decl
1816 : KW_PUBLISHES scoped_name ID
1817 ;
1818
1819 consumes_decl
1820 : KW_CONSUMES scoped_name ID
1821 ;
1822
1823 home_decl
1824 @init {
1825 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Home declarations are not supported. Ignoring...");
1826 }
1827 : home_header home_body
1828 ;
1829
1830 home_header
1831 : KW_HOME ID ( home_inheritance_spec )? ( supported_interface_spec )? KW_MANAGES scoped_name ( primary_key_spec )?
1832 ;
1833
1834 home_inheritance_spec
1835 : COLON scoped_name
1836 ;
1837
1838 primary_key_spec
1839 : KW_PRIMARYKEY scoped_name
1840 ;
1841
1842 home_body
1843 : LEFT_BRACE home_export* RIGHT_BRACE
1844 ;
1845
1846 home_export
1847 : export[null]
1848 | factory_decl SEMICOLON
1849 | finder_decl SEMICOLON
1850 ;
1851
1852 factory_decl
1853 : KW_FACTORY ID LEFT_BRACKET ( init_param_decls )? RIGHT_BRACKET ( raises_expr )?
1854 ;
1855
1856 finder_decl
1857 : KW_FINDER ID LEFT_BRACKET ( init_param_decls )? RIGHT_BRACKET ( raises_expr )?
1858 ;
1859
1860 event
1861 @init{
1862 System.out.println("WARNING (File " + ctx.getFilename() + ", Line " + (_input.LT(1) != null ? _input.LT(1).getLine() - ctx.getCurrentIncludeLine() : "1") + "): Event declarations are not supported. Ignoring...");
1863 }
1864 : ( event_decl | event_abs_decl | event_forward_decl)
1865 ;
1866
1867 event_forward_decl
1868 : ( KW_ABSTRACT )? KW_EVENTTYPE ID
1869 ;
1870
1871 event_abs_decl
1872 : KW_ABSTRACT KW_EVENTTYPE ID value_inheritance_spec LEFT_BRACE export[null]* RIGHT_BRACE
1873 ;
1874
1875 event_decl
1876 : event_header LEFT_BRACE value_element* RIGHT_BRACE
1877 ;
1878
1879 event_header
1880 : ( KW_CUSTOM )? KW_EVENTTYPE ID value_inheritance_spec
1881 ;
1882
1883 annotation_appl returns [Annotation annotation = null]
1884 @init
1885 {
1886 AnnotationDeclaration anndecl = null;
1887 }
1888 :
1889 AT scoped_name
1890 {
1891 anndecl = ctx.getAnnotationDeclaration($scoped_name.pair.first());
1892 if(anndecl == null)
1893 {
1894 throw new ParseException($scoped_name.pair.second(), "was not defined previously");
1895 }
1896
1897 $annotation = new Annotation(anndecl);
1898 }
1899 ( LEFT_BRACKET ( annotation_appl_params[$annotation, $scoped_name.pair.second()] )? RIGHT_BRACKET )?
1900 ;
1901
1902 // TODO Support several members in annotations.
1903 annotation_appl_params [Annotation annotation, Token tkannot]
1904 : const_exp
1905 {
1906 if(!annotation.addValue($const_exp.literalStr))
1907 throw new ParseException(tkannot, "not has only one attribute.");
1908 }
1909 | annotation_appl_param[annotation] ( COMA annotation_appl_param[annotation] )*
1910 ;
1911
1912 annotation_appl_param [Annotation annotation]
1913 @init
1914 {
1915 Token tk = _input.LT(1);
1916 }
1917 : identifier EQUAL const_exp
1918 {
1919 if(!annotation.addValue($identifier.id, $const_exp.literalStr))
1920 throw new ParseException(tk, "is not an attribute of annotation " + annotation.getName());
1921 }
1922 ;
1923
1924 identifier returns [String id]
1925 @init {
1926 $id = _input.LT(1).getText();
1927 }
1928 : ID
1929 ;
1930
1931
1932 INTEGER_LITERAL : ('0' | '1'..'9' '0'..'9'*) INTEGER_TYPE_SUFFIX? ;
1933
1934 OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPE_SUFFIX? ;
1935
1936 HEX_LITERAL : '0' ('x' | 'X') HEX_DIGIT+ INTEGER_TYPE_SUFFIX? ;
1937
1938 fragment
1939 HEX_DIGIT : ( '0'..'9' | 'a'..'f' | 'A'..'F' ) ;
1940
1941 fragment
1942 INTEGER_TYPE_SUFFIX : ('l' | 'L') ;
1943
1944 FLOATING_PT_LITERAL
1945 : ('0'..'9')+ '.' ('0'..'9')* EXPONENT? FLOAT_TYPE_SUFFIX?
1946 | '.' ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX?
1947 | ('0'..'9')+ EXPONENT FLOAT_TYPE_SUFFIX?
1948 | ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX
1949 ;
1950
1951 FIXED_PT_LITERAL
1952 : FLOATING_PT_LITERAL
1953 ;
1954
1955 fragment
1956 EXPONENT : ('e' | 'E') (PLUS|MINUS)? ('0'..'9')+ ;
1957
1958 fragment
1959 FLOAT_TYPE_SUFFIX : ('f' | 'F' | 'd' | 'D') ;
1960
1961 WIDE_CHARACTER_LITERAL
1962 : 'L' CHARACTER_LITERAL
1963 ;
1964
1965 CHARACTER_LITERAL
1966 : '\'' ( ESCAPE_SEQUENCE | ~('\'' | '\\') ) '\''
1967 ;
1968
1969 WIDE_STRING_LITERAL
1970 : 'L' STRING_LITERAL
1971 ;
1972
1973 STRING_LITERAL
1974 : '"' ( ESCAPE_SEQUENCE | ~('\\' | '"') )* '"'
1975 ;
1976
1977 BOOLEAN_LITERAL
1978 : 'TRUE'
1979 | 'FALSE'
1980 ;
1981
1982 fragment
1983 ESCAPE_SEQUENCE
1984 : '\\' ('b' | 't' | 'n' | 'f' | 'r' | '\"' | '\'' | '\\')
1985 | UNICODE_ESCAPE
1986 | OCTAL_ESCAPE
1987 ;
1988
1989 fragment
1990 OCTAL_ESCAPE
1991 : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
1992 | '\\' ('0'..'7') ('0'..'7')
1993 | '\\' ('0'..'7')
1994 ;
1995
1996 fragment
1997 UNICODE_ESCAPE
1998 : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
1999 ;
2000
2001 fragment
2002 LETTER
2003 : '\u0024'
2004 | '\u0041'..'\u005a'
2005 | '\u005f'
2006 | '\u0061'..'\u007a'
2007 | '\u00c0'..'\u00d6'
2008 | '\u00d8'..'\u00f6'
2009 | '\u00f8'..'\u00ff'
2010 | '\u0100'..'\u1fff'
2011 | '\u3040'..'\u318f'
2012 | '\u3300'..'\u337f'
2013 | '\u3400'..'\u3d2d'
2014 | '\u4e00'..'\u9fff'
2015 | '\uf900'..'\ufaff'
2016 ;
2017
2018 fragment
2019 ID_DIGIT
2020 : '\u0030'..'\u0039'
2021 | '\u0660'..'\u0669'
2022 | '\u06f0'..'\u06f9'
2023 | '\u0966'..'\u096f'
2024 | '\u09e6'..'\u09ef'
2025 | '\u0a66'..'\u0a6f'
2026 | '\u0ae6'..'\u0aef'
2027 | '\u0b66'..'\u0b6f'
2028 | '\u0be7'..'\u0bef'
2029 | '\u0c66'..'\u0c6f'
2030 | '\u0ce6'..'\u0cef'
2031 | '\u0d66'..'\u0d6f'
2032 | '\u0e50'..'\u0e59'
2033 | '\u0ed0'..'\u0ed9'
2034 | '\u1040'..'\u1049'
2035 ;
2036
2037 SEMICOLON: ';';
2038 COLON: ':';
2039 COMA: ',';
2040 LEFT_BRACE: '{';
2041 RIGHT_BRACE: '}';
2042 LEFT_BRACKET: '(';
2043 RIGHT_BRACKET: ')';
2044 LEFT_SQUARE_BRACKET: '[';
2045 RIGHT_SQUARE_BRACKET: ']';
2046 TILDE: '~';
2047 SLASH: '/';
2048 LEFT_ANG_BRACKET: '<';
2049 RIGHT_ANG_BRACKET: '>';
2050 STAR: '*';
2051 PLUS: '+';
2052 MINUS: '-';
2053 CARET: '^';
2054 AMPERSAND: '&';
2055 PIPE: '|';
2056 EQUAL: '=';
2057 PERCENT: '%';
2058 AT: '@';
2059
2060 DOUBLE_COLON: '::';
2061 RIGHT_SHIFT: '>>';
2062 LEFT_SHIFT: '<<';
2063
2064 KW_SETRAISES: 'setraises';
2065 KW_OUT: 'out';
2066 KW_EMITS: 'emits';
2067 KW_STRING: 'string';
2068 KW_SWITCH: 'switch';
2069 KW_PUBLISHES: 'publishes';
2070 KW_TYPEDEF: 'typedef';
2071 KW_USES: 'uses';
2072 KW_PRIMARYKEY: 'primarykey';
2073 KW_CUSTOM: 'custom';
2074 KW_OCTET: 'octet';
2075 KW_SEQUENCE: 'sequence';
2076 KW_IMPORT: 'import';
2077 KW_STRUCT: 'struct';
2078 KW_NATIVE: 'native';
2079 KW_READONLY: 'readonly';
2080 KW_FINDER: 'finder';
2081 KW_RAISES: 'raises';
2082 KW_VOID: 'void';
2083 KW_PRIVATE: 'private';
2084 KW_EVENTTYPE: 'eventtype';
2085 KW_WCHAR: 'wchar';
2086 KW_IN: 'in';
2087 KW_DEFAULT: 'default';
2088 KW_PUBLIC: 'public';
2089 KW_SHORT: 'short';
2090 KW_LONG: 'long';
2091 KW_ENUM: 'enum';
2092 KW_WSTRING: 'wstring';
2093 KW_CONTEXT: 'context';
2094 KW_HOME: 'home';
2095 KW_FACTORY: 'factory';
2096 KW_EXCEPTION: 'exception';
2097 KW_GETRAISES: 'getraises';
2098 KW_CONST: 'const';
2099 KW_VALUEBASE: 'ValueBase';
2100 KW_VALUETYPE: 'valuetype';
2101 KW_SUPPORTS: 'supports';
2102 KW_MODULE: 'module';
2103 KW_OBJECT: 'Object';
2104 KW_TRUNCATABLE: 'truncatable';
2105 KW_UNSIGNED: 'unsigned';
2106 KW_FIXED: 'fixed';
2107 KW_UNION: 'union';
2108 KW_ONEWAY: 'oneway';
2109 KW_ANY: 'any';
2110 KW_CHAR: 'char';
2111 KW_CASE: 'case';
2112 KW_FLOAT: 'float';
2113 KW_BOOLEAN: 'boolean';
2114 KW_MULTIPLE: 'multiple';
2115 KW_ABSTRACT: 'abstract';
2116 KW_INOUT: 'inout';
2117 KW_PROVIDES: 'provides';
2118 KW_CONSUMES: 'consumes';
2119 KW_DOUBLE: 'double';
2120 KW_TYPEPREFIX: 'typeprefix';
2121 KW_TYPEID: 'typeid';
2122 KW_ATTRIBUTE: 'attribute';
2123 KW_LOCAL: 'local';
2124 KW_MANAGES: 'manages';
2125 KW_INTERFACE: 'interface';
2126 KW_COMPONENT: 'component';
2127 KW_NAMESPACE: 'namespace';
2128 KW_SERVICE: 'service';
2129 KW_FLOAT32: 'float32';
2130 KW_FLOAT64: 'float64';
2131 KW_FLOAT128: 'float128';
2132 KW_I16: 'i16';
2133 KW_I32: 'i32';
2134 KW_I64: 'i64';
2135 KW_U16: 'u16';
2136 KW_U32: 'u32';
2137 KW_U64: 'u64';
2138 KW_BYTE: 'byte';
2139 KW_LIST: 'list';
2140 KW_SET: 'set';
2141 KW_MAP: 'map';
2142 KW_AT_ANNOTATION: '@annotation';
2143
2144 ID
2145 : LETTER (LETTER|ID_DIGIT)*
2146 ;
2147
2148 WS
2149 : (' ' | '\r' | '\t' | '\u000C' | '\n') -> channel(HIDDEN)
2150 ;
2151
2152 PREPROC_DIRECTIVE
2153 :
2154 '#'
2155 (~'\n')* '\n'
2156 {
2157 ctx.processPreprocessorLine(new String(getText()), getLine());
2158 skip();
2159 //newline();
2160 }
2161 ;
2162
2163 COMMENT
2164 : '/*' .*? '*/' -> channel(HIDDEN)
2165 ;
2166
2167 LINE_COMMENT
2168 : '//' ~('\n' | '\r')* '\r'? '\n' -> channel(HIDDEN)
2169 ;
2170
2171 // [EOF] KIARAIDL.g