Aidl.g4 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. grammar Aidl;
  2. @members {
  3. int oneway = 0;
  4. }
  5. aidl:
  6. packageStatement? (
  7. parcelableStatement |
  8. importStatement* interfaceStatement
  9. )?;
  10. packageStatement:
  11. PACKAGE name SE;
  12. parcelableStatement:
  13. PARCELABLE id SE;
  14. importStatement:
  15. IMPORT path SE;
  16. interfaceStatement:
  17. {oneway = 0;}
  18. (ONEWAY {oneway = 1;})?
  19. INTERFACE id LC interfaceSubStatement* RC;
  20. interfaceSubStatement:
  21. methodStatement | constStatement;
  22. methodStatement:
  23. {oneway &= 1;}
  24. (ONEWAY {oneway |= 2;})?
  25. methodReturnType id LP paramList? RP (EQ INT)? SE;
  26. constStatement:
  27. CONST INT id EQ INTEGER SE |
  28. CONST STRING id EQ LITERALSTRING SE;
  29. methodReturnType:
  30. {oneway==0}? (NULLABLE? type) | VOID;
  31. paramList:
  32. param (CO param)*;
  33. param:
  34. NULLABLE? paramTag? paramType[$paramTag.text] id;
  35. paramTag:
  36. IN |
  37. {oneway==0}? (OUT | INOUT);
  38. paramType[String tag]
  39. locals [int tid = 0]:
  40. {$tag==null}? (
  41. (PRIMITIVE | STRING | interfaceName {$tid = 1;})
  42. ) | {$tag!=null}? (
  43. MAP
  44. | CHARSEQUENCE
  45. | list
  46. | (
  47. name {$tid = -1;}
  48. | type {$tid = $type.tid;}
  49. ) {$tag.equals("in")}?
  50. | className {$tid = 2;}
  51. | type LB RB
  52. );
  53. type
  54. returns [int tid = 0]:
  55. (PRIMITIVE | STRING | CHARSEQUENCE | MAP | list | className {$tid = 2;}) (LB RB)*;
  56. list: LIST (LA type RA)?;
  57. interfaceName: IBINDER | name;
  58. className: name;
  59. name: ID | PATH;
  60. path: PATH;
  61. id: ID;
  62. PRIMITIVE: BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | BOOLEAN | CHAR;
  63. BYTE: 'byte';
  64. SHORT: 'short';
  65. INT: 'int';
  66. LONG: 'long';
  67. FLOAT: 'float';
  68. DOUBLE: 'double';
  69. BOOLEAN: 'boolean';
  70. CHAR: 'char';
  71. PACKAGE: 'package';
  72. PARCELABLE: 'parcelable';
  73. IMPORT: 'import';
  74. INTERFACE: 'interface';
  75. ONEWAY: 'oneway';
  76. VOID: 'void';
  77. CONST: 'const';
  78. NULLABLE: '@nullable';
  79. INOUT: 'inout';
  80. IN: 'in';
  81. OUT: 'out';
  82. STRING: 'String';
  83. CHARSEQUENCE: 'CharSequence';
  84. MAP: 'Map';
  85. LIST: 'List';
  86. IBINDER: 'IBinder';
  87. LP: '(';
  88. RP: ')';
  89. LC: '{';
  90. RC: '}';
  91. LB: '[';
  92. RB: ']';
  93. LA: '<';
  94. RA: '>';
  95. DOT: '.';
  96. CO: ',';
  97. SE: ';';
  98. EQ: '=';
  99. PATH: ID (DOT ID)+;
  100. ID: [_a-zA-Z][_a-zA-Z0-9]*;
  101. INTEGER: [0-9]+;
  102. LITERALSTRING: '"' (ESC | .)*? '"';
  103. fragment ESC: '\\"' | '\\\\';
  104. WS: [ \t\r\n]+ -> channel(1);
  105. COMMENT_BLOCK: '/*' .*? '*/' -> channel(2);
  106. COMMENT_LINE: '//' .*? EL -> channel(2);
  107. fragment EL: '\r\n' | '\n' | '\n\r' | EOF;